67 lines
1.3 KiB
Rust
67 lines
1.3 KiB
Rust
use cgmath::Euler;
|
|
use glow::NativeProgram;
|
|
use nalgebra_glm::{look_at, Mat4x4, Vec3};
|
|
use std::num::NonZeroU32;
|
|
|
|
#[derive(Clone)]
|
|
pub(crate) struct Camera {
|
|
pos: Vec3,
|
|
upward: Vec3,
|
|
center: Vec3,
|
|
}
|
|
|
|
pub type CameraPositon = Vec3;
|
|
|
|
impl Camera {
|
|
pub(crate) fn new(world_loc: CameraPositon, upward: Vec3, center: Vec3) -> Self {
|
|
Self {
|
|
pos: world_loc,
|
|
upward,
|
|
center,
|
|
}
|
|
}
|
|
|
|
pub fn get_position(&self) -> CameraPositon {
|
|
self.pos
|
|
}
|
|
|
|
pub fn set_position(&mut self, pos: CameraPositon) {
|
|
self.pos = pos;
|
|
}
|
|
|
|
pub fn get_upward(&self) -> Vec3 {
|
|
self.upward
|
|
}
|
|
|
|
pub fn get_center(&self) -> Vec3 {
|
|
self.center
|
|
}
|
|
|
|
pub fn set_upward(&mut self, upward: Vec3) {
|
|
self.upward = upward;
|
|
}
|
|
|
|
pub fn set_center(&mut self, center: Vec3) {
|
|
self.center = center;
|
|
}
|
|
|
|
pub fn get_view_matrix(&self) -> Mat4x4 {
|
|
let l = self.center;
|
|
look_at(&self.pos, &l, &self.upward)
|
|
}
|
|
|
|
pub fn front(&self) -> Vec3 {
|
|
self.center - self.pos
|
|
}
|
|
}
|
|
|
|
impl Default for Camera {
|
|
fn default() -> Self {
|
|
Self {
|
|
pos: Vec3::new(0.0, 0.0, 0.0),
|
|
upward: Vec3::new(0.0, 1.0, 0.0),
|
|
center: Vec3::new(0.0, 0.0, -1.0),
|
|
}
|
|
}
|
|
}
|