avoid crashes on dir=0
This commit is contained in:
parent
653788d456
commit
0065a45e7d
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user