pub struct Transform { /* private fields */ }Expand description
Validated local GPU-space transform, aligned for contiguous SIMD-friendly columns.
Implementations§
Source§impl Transform
impl Transform
Sourcepub fn new(
position: [f32; 3],
rotation: [f32; 4],
scale: [f32; 3],
) -> Result<Self, RenderError>
pub fn new( position: [f32; 3], rotation: [f32; 4], scale: [f32; 3], ) -> Result<Self, RenderError>
Construct with a unit quaternion and positive finite scale, without implicit normalization.
Sourcepub fn position(self) -> [f32; 3]
pub fn position(self) -> [f32; 3]
Local translation; global f64 coordinates belong to world/chunk positioning.
Examples found in repository?
examples/scene.rs (line 42)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 // Opaque asset identities only; this example qualifies CPU scene ownership, not drawing.
17 let mut assets = ResourceArena::new(RenderLimits::default())?;
18 let binding = RenderBinding {
19 mesh: assets.insert((), 1)?,
20 material: assets.insert((), 1)?,
21 tint: [1.0; 4],
22 animation: 0,
23 morph: 0,
24 };
25 let mut world = SceneWorld::new(SceneLimits {
26 max_entities: 64,
27 max_snapshot_instances: 64,
28 ..Default::default()
29 })?;
30 let mut first = None;
31 for i in 0..64 {
32 let id = world.spawn(
33 Transform::default().with_position([i as f32, 0.0, 0.0])?,
34 binding,
35 Some(Velocity::new([1.0, 0.0, 0.0])?),
36 )?;
37 first = first.or(Some(id));
38 }
39 let before = world.snapshot()?;
40 world.step_velocity(0.016)?;
41 let after = world.snapshot()?;
42 assert_eq!(before.instances()[0].transform.position()[0], 0.0);
43 assert_eq!(after.instances()[0].transform.position()[0], 0.016);
44 let mut commands = SceneCommands::new(8)?;
45 if let Some(first) = first {
46 commands.push(SceneCommand::SetVelocity(first, None))?;
47 }
48 for outcome in commands.apply(&mut world)? {
49 outcome?;
50 }
51 println!(
52 "entities={} owned_snapshots=2 moving_rows={}",
53 world.len(),
54 world.moving_columns().entities.len()
55 );
56 Ok(())
57}Sourcepub fn with_position(self, position: [f32; 3]) -> Result<Self, RenderError>
pub fn with_position(self, position: [f32; 3]) -> Result<Self, RenderError>
Validated replacement; rejection leaves the existing value unchanged.
Examples found in repository?
examples/scene.rs (line 33)
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16 // Opaque asset identities only; this example qualifies CPU scene ownership, not drawing.
17 let mut assets = ResourceArena::new(RenderLimits::default())?;
18 let binding = RenderBinding {
19 mesh: assets.insert((), 1)?,
20 material: assets.insert((), 1)?,
21 tint: [1.0; 4],
22 animation: 0,
23 morph: 0,
24 };
25 let mut world = SceneWorld::new(SceneLimits {
26 max_entities: 64,
27 max_snapshot_instances: 64,
28 ..Default::default()
29 })?;
30 let mut first = None;
31 for i in 0..64 {
32 let id = world.spawn(
33 Transform::default().with_position([i as f32, 0.0, 0.0])?,
34 binding,
35 Some(Velocity::new([1.0, 0.0, 0.0])?),
36 )?;
37 first = first.or(Some(id));
38 }
39 let before = world.snapshot()?;
40 world.step_velocity(0.016)?;
41 let after = world.snapshot()?;
42 assert_eq!(before.instances()[0].transform.position()[0], 0.0);
43 assert_eq!(after.instances()[0].transform.position()[0], 0.016);
44 let mut commands = SceneCommands::new(8)?;
45 if let Some(first) = first {
46 commands.push(SceneCommand::SetVelocity(first, None))?;
47 }
48 for outcome in commands.apply(&mut world)? {
49 outcome?;
50 }
51 println!(
52 "entities={} owned_snapshots=2 moving_rows={}",
53 world.len(),
54 world.moving_columns().entities.len()
55 );
56 Ok(())
57}Trait Implementations§
impl Copy for Transform
impl StructuralPartialEq for Transform
Auto Trait Implementations§
impl Freeze for Transform
impl RefUnwindSafe for Transform
impl Send for Transform
impl Sync for Transform
impl Unpin for Transform
impl UnsafeUnpin for Transform
impl UnwindSafe for Transform
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more