use glam::{Mat3, Mat4, Quat, Vec2, Vec3};
use hecs::Entity;
#[derive(Clone, Copy, Debug)]
pub struct Parent(pub Entity);
#[derive(Clone, Copy, Debug)]
pub struct Transform2D {
pub position: Vec2,
pub rotation: f32,
pub scale: Vec2,
}
impl Default for Transform2D {
fn default() -> Self {
Self {
position: Vec2::ZERO,
rotation: 0.0,
scale: Vec2::ONE,
}
}
}
impl Transform2D {
pub fn at(position: Vec2) -> Self {
Self {
position,
..Self::default()
}
}
pub fn matrix(self) -> Mat3 {
Mat3::from_scale_angle_translation(self.scale, self.rotation, self.position)
}
}
#[derive(Clone, Copy, Debug)]
pub struct Transform3D {
pub position: Vec3,
pub rotation: Quat,
pub scale: Vec3,
}
impl Default for Transform3D {
fn default() -> Self {
Self {
position: Vec3::ZERO,
rotation: Quat::IDENTITY,
scale: Vec3::ONE,
}
}
}
impl Transform3D {
pub fn at(position: Vec3) -> Self {
Self {
position,
..Self::default()
}
}
pub fn matrix(self) -> Mat4 {
Mat4::from_scale_rotation_translation(self.scale, self.rotation, self.position)
}
}
#[derive(Clone, Copy, Debug)]
pub struct GlobalTransform2D(pub Mat3);
impl Default for GlobalTransform2D {
fn default() -> Self {
Self(Mat3::IDENTITY)
}
}
#[derive(Clone, Copy, Debug)]
pub struct GlobalTransform3D(pub Mat4);
impl Default for GlobalTransform3D {
fn default() -> Self {
Self(Mat4::IDENTITY)
}
}