Skip to content

Commit

Permalink
fix z_buffer depth format
Browse files Browse the repository at this point in the history
  • Loading branch information
makeecat committed Aug 12, 2024
1 parent 7bf1f39 commit 032e216
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,13 +996,17 @@ impl Camera {
maze: &Maze,
) -> Vec<f32> {
let (width, height) = self.resolution;
let camera_to_world = quad_orientation.to_rotation_matrix().matrix()
let rotation_camera_to_world = quad_orientation.to_rotation_matrix().matrix()
* Matrix3::new(1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0);
(0..width * height)
.map(|i| {
let ray_dir = camera_to_world * self.ray_directions[i];
self.ray_cast(quad_position, &ray_dir, maze)
.unwrap_or(std::f32::INFINITY)
self.ray_cast(
&quad_position,
&rotation_camera_to_world.try_inverse().unwrap(),
&(rotation_camera_to_world * self.ray_directions[i]),
&maze,
)
.unwrap_or(std::f32::INFINITY)
})
.collect()
}
Expand All @@ -1016,6 +1020,7 @@ impl Camera {
fn ray_cast(
&self,
origin: &Vector3<f32>,
rotation_world_to_camera: &Matrix3<f32>,
direction: &Vector3<f32>,
maze: &Maze,
) -> Option<f32> {
Expand All @@ -1039,7 +1044,8 @@ impl Camera {
}
}
if closest_hit < self.far {
Some(closest_hit)
let closest_pt = rotation_world_to_camera * direction * closest_hit;
Some(closest_pt.x)
} else {
None
}
Expand Down

0 comments on commit 032e216

Please sign in to comment.