Reuse ndc_to_world matrix in Camera::viewport_to_world (#6532)
# Objective Solve #6531. Co-authored-by: devil-ira <justthecooldude@gmail.com>
This commit is contained in:
parent
1914a3f288
commit
9b56b549ad
@ -236,11 +236,13 @@ impl Camera {
|
|||||||
let target_size = self.logical_viewport_size()?;
|
let target_size = self.logical_viewport_size()?;
|
||||||
let ndc = viewport_position * 2. / target_size - Vec2::ONE;
|
let ndc = viewport_position * 2. / target_size - Vec2::ONE;
|
||||||
|
|
||||||
let world_near_plane = self.ndc_to_world(camera_transform, ndc.extend(1.))?;
|
let ndc_to_world =
|
||||||
// Using EPSILON because passing an ndc with Z = 0 returns NaNs.
|
camera_transform.compute_matrix() * self.computed.projection_matrix.inverse();
|
||||||
let world_far_plane = self.ndc_to_world(camera_transform, ndc.extend(f32::EPSILON))?;
|
let world_near_plane = ndc_to_world.project_point3(ndc.extend(1.));
|
||||||
|
// Using EPSILON because an ndc with Z = 0 returns NaNs.
|
||||||
|
let world_far_plane = ndc_to_world.project_point3(ndc.extend(f32::EPSILON));
|
||||||
|
|
||||||
Some(Ray {
|
(!world_near_plane.is_nan() && !world_far_plane.is_nan()).then_some(Ray {
|
||||||
origin: world_near_plane,
|
origin: world_near_plane,
|
||||||
direction: (world_far_plane - world_near_plane).normalize(),
|
direction: (world_far_plane - world_near_plane).normalize(),
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user