pub struct Velocity(/* private fields */);Expand description
Validated bounded velocity component; no fluid/rigid-body solver is implied.
Implementations§
Source§impl Velocity
impl Velocity
Sourcepub fn new(value: [f32; 3]) -> Result<Self, RenderError>
pub fn new(value: [f32; 3]) -> Result<Self, RenderError>
Reject non-finite or excessively large local velocities before storing them.
Examples found in repository?
examples/scene.rs (line 35)
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 Velocity
impl StructuralPartialEq for Velocity
Auto Trait Implementations§
impl Freeze for Velocity
impl RefUnwindSafe for Velocity
impl Send for Velocity
impl Sync for Velocity
impl Unpin for Velocity
impl UnsafeUnpin for Velocity
impl UnwindSafe for Velocity
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