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)
|
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 {
|
pub fn transform(&self) -> Mat4 {
|
||||||
// for yaw=0, pitch=0:
|
// for yaw=0, pitch=0:
|
||||||
// X -> -Z
|
// X -> -Z
|
||||||
|
|
|
||||||
|
|
@ -393,7 +393,10 @@ impl Core {
|
||||||
.map(|&v| {
|
.map(|&v| {
|
||||||
let pos = obj.position + obj.radius * v;
|
let pos = obj.position + obj.radius * v;
|
||||||
let normal = 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 {
|
let light = light_at(Hit {
|
||||||
incident: Ray::new(pos, dir),
|
incident: Ray::new(pos, dir),
|
||||||
normal,
|
normal,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user