Add Transform::up

This commit is contained in:
Hanno Braun 2024-11-14 17:48:00 +01:00
parent 63448f4469
commit a9debaccb3
2 changed files with 8 additions and 7 deletions

View File

@ -53,6 +53,12 @@ impl Transform {
Vector::from([d[0], d[1], d[2]])
}
/// # Extract the "up" vector from the rotational component
pub fn up(&self) -> Vector<3> {
let d = self.data();
Vector::from([d[4], d[5], d[6]])
}
/// Transform the given point
pub fn transform_point(&self, point: &Point<3>) -> Point<3> {
Point::from(self.0.transform_point(&point.to_na()))

View File

@ -1,4 +1,4 @@
use fj_math::{Transform, Vector};
use fj_math::Transform;
use crate::camera::{Camera, FocusPoint};
@ -15,7 +15,7 @@ impl Rotation {
// the model rotates not the camera, so invert the transform
let camera_rotation = camera.rotation.inverse();
let up_vector = up_vector(&camera_rotation);
let up_vector = camera_rotation.up();
let rotation = Transform::rotation(camera_rotation.right() * angle_x)
* Transform::rotation(up_vector * angle_y);
@ -29,8 +29,3 @@ impl Rotation {
camera.translation = transform.extract_translation();
}
}
fn up_vector(rotation: &Transform) -> Vector<3> {
let d = rotation.data();
Vector::from([d[4], d[5], d[6]])
}