We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ceffc9d commit 9434e1fCopy full SHA for 9434e1f
src/main.rs
@@ -60,7 +60,7 @@ impl std::ops::Mul<Res> for Res {
60
61
fn scene(x: f64, y: f64) -> Res {
62
Res {
63
- sd: capsule_sdf(x, y, 0.4, 0.4, 0.6, 0.6, 0.1),
+ sd: box_sdf(x, y, 0.5, 0.5, 2.0 * PI / 16.0, 0.3, 0.1) - 0.1,
64
emissive: 1.0,
65
}
66
@@ -90,6 +90,16 @@ fn capsule_sdf(x: f64, y: f64, ax: f64, ay: f64, bx: f64, by: f64, r: f64) -> f6
90
segment_sdf(x, y, ax, ay, bx, by) - r
91
92
93
+fn box_sdf(x: f64, y: f64, cx: f64, cy: f64, theta: f64, sx: f64, sy: f64) -> f64 {
94
+ let costheta = theta.cos();
95
+ let sintheta = theta.sin();
96
+ let dx = ((x - cx) * costheta + (y - cy) * sintheta).abs() - sx;
97
+ let dy = ((y - cy) * costheta - (x - cx) * sintheta).abs() - sy;
98
+ let ax = dx.max(0.0);
99
+ let ay = dy.max(0.0);
100
+ dx.max(dy).min(0.0) + (ax * ax + ay * ay).sqrt()
101
+}
102
+
103
fn trace(ox: f64, oy: f64, dx: f64, dy: f64) -> f64 {
104
let mut t = 0.0;
105
let mut i = 0;
0 commit comments