1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
use crate::glm; use std::default::Default; #[derive(Copy, Clone)] pub struct Transform { pub position: glm::Vec3, pub rotation: glm::Quat, pub scale: glm::Vec3, } impl Transform { pub fn new() -> Self { Transform { position: glm::vec3(0.0, 0.0, 0.0), rotation: glm::quat_identity(), scale: glm::vec3(1.0, 1.0, 1.0), } } pub fn matrix(&self) -> glm::Mat4 { glm::scale( &(glm::translation(&self.position) * glm::quat_to_mat4(&self.rotation)), &self.scale, ) } pub fn normal_matrix(matrix: &glm::Mat4) -> glm::Mat3 { glm::mat4_to_mat3(&glm::inverse_transpose(*matrix)) } pub fn from_pos(position: glm::Vec3) -> Self { Transform { position, rotation: glm::quat_identity(), scale: glm::vec3(1.0, 1.0, 1.0), } } } impl Default for Transform { fn default() -> Self { Transform { position: glm::vec3(0.0, 0.0, 0.0), rotation: glm::quat_identity(), scale: glm::vec3(1.0, 1.0, 1.0), } } }