summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index e4afeac..ad59b38 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,7 +4,7 @@ use engine::color::Color;
use engine::object::{Id as ObjectId, Object};
use engine::vector::Vec3;
use engine::vertex::Builder as VertexBuilder;
-use engine::{Engine, WindowSize};
+use engine::{Engine, Key, WindowSize};
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
@@ -128,8 +128,45 @@ fn main() -> Result<(), Box<dyn Error>>
engine.add_object(square);
+ let cam_speed = 3.0;
+
engine.start(|engine| {
- let obj = engine.get_object_by_id_mut(ObjectId::new(1));
+ let delta_time = *engine.delta_time();
+
+ if engine.is_key_pressed(Key::W).unwrap() {
+ let cam_target_direction = engine.camera().target_direction().clone();
+
+ *engine.camera_mut().position_mut() +=
+ cam_target_direction * cam_speed * delta_time.as_secs_f32();
+ }
+ if engine.is_key_pressed(Key::S).unwrap() {
+ let rev_cam_target_direction = -engine.camera().target_direction().clone();
+
+ *engine.camera_mut().position_mut() +=
+ rev_cam_target_direction * cam_speed * delta_time.as_secs_f32();
+ }
+ if engine.is_key_pressed(Key::A).unwrap() {
+ let cam_left = engine.camera().left().clone();
+
+ // Camera speed adjusted to be same no matter how far the distance is to the
+ // camera target
+ let cam_speed_dist_adj = cam_speed
+ * (engine.camera().position() - engine.camera().target()).length();
+
+ *engine.camera_mut().position_mut() +=
+ cam_left * cam_speed_dist_adj * delta_time.as_secs_f32();
+ }
+ if engine.is_key_pressed(Key::D).unwrap() {
+ let cam_right = engine.camera().right().clone();
+
+ // Camera speed adjusted to be same no matter how far the distance is to the
+ // camera target
+ let cam_speed_dist_adj = cam_speed
+ * (engine.camera().position() - engine.camera().target()).length();
+
+ *engine.camera_mut().position_mut() +=
+ cam_right * cam_speed_dist_adj * delta_time.as_secs_f32();
+ }
})?;
Ok(())