hopefully correct camera

This commit is contained in:
numzero 2025-11-13 22:57:20 +03:00
parent f8b8ff2258
commit becb4154ee

View File

@ -23,9 +23,17 @@ impl OrbitalCamera {
}
pub fn transform(&self) -> Mat4 {
// for yaw=0, pitch=0:
// X -> -Z
// Y -> -X
// Z -> Y
Mat4::from_translation(vec3(0., 0., self.distance))
* Mat4::from_euler(glam::EulerRot::ZXZ, 0., PI / 2., -PI / 2.)
* Mat4::from_euler(
* Mat4::from_cols_array_2d(&[
[0., 0., -1., 0.],
[-1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 0., 1.],
]) * Mat4::from_euler(
glam::EulerRot::ZYZ,
0.,
self.position_pitch,
@ -68,7 +76,7 @@ mod tests {
#[test]
fn test_orbital_camera_forward() {
const EPSILON: f32 = 1e-5;
for pitch in [0., 30., 45., 89., 90.] {
for pitch in [0., 30., 45., 89., -30., -45., -89.] {
for yaw in [0., 30., 45., 89., 90.] {
let camera = camera_deg(yaw, pitch);
let pos = camera.position();
@ -91,6 +99,12 @@ mod tests {
abs_diff_eq!(mapped, vec3(0., 0., 1.), epsilon = EPSILON),
"origin not mapped to (0, 0, 1): yaw={yaw:?}°, pitch={pitch:?}°, pos={pos:?}, mapped={mapped:?}"
);
let mapped = tfm.transform_vector3(vec3(0., 0., 1.));
assert!(
mapped.y > 0.,
"up is not up: yaw={yaw:?}°, pitch={pitch:?}°, pos={pos:?}, mapped={mapped:?}"
);
}
}
}