From 50fd6e93547b462590e733b35fbb8b85065ca395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Dahlstr=C3=B6m?= Date: Sun, 29 Dec 2024 18:06:16 +0200 Subject: [PATCH] Rename cam::Mode to Transform which is more descriptive --- core/src/render/cam.rs | 29 ++++++++++++++++------------- demos/src/bin/bezier.rs | 2 +- demos/src/bin/crates.rs | 10 ++++++---- demos/src/bin/solids.rs | 2 +- demos/src/bin/sprites.rs | 8 +++++--- demos/src/bin/square.rs | 4 +++- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/core/src/render/cam.rs b/core/src/render/cam.rs index 10371d70..74649cfa 100644 --- a/core/src/render/cam.rs +++ b/core/src/render/cam.rs @@ -19,19 +19,17 @@ use super::{ VertexShader, View, ViewToProj, World, WorldToView, }; -/// Camera movement mode. -/// -/// TODO Rename to something more specific (e.g. `Motion`?) -pub trait Mode { +/// Trait for different camera motion transforms. +pub trait Transform { /// Returns the current world-to-view matrix of this camera mode. fn world_to_view(&self) -> Mat4x4; } /// Type to manage the world-to-viewport transformation. #[derive(Copy, Clone, Debug, Default)] -pub struct Camera { +pub struct Camera { /// The movement mode of the camera. - pub mode: M, + pub transform: Tf, /// Viewport width and height. pub dims: Dims, /// Projection matrix. @@ -85,9 +83,14 @@ impl Camera<()> { } } - pub fn mode(self, mode: M) -> Camera { + pub fn transform(self, mode: M) -> Camera { let Self { dims, project, viewport, .. } = self; - Camera { mode, dims, project, viewport } + Camera { + transform: mode, + dims, + project, + viewport, + } } } @@ -131,10 +134,10 @@ impl Camera { } } -impl Camera { +impl Camera { /// Returns the composed camera and projection matrix. pub fn world_to_project(&self) -> Mat4x4> { - self.mode.world_to_view().then(&self.project) + self.transform.world_to_view().then(&self.project) } /// Renders the given geometry from the viewpoint of this camera. @@ -262,7 +265,7 @@ impl Orbit { // #[cfg(feature = "fp")] -impl Mode for FirstPerson { +impl Transform for FirstPerson { fn world_to_view(&self) -> Mat4x4 { let &Self { pos, heading, .. } = self; let fwd_move = az_alt(heading.az(), turns(0.0)).to_cart(); @@ -278,7 +281,7 @@ impl Mode for FirstPerson { } #[cfg(feature = "fp")] -impl Mode for Orbit { +impl Transform for Orbit { fn world_to_view(&self) -> Mat4x4 { // TODO Figure out how to do this with orient //let fwd = self.dir.to_cart().normalize(); @@ -294,7 +297,7 @@ impl Mode for Orbit { } } -impl Mode for Mat4x4 { +impl Transform for Mat4x4 { fn world_to_view(&self) -> Mat4x4 { *self } diff --git a/demos/src/bin/bezier.rs b/demos/src/bin/bezier.rs index 4b754c95..ee67ba63 100644 --- a/demos/src/bin/bezier.rs +++ b/demos/src/bin/bezier.rs @@ -1,8 +1,8 @@ -use re::geom::Ray; use std::{mem::swap, ops::ControlFlow::Continue}; use re::prelude::*; +use re::geom::Ray; use re::math::rand::{Distrib, Uniform, VectorsOnUnitDisk, Xorshift64}; use re_front::{dims::SVGA_800_600, minifb::Window, Frame}; diff --git a/demos/src/bin/crates.rs b/demos/src/bin/crates.rs index a6cb0eac..dbca08d3 100644 --- a/demos/src/bin/crates.rs +++ b/demos/src/bin/crates.rs @@ -3,7 +3,9 @@ use core::ops::ControlFlow::*; use re::prelude::*; use re::math::color::gray; -use re::render::{cam::FirstPerson, Batch, Camera, ModelToProj}; +use re::render::{ + cam::FirstPerson, shader::Shader, Batch, Camera, ModelToProj, +}; use re_front::sdl2::Window; use re_geom::solids::Box; @@ -32,7 +34,7 @@ fn main() { let (w, h) = win.dims; let mut cam = Camera::new(win.dims) - .mode(FirstPerson::default()) + .transform(FirstPerson::default()) .viewport((10..w - 10, 10..h - 10)) .perspective(1.0, 0.1..1000.0); @@ -61,8 +63,8 @@ fn main() { let d_az = turns(ms.x() as f32) * -0.001; let d_alt = turns(ms.y() as f32) * 0.001; - cam.mode.rotate(d_az, d_alt); - cam.mode + cam.transform.rotate(d_az, d_alt); + cam.transform .translate(cam_vel.mul(frame.dt.as_secs_f32())); let flip = scale3(1.0, -1.0, -1.0).to(); diff --git a/demos/src/bin/solids.rs b/demos/src/bin/solids.rs index e6515981..391209f7 100644 --- a/demos/src/bin/solids.rs +++ b/demos/src/bin/solids.rs @@ -60,7 +60,7 @@ fn main() { let (w, h) = win.dims; let cam = Camera::new(win.dims) - .mode(scale3(1.0, -1.0, -1.0).to()) + .transform(scale3(1.0, -1.0, -1.0).to()) .perspective(1.5, 0.1..1000.0) .viewport(vec2(10, 10)..vec2(w - 10, h - 10)); diff --git a/demos/src/bin/sprites.rs b/demos/src/bin/sprites.rs index 12739744..b50933e3 100644 --- a/demos/src/bin/sprites.rs +++ b/demos/src/bin/sprites.rs @@ -3,7 +3,9 @@ use core::{array::from_fn, ops::ControlFlow::Continue}; use re::prelude::*; use re::math::rand::{Distrib, PointsInUnitBall, Xorshift64}; -use re::render::{cam::Mode, render, Model, ModelToView, ViewToProj}; +use re::render::{ + cam::Transform, render, shader::Shader, Model, ModelToView, ViewToProj, +}; use re_front::minifb::Window; fn main() { @@ -51,7 +53,7 @@ fn main() { let (w, h) = win.dims; let cam = Camera::new(win.dims) - .mode(translate(0.5 * Vec3::Z).to()) + .transform(translate(0.5 * Vec3::Z).to()) .perspective(1.0, 1e-2..1e3) .viewport(vec2(10, 10)..vec2(w - 10, h - 10)); @@ -61,7 +63,7 @@ fn main() { let modelview = rotate_x(theta * 0.2) .then(&rotate_z(theta * 0.14)) .to() - .then(&cam.mode.world_to_view()); + .then(&cam.transform.world_to_view()); render( &tris, diff --git a/demos/src/bin/square.rs b/demos/src/bin/square.rs index ae261d2a..257bc448 100644 --- a/demos/src/bin/square.rs +++ b/demos/src/bin/square.rs @@ -3,7 +3,9 @@ use std::ops::ControlFlow::*; use re::prelude::*; use re::math::{pt2, pt3}; -use re::render::{render, tex::SamplerClamp, Context, ModelToProj}; +use re::render::{ + render, shader::Shader, tex::SamplerClamp, Context, ModelToProj, +}; use re_front::minifb::Window;