aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2021-10-27 21:49:04 +0300
committereug-vs <eugene@eug-vs.xyz>2021-10-27 21:49:04 +0300
commit47f76ad2898ca5f0f1f94c2b5d9e08db5613187b (patch)
tree062028854298791883b467414cf6ecb8dd1e3c02 /src/main.rs
parentba78b90209c5fd3a183043ad3f5110c4a60bf335 (diff)
downloadpistol-47f76ad2898ca5f0f1f94c2b5d9e08db5613187b.tar.gz
feat: allow controlling Lights
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 804ddfa..7226c8e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,15 +3,16 @@ extern crate ncurses;
mod camera;
mod canvas;
use std::{f32::consts::PI, time::Instant};
-use cgmath::Vector3;
+use cgmath::{Angle, InnerSpace, Matrix3, Rad, Vector3};
use ncurses::*;
-use crate::camera::{Buffer, Camera, WIDTH, HEIGHT, rotate_z};
+use crate::camera::{Buffer, Camera, WIDTH, HEIGHT};
fn main() {
let mut cam = Camera {
position: Vector3 { x: 0.0, y: -0.7, z: 0.0 },
- direction: Vector3 { x: 1.0, y: 0.0, z: 0.0 },
+ direction: Vector3 { x: 1.0, y: 0.0, z: 0.0 }.normalize(),
+ light: Vector3 { x: 1.0, y: 1.0, z: -1.0 }.normalize(),
angle: PI / 2.0,
distance: 1.0,
aspect_ratio: 2.0 * HEIGHT as f32 / WIDTH as f32,
@@ -34,10 +35,15 @@ fn main() {
cam.render();
addstr(&cam.buffer.to_string());
addstr(&format!("\nRendered in {:?}\n", timestamp.elapsed()).to_string());
+ addstr(&format!("Camera: {:?}\n", cam.position));
+ addstr(&format!("Facing: {:?}\n", cam.direction));
+ addstr(&format!("Light: {:?}\n", cam.light));
refresh();
// Handle input
let char = getch();
+ addstr(&format!("\nPressed: {:?}\n", char));
+ refresh();
let cam_speed = 0.5;
let cam_turn_rate = 30.0;
@@ -47,15 +53,19 @@ fn main() {
} else if char == 107 || char == 75 {
cam.position += cam.direction * cam_speed;
} else if char == 104 {
- cam.direction = rotate_z(cam.direction, -2.0 * PI / cam_turn_rate);
+ cam.direction = Matrix3::from_angle_z(-Rad::full_turn() / cam_turn_rate) * cam.direction;
} else if char == 108 {
- cam.direction = rotate_z(cam.direction, 2.0 * PI / cam_turn_rate);
+ cam.direction = Matrix3::from_angle_z(Rad::full_turn() / cam_turn_rate) * cam.direction;
} else if char == 72 {
- cam.position -= rotate_z(cam.direction, PI / 2.0) * cam_speed;
+ cam.position -= Matrix3::from_angle_z(Rad::turn_div_4()) * cam.direction * cam_speed;
} else if char == 76 {
- cam.position += rotate_z(cam.direction, PI / 2.0) * cam_speed;
- } else if char == 70 { // F
+ cam.position += Matrix3::from_angle_z(Rad::turn_div_4()) * cam.direction * cam_speed;
+ } else if char == 70 { // F to reverse camera direction
cam.direction = -cam.direction;
+ } else if char == 101 { // e to change lights
+ cam.light = Matrix3::from_angle_z(Rad::turn_div_2() / cam_turn_rate) * cam.light;
+ } else if char == 69 { // E to change lights vertically
+ cam.light = Matrix3::from_angle_y(Rad::turn_div_2() / cam_turn_rate) * cam.light;
}
}