Skip to main content

gust_render/
transform.rs

1//! Transform
2//! this mod is a groupment of all traits dedicated to the movement of a gust entity.
3//! You can attach these trait to anything that you need to move.
4
5use nalgebra::Scalar;
6use Vector;
7
8/// A trait that define something fully transformable.
9pub trait Transformable: Movable + Rotable + Scalable {
10    /// Move the sprite off the offset.
11    fn contain<T>(&self, offset: Vector<T>) -> bool
12    where
13        T: Scalar + Into<f32>;
14
15    /// Set the origin of the object.
16    fn set_origin<T>(&mut self, origin: Vector<T>)
17    where
18        T: Scalar + Into<f32>;
19
20    /// Get the origin of the transformable.
21    fn get_origin(&self) -> Vector<f32>;
22}
23
24/// Trait defining movable structures as sprite or higher
25pub trait Movable {
26    /// Move the sprite off the offset
27    fn translate<T>(&mut self, offset: Vector<T>)
28    where
29        T: Scalar + Into<f32>;
30
31    /// Set position of the sprite
32    fn set_position<T>(&mut self, pos: Vector<T>)
33    where
34        T: Scalar + Into<f32>;
35
36    /// Get current position
37    fn get_position(&self) -> Vector<f32>;
38}
39
40/// A trait that define everything that can rotate in a 3D space.
41pub trait Rotable {
42    /// Rotate from the actual angle with the angle given in argument.
43    fn rotate<T>(&mut self, angle: T)
44    where
45        T: Scalar + Into<f32>;
46
47    /// Set the rotation of the Rotable struct.
48    fn set_rotation<T>(&mut self, angle: T)
49    where
50        T: Scalar + Into<f32>;
51
52    /// Return the rotation of the struct.
53    fn get_rotation(&self) -> f32;
54}
55
56pub trait Scalable {
57    /// Scale the sprite from a factor
58    fn scale<T>(&mut self, factor: Vector<T>)
59    where
60        T: Scalar + Into<f32>;
61
62    /// Set the scale of the sprite
63    fn set_scale<T>(&mut self, vec: Vector<T>)
64    where
65        T: Scalar + Into<f32>;
66
67    /// Get the current scale
68    fn get_scale(&self) -> Vector<f32>;
69}