pub fn ray_cast(
origin: &Vector3<f32>,
rotation_world_to_camera: &Matrix3<f32>,
direction: &Vector3<f32>,
maze: &Maze,
near: f32,
far: f32,
) -> Result<f32, SimulationError>
Expand description
Casts a ray from the camera origin in the given direction
§Arguments
origin
- The origin of the rayrotation_world_to_camera
- The rotation matrix from world to camera coordinatesdirection
- The direction of the raymaze
- The maze in the scenenear
- The minimum distance to considerfar
- The maximum distance to consider
§Returns
- The distance to the closest obstacle hit by the ray
§Errors
- If the ray does not hit any obstacles
§Example
use peng_quad::{ray_cast, Maze};
use nalgebra::{Vector3, Matrix3};
let origin = Vector3::new(0.0, 0.0, 0.0);
let rotation_world_to_camera = Matrix3::identity();
let direction = Vector3::new(0.0, 0.0, 1.0);
let maze = Maze::new([-1.0, -1.0, -1.0], [1.0, 1.0, 1.0], 5, [0.1, 0.1, 0.1], [0.1, 0.5]);
let near = 0.1;
let far = 100.0;
let distance = ray_cast(&origin, &rotation_world_to_camera, &direction, &maze, near, far);