initial (bad) voxel renderer

This commit is contained in:
2024-06-04 12:11:28 -04:00
commit 7ae6a01949
31 changed files with 4268 additions and 0 deletions

44
src/client/camera.rs Normal file
View File

@@ -0,0 +1,44 @@
use nalgebra::{Point3, Rotation3, UnitVector3, Vector3};
const DEFAULT_ASPECT_RATIO: f32 = 16. / 9.;
#[derive(Debug, Clone, Copy)]
pub struct Camera {
pub pos: Point3<f32>,
pub orientation: Rotation3<f32>,
pub aspect: f32,
pub scale: f32,
}
impl Default for Camera {
fn default() -> Self {
Self {
pos: Point3::origin(),
orientation: Rotation3::identity(),
aspect: DEFAULT_ASPECT_RATIO,
scale: 1.0,
}
}
}
impl Camera {
pub fn left(&self) -> UnitVector3<f32> {
self.orientation * -Vector3::x_axis()
}
pub fn right(&self) -> UnitVector3<f32> {
self.orientation * Vector3::x_axis()
}
pub fn down(&self) -> UnitVector3<f32> {
self.orientation * -Vector3::y_axis()
}
pub fn up(&self) -> UnitVector3<f32> {
self.orientation * Vector3::y_axis()
}
pub fn backward(&self) -> UnitVector3<f32> {
self.orientation * -Vector3::z_axis()
}
pub fn forward(&self) -> UnitVector3<f32> {
self.orientation * Vector3::z_axis()
}
}