#[derive(Clone, Debug)]
pub struct RenderView {
pub view: nalgebra_glm::Mat4,
pub projection: nalgebra_glm::Mat4,
pub view_projection: nalgebra_glm::Mat4,
pub inverse_view: nalgebra_glm::Mat4,
pub inverse_projection: nalgebra_glm::Mat4,
pub inverse_view_projection: nalgebra_glm::Mat4,
pub camera_position: nalgebra_glm::Vec3,
pub camera_right: nalgebra_glm::Vec3,
pub camera_up: nalgebra_glm::Vec3,
pub frustum_planes: [nalgebra_glm::Vec4; 6],
pub z_near: f32,
pub z_far: f32,
pub y_fov_rad: f32,
pub aspect: f32,
pub orthographic: Option<(f32, f32)>,
pub screen_size: (u32, u32),
pub constrained_aspect: Option<f32>,
}
#[derive(Clone, Copy, Debug)]
pub struct DynamicRenderState {
pub visible: u32,
pub morph_weights: [f32; 8],
pub transform: nalgebra_glm::Mat4,
pub culling_mask: u32,
pub is_overlay: u32,
pub render_layer: u32,
}
pub fn reverse_z_perspective(
y_fov_rad: f32,
aspect: f32,
z_near: f32,
z_far: f32,
) -> nalgebra_glm::Mat4 {
let focal_length = 1.0 / (y_fov_rad / 2.0).tan();
nalgebra_glm::Mat4::new(
focal_length / aspect,
0.0,
0.0,
0.0,
0.0,
focal_length,
0.0,
0.0,
0.0,
0.0,
z_near / (z_far - z_near),
z_near * z_far / (z_far - z_near),
0.0,
0.0,
-1.0,
0.0,
)
}
#[derive(Debug, Clone, Copy, Default)]
pub struct ViewportRect {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
}
impl ViewportRect {
pub fn contains(&self, screen_pos: nalgebra_glm::Vec2) -> bool {
screen_pos.x >= self.x
&& screen_pos.x <= self.x + self.width
&& screen_pos.y >= self.y
&& screen_pos.y <= self.y + self.height
}
pub fn to_local(&self, screen_pos: nalgebra_glm::Vec2) -> nalgebra_glm::Vec2 {
nalgebra_glm::Vec2::new(screen_pos.x - self.x, screen_pos.y - self.y)
}
}