sevenx_engine 0.2.11

Engine de jogos 2D/3D completa com suporte Android, física, áudio, partículas, tilemap, UI, eventos e sistema 3D avançado com PBR.
Documentation
/// Representa a transformação espacial de um objeto (posição, rotação, escala).
#[derive(Debug, Clone, Copy)]
pub struct Transform {
    pub position: (f32, f32),
    pub rotation: f32,  // Em radianos
    pub scale: (f32, f32),
    pub flip_h: bool,   // Flip horizontal
    pub flip_v: bool,   // Flip vertical
}

impl Transform {
    pub fn new(x: f32, y: f32) -> Self {
        Self {
            position: (x, y),
            rotation: 0.0,
            scale: (1.0, 1.0),
            flip_h: false,
            flip_v: false,
        }
    }

    pub fn with_scale(mut self, scale_x: f32, scale_y: f32) -> Self {
        self.scale = (scale_x, scale_y);
        self
    }

    pub fn with_rotation(mut self, rotation: f32) -> Self {
        self.rotation = rotation;
        self
    }

    pub fn with_flip_h(mut self, flip: bool) -> Self {
        self.flip_h = flip;
        self
    }

    pub fn with_flip_v(mut self, flip: bool) -> Self {
        self.flip_v = flip;
        self
    }

    pub fn translate(&mut self, dx: f32, dy: f32) {
        self.position.0 += dx;
        self.position.1 += dy;
    }

    pub fn rotate(&mut self, angle: f32) {
        self.rotation += angle;
    }

    pub fn set_rotation(&mut self, angle: f32) {
        self.rotation = angle;
    }

    pub fn set_rotation_degrees(&mut self, degrees: f32) {
        self.rotation = degrees.to_radians();
    }

    pub fn get_rotation_degrees(&self) -> f32 {
        self.rotation.to_degrees()
    }

    /// Rotaciona um ponto ao redor da origem.
    pub fn rotate_point(&self, x: f32, y: f32) -> (f32, f32) {
        let cos = self.rotation.cos();
        let sin = self.rotation.sin();
        (x * cos - y * sin, x * sin + y * cos)
    }
}

impl Default for Transform {
    fn default() -> Self {
        Self {
            position: (0.0, 0.0),
            rotation: 0.0,
            scale: (1.0, 1.0),
            flip_h: false,
            flip_v: false,
        }
    }
}