-
Notifications
You must be signed in to change notification settings - Fork 65
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
Gizmo does not work with reversed z projection matrix #46
Comments
I'm having no problem using egui-guizmo with an infinite reversed-z right handed projection matrix (computed via glam helpers). How are you using yours? |
Tried it again, and now it's working for me too. Unfortunately, I lost the code that I used to try it out with but after trying different theories, I think it did not work for me because the matrix was wrong. At the time of writing this issue, I also created a PR for my math library of choice: ultraviolet. That PR fixes the incorrect reverse-z-projection matrix (fu5ha/ultraviolet#168) and I might have just used some adapted version of the old and incorrect projection matrix for the gizmo. This might be the code I used for generating the incorrect reverse-z projection matrix, which also reproduces the behaviour I got when I wrote this issue: pub fn perspective_reversed_incorrect(
vertical_fov: f32,
aspect_ratio: f32,
z_near: f32,
z_far: f32,
) -> Mat4 {
let t = (vertical_fov / 2.0).tan();
let sy = 1.0 / t;
let sx = sy / aspect_ratio;
let nmf = z_near - z_far;
Mat4::new(
Vec4::new(sx, 0.0, 0.0, 0.0),
Vec4::new(0.0, sy, 0.0, 0.0),
Vec4::new(0.0, 0.0, z_far / nmf, -1.0),
Vec4::new(0.0, 0.0, -z_near * z_far / nmf, 0.0),
)
} Changing the third column of the matrix in the following way makes the gizmo interactable again: - Vec4::new(0.0, 0.0, z_far / nmf, -1.0),
+ Vec4::new(0.0, 0.0, -z_near / nmf, -1.0), This matches the implementation of the current I apologize for wrongly assuming that this was an issue with the gizmo crate. |
Using a reversed z projection matrix leads to the gizmo not being interactable. It might be a good idea to document this behaviour. In the meanwhile, this issue exists to potentially save someone time if they stumble upon the same issue.
The text was updated successfully, but these errors were encountered: