hopefully correct camera
This commit is contained in:
parent
f8b8ff2258
commit
becb4154ee
|
|
@ -23,9 +23,17 @@ impl OrbitalCamera {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transform(&self) -> Mat4 {
|
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_translation(vec3(0., 0., self.distance))
|
||||||
* Mat4::from_euler(glam::EulerRot::ZXZ, 0., PI / 2., -PI / 2.)
|
* Mat4::from_cols_array_2d(&[
|
||||||
* Mat4::from_euler(
|
[0., 0., -1., 0.],
|
||||||
|
[-1., 0., 0., 0.],
|
||||||
|
[0., 1., 0., 0.],
|
||||||
|
[0., 0., 0., 1.],
|
||||||
|
]) * Mat4::from_euler(
|
||||||
glam::EulerRot::ZYZ,
|
glam::EulerRot::ZYZ,
|
||||||
0.,
|
0.,
|
||||||
self.position_pitch,
|
self.position_pitch,
|
||||||
|
|
@ -68,7 +76,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_orbital_camera_forward() {
|
fn test_orbital_camera_forward() {
|
||||||
const EPSILON: f32 = 1e-5;
|
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.] {
|
for yaw in [0., 30., 45., 89., 90.] {
|
||||||
let camera = camera_deg(yaw, pitch);
|
let camera = camera_deg(yaw, pitch);
|
||||||
let pos = camera.position();
|
let pos = camera.position();
|
||||||
|
|
@ -91,6 +99,12 @@ mod tests {
|
||||||
abs_diff_eq!(mapped, vec3(0., 0., 1.), epsilon = EPSILON),
|
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:?}"
|
"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:?}"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user