4acf1d821d
- AppHandler::render now receives the current &Frame; its default implementation renders the whole scene automatically via app.render_scene(frame.view()) (Option A). Users can simply not implement render for full auto-rendering. - Add Renderer::render_scene: batch-renders every scene entity in a single render pass. Factored per-mesh draw logic into a private draw_entity helper shared with Renderer::render. - Add App::render_scene(view) delegating to the Renderer. - Fill simple.rs with a real quad (mesh/material/entity) without importing wgpu; the scene now auto-renders via the trait default.
46 lines
1.4 KiB
Rust
46 lines
1.4 KiB
Rust
//! # Transform Module
|
|
//!
|
|
//! Defines the `Transform` struct for representing object transformations in 3D space,
|
|
//! including translation, rotation, and scale. Also provides functionality to convert
|
|
//! the transform into a 4x4 matrix for use in shaders.
|
|
//!
|
|
//! ## Usage
|
|
//! - Used by `Scene` entities to define their position in the world
|
|
//! - Converted to `Mat4` for MVP matrix calculations in the renderer
|
|
//!
|
|
//! ## Related Types
|
|
//! - `Transform`: Core struct for position/rotation/scale
|
|
//! - `to_matrix()`: Converts transform to a 4x4 matrix
|
|
|
|
use glam::{Mat4, Quat, Vec3};
|
|
|
|
/// Represents a 3D transformation with translation, rotation, and scale.
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
pub struct Transform {
|
|
/// Translation vector in 3D space
|
|
pub translation: Vec3,
|
|
/// Rotation as a quaternion
|
|
pub rotation: Quat,
|
|
/// Scale factors along X, Y, Z axes
|
|
pub scale: Vec3,
|
|
}
|
|
|
|
impl Transform {
|
|
/// Creates a new identity transform.
|
|
pub fn identity() -> Self {
|
|
Self {
|
|
translation: Vec3::ZERO,
|
|
rotation: Quat::IDENTITY,
|
|
scale: Vec3::ONE,
|
|
}
|
|
}
|
|
|
|
/// Converts the transform into a 4x4 transformation matrix.
|
|
///
|
|
/// # Returns
|
|
/// A `Mat4` representing the transformation matrix
|
|
pub fn to_matrix(&self) -> Mat4 {
|
|
Mat4::from_scale_rotation_translation(self.scale, self.rotation, self.translation)
|
|
}
|
|
}
|