ranim_core/traits/transform/
rotate.rs1use glam::DVec3;
2
3use crate::traits::Discard;
4
5pub trait RotateTransform {
9 fn rotate_on_axis(&mut self, axis: DVec3, angle: f64) -> &mut Self;
11 fn rotate_on_x(&mut self, angle: f64) -> &mut Self {
13 self.rotate_on_axis(DVec3::X, angle)
14 }
15 fn rotate_on_y(&mut self, angle: f64) -> &mut Self {
17 self.rotate_on_axis(DVec3::Y, angle)
18 }
19 fn rotate_on_z(&mut self, angle: f64) -> &mut Self {
21 self.rotate_on_axis(DVec3::Z, angle)
22 }
23}
24
25impl RotateTransform for DVec3 {
26 fn rotate_on_axis(&mut self, axis: DVec3, angle: f64) -> &mut Self {
27 *self = DVec3::rotate_axis(*self, axis, angle);
28 self
29 }
30}
31
32impl<T: RotateTransform> RotateTransform for [T] {
33 fn rotate_on_axis(&mut self, axis: DVec3, angle: f64) -> &mut Self {
34 self.iter_mut()
35 .for_each(|x| x.rotate_on_axis(axis, angle).discard());
36 self
37 }
38}
39
40impl<T: RotateTransform> RotateTransform for Vec<T> {
41 fn rotate_on_axis(&mut self, axis: DVec3, angle: f64) -> &mut Self {
42 self.as_mut_slice().rotate_on_axis(axis, angle);
43 self
44 }
45}