From a63a5fd647a2117885e70954181ea7164e470bb3 Mon Sep 17 00:00:00 2001
From: eug-vs <eugene@eug-vs.xyz>
Date: Wed, 27 Oct 2021 11:58:40 +0300
Subject: feat: add camera rotation

---
 src/camera.rs | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

(limited to 'src/camera.rs')

diff --git a/src/camera.rs b/src/camera.rs
index eb7cea2..d87abe2 100644
--- a/src/camera.rs
+++ b/src/camera.rs
@@ -54,17 +54,17 @@ impl Camera {
         let floor_dist = point.z + 1.0;
 
         // Sphere
-        let center = Vector { x: 3.0, y: 0.0, z: 0.0 };
+        let center = Vector { x: 4.0, y: 0.0, z: 0.0 };
         let radius = 1.0 + 0.5 * self.time.sin();
         let sphere_dist = (point - center).magnitude() - radius;
 
         // Small sphere
-        let center2 = Vector { x: 2.5, y: 0.5, z: 0.0 };
+        let center2 = Vector { x: 3.5, y: 0.5, z: 0.0 };
         let radius2 = 0.7;
         let sphere2_dist = (point - center2).magnitude() - radius2;
 
         // Second sphere
-        let center3 = Vector { x: 3.0 + self.time.sin() * 1.6, y: -2.5, z: 0.0 - self.time.sin() * 0.8 };
+        let center3 = Vector { x: 4.0 + self.time.sin() * 1.6, y: -2.5, z: 0.0 - self.time.sin() * 0.8 };
         let radius3 = 1.0;
         let sphere3_dist = (point - center3).magnitude() - radius3;
 
@@ -79,6 +79,11 @@ impl Camera {
         )
     }
 
+    pub fn rorate_around_point(& mut self, point: Vector) {
+        self.position = rotate_z(self.position - point, 2.0 * PI / 60.0) + point;
+        self.direction = (point - self.position).normalize();
+    }
+
     pub fn screen(&self) -> (f32, f32) {
         let width = self.distance * 2.0 * (self.angle / 2.0).tan();
         let height = width * self.aspect_ratio;
@@ -86,6 +91,8 @@ impl Camera {
         (width, height)
     }
     pub fn render(& mut self) {
+        self.rorate_around_point(Vector { x: 4.0, y: 0.0, z: 0.0 });
+
         let palette = "$@B%8&WM#oahkbdpqwmZO0QLCJUYXzcvunxrjft/\\|()1{}[]?-_+~<>i!lI;:,\"^`'.";
         let (screen_width, screen_height) = self.screen();
 
-- 
cgit v1.2.3