avoid crashes on dir=0

This commit is contained in:
numzero 2025-11-25 14:40:53 +03:00
parent 653788d456
commit 0065a45e7d
2 changed files with 10 additions and 1 deletions

View File

@ -20,6 +20,12 @@ impl OrbitalCamera {
self.distance * vec3(xy * x, xy * y, z)
}
pub fn direction(&self) -> Vec3 {
let (y, x) = self.position_yaw.sin_cos();
let (z, xy) = self.position_pitch.sin_cos();
-vec3(xy * x, xy * y, z)
}
pub fn transform(&self) -> Mat4 {
// for yaw=0, pitch=0:
// X -> -Z

View File

@ -393,7 +393,10 @@ impl Core {
.map(|&v| {
let pos = obj.position + obj.radius * v;
let normal = v;
let dir = (pos - camera.position()).normalize();
let mut dir = (pos - camera.position()).normalize();
if !dir.is_finite() {
dir = camera.direction();
}
let light = light_at(Hit {
incident: Ray::new(pos, dir),
normal,