diff options
author | eug-vs <eugene@eug-vs.xyz> | 2021-10-27 11:40:37 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2021-10-27 11:40:37 +0300 |
commit | 8391a35aaa35da3018744f89b296e57549b29255 (patch) | |
tree | 5d9ad2415bd5c577470762335a95c45a7b575735 | |
parent | 92d5cd982d87963165ee175b985a8a477154a5e7 (diff) | |
download | pistol-8391a35aaa35da3018744f89b296e57549b29255.tar.gz |
feat: add time parameter
-rw-r--r-- | src/camera.rs | 6 | ||||
-rw-r--r-- | src/main.rs | 15 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/camera.rs b/src/camera.rs index 646307f..eb7cea2 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -32,6 +32,7 @@ impl fmt::Display for Buffer { #[derive(Debug)] pub struct Camera { + pub time: f32, pub position: Vector, pub direction: Vector, pub angle: f32, @@ -42,6 +43,7 @@ pub struct Camera { } fn softmin(left: f32, right: f32, k: f32) -> f32 { + // return left.min(right); let h = (k-(left-right).abs()).max(0.0) / k; return left.min(right) - h*h*k*(1.0/4.0); } @@ -53,7 +55,7 @@ impl Camera { // Sphere let center = Vector { x: 3.0, y: 0.0, z: 0.0 }; - let radius = 1.0; + let radius = 1.0 + 0.5 * self.time.sin(); let sphere_dist = (point - center).magnitude() - radius; // Small sphere @@ -62,7 +64,7 @@ impl Camera { let sphere2_dist = (point - center2).magnitude() - radius2; // Second sphere - let center3 = Vector { x: 3.0, y: -2.5, z: 0.0 }; + let center3 = Vector { x: 3.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; diff --git a/src/main.rs b/src/main.rs index 3a757db..b14ef5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,10 +12,17 @@ fn main() { angle: PI / 2.0, distance: 1.0, aspect_ratio: 1.0, - brightness: 10.0, - buffer: Buffer([['.'; 120]; 60]) + brightness: 5.0, + buffer: Buffer([['.'; 120]; 60]), + time: 0.0, }; - cam.render(); - println!("{}", cam.buffer); + for _round in 0..1 { + for i in 0..60 { + // 1 sin round + cam.time = (i as f32 / 60.0) * 2.0 * PI; + cam.render(); + println!("{}", cam.buffer); + } + } } |