Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] provide methods for inverse projection matrices #390

Open
wolfiestyle opened this issue Apr 3, 2023 · 0 comments
Open

[feature] provide methods for inverse projection matrices #390

wolfiestyle opened this issue Apr 3, 2023 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@wolfiestyle
Copy link

The inverse of projection matrices can be computed analytically and evaluated directly from the same input parameters for improved performance and precision. For example, the inverse of perspective_rh would be something like:

pub fn perspective_rh_inv(fov_y_radians: f32, aspect_ratio: f32, z_near: f32, z_far: f32) -> Self {
        glam_assert!(z_near > 0.0 && z_far > 0.0);
        let (sin_fov, cos_fov) = (0.5 * fov_y_radians).sin_cos();
        let h = sin_fov / cos_fov;
        let w = h * aspect_ratio;
        let r = 1.0 / z_near;
        Self::from_cols(
            Vec4::new(w, 0.0, 0.0, 0.0),
            Vec4::new(0.0, h, 0.0, 0.0),
            Vec4::new(0.0, 0.0, 0.0, 1.0/z_far - r),
            Vec4::new(0.0, 0.0, -1.0, r),
        )
    }
@bitshifter bitshifter added enhancement New feature or request help wanted Extra attention is needed labels Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants