Add y rotation to location

This commit is contained in:
hodasemi 2025-04-01 07:46:45 +02:00
parent 1512baa2d0
commit fa35adbcc7

View file

@ -13,6 +13,7 @@ pub struct Location {
offset: Vector3<f32>,
position: Vector3<f32>,
rotation: Rad<f32>,
y_rotation: Rad<f32>,
movement_min_threshold: f32,
@ -29,6 +30,7 @@ impl Clone for Location {
offset: self.offset,
position: self.position,
rotation: self.rotation,
y_rotation: self.y_rotation,
movement_min_threshold: 0.4,
@ -49,6 +51,7 @@ impl Location {
offset: Vector3::zero(),
position: Vector3::zero(),
rotation: Rad(0.0),
y_rotation: Rad(0.0),
movement_min_threshold: 0.4,
@ -136,6 +139,16 @@ impl Location {
}
}
pub fn set_y_rotation(&mut self, y_rotation: impl Into<Rad<f32>>) {
let y_rotation = y_rotation.into();
if self.y_rotation != y_rotation {
self.y_rotation = y_rotation;
self.update_apply().unwrap();
}
}
pub fn set_position(&mut self, position: Vector3<f32>) {
if self.position != position {
self.position = position;
@ -170,6 +183,7 @@ impl Location {
fn update_matrix(&mut self) {
self.transformation = Matrix4::from_translation(self.position + self.offset)
* Matrix4::from_angle_y(self.y_rotation)
* Matrix4::from_angle_z(self.rotation)
* Matrix4::from_nonuniform_scale(self.scale.x, self.scale.y, self.scale.z);
}