use galeon_engine_macros::Component;
use crate::entity::Entity;
#[derive(Component, Debug, Clone, Copy, PartialEq)]
pub struct Transform {
pub position: [f32; 3],
pub rotation: [f32; 4],
pub scale: [f32; 3],
}
impl Transform {
pub fn identity() -> Self {
Self {
position: [0.0, 0.0, 0.0],
rotation: [0.0, 0.0, 0.0, 1.0],
scale: [1.0, 1.0, 1.0],
}
}
pub fn from_position(x: f32, y: f32, z: f32) -> Self {
Self {
position: [x, y, z],
..Self::identity()
}
}
}
impl Default for Transform {
fn default() -> Self {
Self::identity()
}
}
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq)]
pub struct Visibility {
pub visible: bool,
}
impl Default for Visibility {
fn default() -> Self {
Self { visible: true }
}
}
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MeshHandle {
pub id: u32,
}
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MaterialHandle {
pub id: u32,
}
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ParentEntity(pub Entity);
#[derive(Component, Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum ObjectType {
#[default]
Mesh = 0,
PointLight = 1,
DirectionalLight = 2,
LineSegments = 3,
Group = 4,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn transform_identity() {
let t = Transform::identity();
assert_eq!(t.position, [0.0, 0.0, 0.0]);
assert_eq!(t.rotation, [0.0, 0.0, 0.0, 1.0]);
assert_eq!(t.scale, [1.0, 1.0, 1.0]);
}
#[test]
fn transform_from_position() {
let t = Transform::from_position(1.0, 2.0, 3.0);
assert_eq!(t.position, [1.0, 2.0, 3.0]);
assert_eq!(t.scale, [1.0, 1.0, 1.0]);
}
#[test]
fn visibility_default_is_visible() {
assert!(Visibility::default().visible);
}
#[test]
fn parent_entity_stores_entity() {
let entity = crate::entity::Entity::from_raw(42, 0);
let parent = ParentEntity(entity);
assert_eq!(parent.0, entity);
}
#[test]
fn object_type_default_is_mesh() {
assert_eq!(ObjectType::default(), ObjectType::Mesh);
}
#[test]
fn object_type_as_u8() {
assert_eq!(ObjectType::Mesh as u8, 0);
assert_eq!(ObjectType::PointLight as u8, 1);
assert_eq!(ObjectType::DirectionalLight as u8, 2);
assert_eq!(ObjectType::LineSegments as u8, 3);
assert_eq!(ObjectType::Group as u8, 4);
}
}