update projection
This commit is contained in:
parent
ffed77a2fc
commit
f909a3e140
1 changed files with 15 additions and 6 deletions
|
@ -45,6 +45,8 @@ pub fn make_projection_rh_from_frustum_reversed(
|
|||
) -> Mat4 {
|
||||
assert!(z_near > 0.0 && z_far > 0.0);
|
||||
|
||||
info!("near {:?}",z_near);
|
||||
|
||||
//
|
||||
// reversed z 0..1 projection based on https://thxforthefish.com/posts/reverse_z/
|
||||
//
|
||||
|
@ -57,15 +59,18 @@ pub fn make_projection_rh_from_frustum_reversed(
|
|||
let sx = 2.0 * z_near / (right - left);
|
||||
let sy = 2.0 * z_near / (top - bottom);
|
||||
|
||||
//
|
||||
// for reverse z 0..1
|
||||
// sx 0 a 0
|
||||
// 0 sy b 0
|
||||
// 0 0 c d
|
||||
// 0 0 -1 0
|
||||
|
||||
Mat4::from_cols(
|
||||
Vec4::new(sx, 0.0, 0.0, 0.0),
|
||||
Vec4::new(0.0, sy, 0.0, 0.0),
|
||||
Vec4::new(a, b, c, -1.0),
|
||||
Vec4::new(0.0, 0.0, d, 0.0),
|
||||
Vec4::new(0.0, 0.0, c, -1.0),
|
||||
Vec4::new(a, b, d, 0.0),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
pub fn make_projection_rh_custom(fov_y: f32, aspect_ratio: f32, z_near: f32, z_far: f32) -> Mat4 {
|
||||
|
@ -117,13 +122,15 @@ pub fn create_offaxis_matrices(
|
|||
// calculate a reasonable near distance
|
||||
let z_near = min_near_distance.max(dist - min_near_distance_offset);
|
||||
|
||||
// let z_near = min_near_distance;
|
||||
|
||||
// distances
|
||||
let left = vec_right_normalized.dot(frustum_left) * z_near / dist; // left screen edge
|
||||
let right = vec_right_normalized.dot(frustum_right) * z_near / dist; // right screen edge
|
||||
let bottom = vec_up_normalized.dot(frustum_left) * z_near / dist; // bottom screen edge
|
||||
let top = vec_up_normalized.dot(frustum_up) * z_near / dist; // distance eye from screen
|
||||
|
||||
// info!("l r b t {} {} {} {}",left,right,bottom,top);
|
||||
info!("l r b t {} {} {} {}",left,right,bottom,top);
|
||||
|
||||
// create a view frustum
|
||||
let projection_matrix =
|
||||
|
@ -151,7 +158,7 @@ pub fn create_offaxis_matrices(
|
|||
Vec4::W,
|
||||
);
|
||||
|
||||
let rotation_quat = Quat::from_mat4(&view_matrix_rotation); // Quat::from_mat4(view_matrix_rotation);
|
||||
// let rotation_quat = Quat::from_mat4(&view_matrix_rotation); // Quat::from_mat4(view_matrix_rotation);
|
||||
|
||||
// info!("Rotation Mat {:?}",view_matrix_rotation);
|
||||
// info!("Viewer Rotation {:?}",rotation_quat);
|
||||
|
@ -161,6 +168,8 @@ pub fn create_offaxis_matrices(
|
|||
// create resulting view matrix (this should be much simpler using glam API)
|
||||
let view_matrix = view_matrix_rotation * view_matrix_eye;
|
||||
|
||||
// info!("{:?}",view_matrix_eye);
|
||||
|
||||
// return tuple of view and projection
|
||||
(view_matrix, projection_matrix)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue