From 4f068467c4954fb79e6ce297ae1ac0fdd2bdf16a Mon Sep 17 00:00:00 2001 From: tcmal Date: Sun, 25 Aug 2024 17:44:24 +0100 Subject: WIP refactor(skeleton): type state for context also some api improvements closes #2 related: #7 --- stockton-render/src/camera.rs | 62 ------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 stockton-render/src/camera.rs (limited to 'stockton-render/src/camera.rs') diff --git a/stockton-render/src/camera.rs b/stockton-render/src/camera.rs deleted file mode 100644 index 6abc183..0000000 --- a/stockton-render/src/camera.rs +++ /dev/null @@ -1,62 +0,0 @@ -//! Things related to converting 3D world space to 2D screen space - -use legion::maybe_changed; -use na::{look_at_lh, perspective_lh_zo}; -use stockton_types::{ - components::{CameraSettings, CameraVPMatrix, Transform}, - Vector3, -}; - -use stockton_skeleton::{ - draw_passes::{DrawPass, Singular}, - Renderer, -}; - -fn euler_to_direction(euler: &Vector3) -> Vector3 { - let pitch = euler.x; - let yaw = euler.y; - let _roll = euler.z; // TODO: Support camera roll - - Vector3::new( - yaw.sin() * pitch.cos(), - pitch.sin(), - yaw.cos() * pitch.cos(), - ) -} - -#[system(for_each)] -#[filter(maybe_changed::() | maybe_changed::())] -pub fn calc_vp_matrix + 'static>( - transform: &Transform, - settings: &CameraSettings, - matrix: &mut CameraVPMatrix, - #[resource] renderer: &Renderer, -) { - // Get look direction from euler angles - let direction = euler_to_direction(&transform.rotation); - - // Converts world space to camera space - let view_matrix = look_at_lh( - &transform.position, - &(transform.position + direction), - &Vector3::new(0.0, 1.0, 0.0), - ); - - // Converts camera space to screen space - let projection_matrix = { - let mut temp = perspective_lh_zo( - renderer.get_aspect_ratio(), - settings.fov, - settings.near, - settings.far, - ); - - // Vulkan's co-ord system is different from OpenGLs - temp[(1, 1)] *= -1.0; - - temp - }; - - // Chain them together into a single matrix - matrix.vp_matrix = projection_matrix * view_matrix; -} -- cgit v1.2.3