diff options
author | eug-vs <eugene@eug-vs.xyz> | 2021-10-27 23:05:14 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2021-10-27 23:06:45 +0300 |
commit | 8b2dd268c48d45c7bced63fac1684052568e8f94 (patch) | |
tree | 983d53551d57be4b38aa07c3c0a622a5afa37c1f /src/camera.rs | |
parent | 28b63fcbbbdc6a1b7ba50ef2f6734b060a735c8c (diff) | |
download | pistol-8b2dd268c48d45c7bced63fac1684052568e8f94.tar.gz |
feat: more sophisticated camera movement
Diffstat (limited to 'src/camera.rs')
-rw-r--r-- | src/camera.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/camera.rs b/src/camera.rs index 204b9f8..c620b24 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,8 +1,6 @@ -use cgmath::Matrix3; -use cgmath::Rad; use cgmath::Vector3; use cgmath::prelude::*; -use std::{cmp::{max, min}, f32::consts::PI, fmt}; +use std::fmt; type Vector = Vector3<f32>; @@ -29,12 +27,15 @@ pub struct Camera { pub time: f32, pub position: Vector, pub direction: Vector, + pub up: Vector, pub light: Vector, pub angle: f32, pub distance: f32, pub brightness: f32, pub aspect_ratio: f32, pub buffer: Buffer, + pub speed: f32, + pub turn_rate: f32, } fn softmin(left: f32, right: f32, k: f32) -> f32 { @@ -97,8 +98,8 @@ impl Camera { let palette = "$@B%8&WM#oahkbdpqwmZO0QLCJUYXzcvunxrjft/\\|()1{}[]?-_+~<>i!lI;:,\"^`'. "; let (screen_width, screen_height) = self.screen(); - let h_step = Matrix3::from_angle_z(Rad::turn_div_4()) * self.direction * screen_width / WIDTH as f32; - let v_step = Vector { x: 0.0, y: 0.0, z: -screen_height / HEIGHT as f32 }; + let h_step = self.up.cross(self.direction) * screen_width / WIDTH as f32; + let v_step = -self.up * screen_height / HEIGHT as f32; // println!("Steps: h{}, v{}", h_step, v_step); // Initialize with a corner |