pub trait Scene: Class<PxScene> + UserData {
type ArticulationLink: ArticulationLink;
type RigidStatic: RigidStatic;
type RigidDynamic: RigidDynamic;
type ArticulationReducedCoordinate: ArticulationReducedCoordinate;
type ActorMap: RigidActor;
type Aggregate: Aggregate;
Show 39 methods
// Provided methods
unsafe fn from_raw(ptr: *mut PxScene) -> Option<Owner<Self>> { ... }
fn get_user_data(&self) -> &Self::UserData { ... }
fn get_user_data_mut(&mut self) -> *mut Self::UserData { ... }
fn get_pvd_client(&mut self) -> Option<&mut PvdSceneClient> { ... }
fn create_controller_manager<C: Controller>(
&mut self,
locking_enabled: bool
) -> Option<Owner<PxControllerManager<C>>> { ... }
fn add_dynamic_actor(&mut self, actor: Owner<Self::RigidDynamic>) { ... }
fn add_dynamic_actors(&mut self, actors: Vec<Owner<Self::RigidDynamic>>) { ... }
fn add_static_actor(&mut self, actor: Owner<Self::RigidStatic>) { ... }
fn add_static_actors(&mut self, actors: Vec<Owner<Self::RigidStatic>>) { ... }
fn add_articulation_link(&mut self, actor: Owner<Self::ArticulationLink>) { ... }
fn add_articulation_links(
&mut self,
actors: Vec<Owner<Self::ArticulationLink>>
) { ... }
fn remove_actor(&mut self, actor: &mut impl Actor, wake_touching: bool) { ... }
fn remove_actors(&mut self, actors: Vec<&mut impl Actor>, wake_touching: bool) { ... }
fn add_articulation(
&mut self,
articulation: Owner<Self::ArticulationReducedCoordinate>
) { ... }
fn remove_articulation(
&mut self,
articulation: &mut Self::ArticulationReducedCoordinate,
wake_touching: bool
) { ... }
fn add_aggregate(&mut self, aggregate: Owner<Self::Aggregate>) { ... }
fn remove_aggregate(
&mut self,
aggregate: &mut Self::Aggregate,
wake_touching: bool
) { ... }
fn add_pruning_structure(
&mut self,
pruning_structure: Owner<PruningStructure>
) { ... }
fn simulate(
&mut self,
time_step: f32,
completion_task: Option<&mut PxBaseTask>,
scratch: Option<&mut ScratchBuffer>
) { ... }
fn fetch_results(&mut self, block: bool) -> Result<(), u32> { ... }
fn step(
&mut self,
time_step: f32,
completion_task: Option<&mut PxBaseTask>,
scratch: Option<&mut ScratchBuffer>,
block: bool
) -> Result<(), u32> { ... }
fn get_articulations(
&mut self
) -> Vec<&mut Self::ArticulationReducedCoordinate> { ... }
fn get_actors(
&mut self,
actor_types: ActorTypeFlags
) -> Vec<&mut Self::ActorMap> { ... }
fn get_active_actors(&mut self) -> &mut [&mut Self::ActorMap] { ... }
fn get_static_actors(&mut self) -> Vec<&mut Self::RigidStatic> { ... }
fn get_dynamic_actors(&mut self) -> Vec<&mut Self::RigidDynamic> { ... }
fn get_aggregates(&mut self) -> Vec<&mut Self::Aggregate> { ... }
fn get_constraints(&mut self) -> Vec<&mut Constraint> { ... }
unsafe fn set_contact_modify_callback(
&mut self,
callback: &mut PxContactModifyCallback
) { ... }
unsafe fn get_contact_modify_callback(&self) -> &PxContactModifyCallback { ... }
unsafe fn set_ccd_contact_modify_callback(
&mut self,
callback: &mut PxCCDContactModifyCallback
) { ... }
unsafe fn get_ccd_contact_callback(&self) -> &PxCCDContactModifyCallback { ... }
unsafe fn set_broad_phase_callback(
&mut self,
callback: &mut PxBroadPhaseCallback
) { ... }
unsafe fn get_broad_phase_callback(&self) -> &PxBroadPhaseCallback { ... }
fn reset_filtering(&mut self, actor: &mut impl Actor) -> bool { ... }
fn reset_rigid_actor_filtering<R: RigidActor>(
&mut self,
actor: &mut R,
shapes: &[&mut R::Shape]
) { ... }
fn get_kinematic_kinematic_filtering_mode(&self) -> PairFilteringMode { ... }
fn get_static_kinematic_filtering_mode(&self) -> PairFilteringMode { ... }
fn set_gravity(&mut self, x: f32, y: f32, z: f32) { ... }
}
Required Associated Types§
type ArticulationLink: ArticulationLink
type RigidStatic: RigidStatic
type RigidDynamic: RigidDynamic
type ArticulationReducedCoordinate: ArticulationReducedCoordinate
type ActorMap: RigidActor
type Aggregate: Aggregate
Provided Methods§
sourceunsafe fn from_raw(ptr: *mut PxScene) -> Option<Owner<Self>>
unsafe fn from_raw(ptr: *mut PxScene) -> Option<Owner<Self>>
Safety
Owner’s own the pointer they wrap, using the pointer after dropping the Owner,
or creating multiple Owners from the same pointer will cause UB. Use into_ptr
to
retrieve the pointer and consume the Owner without dropping the pointee.
sourcefn get_user_data(&self) -> &Self::UserData
fn get_user_data(&self) -> &Self::UserData
Get the user data.
sourcefn get_user_data_mut(&mut self) -> *mut Self::UserData
fn get_user_data_mut(&mut self) -> *mut Self::UserData
Get the user data.
sourcefn get_pvd_client(&mut self) -> Option<&mut PvdSceneClient>
fn get_pvd_client(&mut self) -> Option<&mut PvdSceneClient>
Get the visual debugger client
sourcefn create_controller_manager<C: Controller>(
&mut self,
locking_enabled: bool
) -> Option<Owner<PxControllerManager<C>>>
fn create_controller_manager<C: Controller>( &mut self, locking_enabled: bool ) -> Option<Owner<PxControllerManager<C>>>
Create a controller manager.
sourcefn add_dynamic_actor(&mut self, actor: Owner<Self::RigidDynamic>)
fn add_dynamic_actor(&mut self, actor: Owner<Self::RigidDynamic>)
Add a dynamic actor to the world.
Examples found in repository?
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
fn main() {
// Holds a PxFoundation and a PxPhysics.
// Also has an optional Pvd and transport, not enabled by default.
// The default allocator is the one provided by PhysX.
let mut physics = PhysicsFoundation::<_, PxShape>::default();
physics.set_profiler(PrintProfilerCallback {
start: std::time::Instant::now(),
});
// Setup the scene object. The PxScene type alias makes this much cleaner.
// There are lots of unwrap calls due to potential null pointers.
let mut scene: Owner<PxScene> = physics
.create(SceneDescriptor {
gravity: PxVec3::new(0.0, -9.81, 0.0),
on_advance: Some(OnAdvance),
..SceneDescriptor::new(())
})
.unwrap();
let mut material = physics.create_material(0.5, 0.5, 0.6, ()).unwrap();
let ground_plane = physics
.create_plane(PxVec3::new(0.0, 1.0, 0.0), 0.0, material.as_mut(), ())
.unwrap();
// The scene owns actors that are added to it. They can be retrieved using the
// various getters on the scene.
scene.add_static_actor(ground_plane);
let sphere_geo = PxSphereGeometry::new(10.0);
let mut sphere_actor = physics
.create_rigid_dynamic(
PxTransform::from_translation(&PxVec3::new(0.0, 40.0, 100.0)),
&sphere_geo,
material.as_mut(),
10.0,
PxTransform::default(),
(),
)
.unwrap();
sphere_actor.set_angular_damping(0.5);
sphere_actor.set_rigid_body_flag(RigidBodyFlag::EnablePoseIntegrationPreview, true);
scene.add_dynamic_actor(sphere_actor);
for _ in 0..100 {
#[allow(unsafe_code)]
// SAFETY: it's unsafe /shrug
let mut sb = unsafe { ScratchBuffer::new(4) };
// Calls both simulate and fetch_results. More complex simulation update
// controls are not fully supported.
scene
.step(0.1, None::<&mut physx_sys::PxBaseTask>, Some(&mut sb), true)
.expect("error occured during simulation");
}
}
More examples
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
fn main() {
// Holds a PxFoundation and a PxPhysics.
// Also has an optional Pvd and transport, not enabled by default.
// The default allocator is the one provided by PhysX.
let mut physics = PhysicsFoundation::<_, PxShape>::default();
// Setup the scene object. The PxScene type alias makes this much cleaner.
// There are lots of unwrap calls due to potential null pointers.
let mut scene: Owner<PxScene> = physics
.create(SceneDescriptor {
gravity: PxVec3::new(0.0, -9.81, 0.0),
on_advance: Some(OnAdvance),
..SceneDescriptor::new(())
})
.unwrap();
let mut material = physics.create_material(0.5, 0.5, 0.6, ()).unwrap();
let ground_plane = physics
.create_plane(PxVec3::new(0.0, 1.0, 0.0), 0.0, material.as_mut(), ())
.unwrap();
// The scene owns actors that are added to it. They can be retrieved using the
// various getters on the scene.
scene.add_static_actor(ground_plane);
let sphere_geo = PxSphereGeometry::new(10.0);
let mut sphere_actor = physics
.create_rigid_dynamic(
PxTransform::from_translation(&PxVec3::new(0.0, 40.0, 100.0)),
&sphere_geo,
material.as_mut(),
10.0,
PxTransform::default(),
(),
)
.unwrap();
sphere_actor.set_angular_damping(0.5);
sphere_actor.set_rigid_body_flag(RigidBodyFlag::EnablePoseIntegrationPreview, true);
scene.add_dynamic_actor(sphere_actor);
// SAFETY: scratch buffer creation
#[allow(unsafe_code)]
let mut scratch = unsafe { ScratchBuffer::new(4) };
// Updating
let heights_over_time = (0..100)
.map(|_| {
// Calls both simulate and fetch_results. More complex simulation update
// controls are not fully supported.
scene
.step(
0.1,
None::<&mut physx_sys::PxBaseTask>,
Some(&mut scratch),
true,
)
.expect("error occured during simulation");
// For simplicity, just read out the only dynamic actor in the scene.
// getActiveActors is also supported, it returns a Vec<&mut ActorMap> which has
// a map method that takes a function for each actor type, and `as_<T>` methods
// that return an Option<&mut T>.
let actors = scene.get_dynamic_actors();
actors[0].get_global_position().y() as i32 - 10
})
.collect::<Vec<_>>();
// Draw to stdout
let max_h = 18;
(0..max_h)
.map(|h| {
let h = max_h - 1 - h;
heights_over_time
.iter()
.enumerate()
.map(|(_t, p)| if h == *p { 'o' } else { ' ' })
.collect::<String>()
})
.for_each(|line| println!("{}", line));
}
sourcefn add_dynamic_actors(&mut self, actors: Vec<Owner<Self::RigidDynamic>>)
fn add_dynamic_actors(&mut self, actors: Vec<Owner<Self::RigidDynamic>>)
Add dynamic actors to the world.
sourcefn add_static_actor(&mut self, actor: Owner<Self::RigidStatic>)
fn add_static_actor(&mut self, actor: Owner<Self::RigidStatic>)
Add a static actor to the world.
Examples found in repository?
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
fn main() {
// Holds a PxFoundation and a PxPhysics.
// Also has an optional Pvd and transport, not enabled by default.
// The default allocator is the one provided by PhysX.
let mut physics = PhysicsFoundation::<_, PxShape>::default();
physics.set_profiler(PrintProfilerCallback {
start: std::time::Instant::now(),
});
// Setup the scene object. The PxScene type alias makes this much cleaner.
// There are lots of unwrap calls due to potential null pointers.
let mut scene: Owner<PxScene> = physics
.create(SceneDescriptor {
gravity: PxVec3::new(0.0, -9.81, 0.0),
on_advance: Some(OnAdvance),
..SceneDescriptor::new(())
})
.unwrap();
let mut material = physics.create_material(0.5, 0.5, 0.6, ()).unwrap();
let ground_plane = physics
.create_plane(PxVec3::new(0.0, 1.0, 0.0), 0.0, material.as_mut(), ())
.unwrap();
// The scene owns actors that are added to it. They can be retrieved using the
// various getters on the scene.
scene.add_static_actor(ground_plane);
let sphere_geo = PxSphereGeometry::new(10.0);
let mut sphere_actor = physics
.create_rigid_dynamic(
PxTransform::from_translation(&PxVec3::new(0.0, 40.0, 100.0)),
&sphere_geo,
material.as_mut(),
10.0,
PxTransform::default(),
(),
)
.unwrap();
sphere_actor.set_angular_damping(0.5);
sphere_actor.set_rigid_body_flag(RigidBodyFlag::EnablePoseIntegrationPreview, true);
scene.add_dynamic_actor(sphere_actor);
for _ in 0..100 {
#[allow(unsafe_code)]
// SAFETY: it's unsafe /shrug
let mut sb = unsafe { ScratchBuffer::new(4) };
// Calls both simulate and fetch_results. More complex simulation update
// controls are not fully supported.
scene
.step(0.1, None::<&mut physx_sys::PxBaseTask>, Some(&mut sb), true)
.expect("error occured during simulation");
}
}
More examples
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
fn main() {
// Holds a PxFoundation and a PxPhysics.
// Also has an optional Pvd and transport, not enabled by default.
// The default allocator is the one provided by PhysX.
let mut physics = PhysicsFoundation::<_, PxShape>::default();
// Setup the scene object. The PxScene type alias makes this much cleaner.
// There are lots of unwrap calls due to potential null pointers.
let mut scene: Owner<PxScene> = physics
.create(SceneDescriptor {
gravity: PxVec3::new(0.0, -9.81, 0.0),
on_advance: Some(OnAdvance),
..SceneDescriptor::new(())
})
.unwrap();
let mut material = physics.create_material(0.5, 0.5, 0.6, ()).unwrap();
let ground_plane = physics
.create_plane(PxVec3::new(0.0, 1.0, 0.0), 0.0, material.as_mut(), ())
.unwrap();
// The scene owns actors that are added to it. They can be retrieved using the
// various getters on the scene.
scene.add_static_actor(ground_plane);
let sphere_geo = PxSphereGeometry::new(10.0);
let mut sphere_actor = physics
.create_rigid_dynamic(
PxTransform::from_translation(&PxVec3::new(0.0, 40.0, 100.0)),
&sphere_geo,
material.as_mut(),
10.0,
PxTransform::default(),
(),
)
.unwrap();
sphere_actor.set_angular_damping(0.5);
sphere_actor.set_rigid_body_flag(RigidBodyFlag::EnablePoseIntegrationPreview, true);
scene.add_dynamic_actor(sphere_actor);
// SAFETY: scratch buffer creation
#[allow(unsafe_code)]
let mut scratch = unsafe { ScratchBuffer::new(4) };
// Updating
let heights_over_time = (0..100)
.map(|_| {
// Calls both simulate and fetch_results. More complex simulation update
// controls are not fully supported.
scene
.step(
0.1,
None::<&mut physx_sys::PxBaseTask>,
Some(&mut scratch),
true,
)
.expect("error occured during simulation");
// For simplicity, just read out the only dynamic actor in the scene.
// getActiveActors is also supported, it returns a Vec<&mut ActorMap> which has
// a map method that takes a function for each actor type, and `as_<T>` methods
// that return an Option<&mut T>.
let actors = scene.get_dynamic_actors();
actors[0].get_global_position().y() as i32 - 10
})
.collect::<Vec<_>>();
// Draw to stdout
let max_h = 18;
(0..max_h)
.map(|h| {
let h = max_h - 1 - h;
heights_over_time
.iter()
.enumerate()
.map(|(_t, p)| if h == *p { 'o' } else { ' ' })
.collect::<String>()
})
.for_each(|line| println!("{}", line));
}
sourcefn add_static_actors(&mut self, actors: Vec<Owner<Self::RigidStatic>>)
fn add_static_actors(&mut self, actors: Vec<Owner<Self::RigidStatic>>)
Add dynamic actors to the world.
sourcefn add_articulation_link(&mut self, actor: Owner<Self::ArticulationLink>)
fn add_articulation_link(&mut self, actor: Owner<Self::ArticulationLink>)
Add an articulation link to the world.
sourcefn add_articulation_links(&mut self, actors: Vec<Owner<Self::ArticulationLink>>)
fn add_articulation_links(&mut self, actors: Vec<Owner<Self::ArticulationLink>>)
Add articulation links to the world.
sourcefn remove_actor(&mut self, actor: &mut impl Actor, wake_touching: bool)
fn remove_actor(&mut self, actor: &mut impl Actor, wake_touching: bool)
Remove an actor from the scene.
sourcefn remove_actors(&mut self, actors: Vec<&mut impl Actor>, wake_touching: bool)
fn remove_actors(&mut self, actors: Vec<&mut impl Actor>, wake_touching: bool)
Remove actors from the scene.
sourcefn add_articulation(
&mut self,
articulation: Owner<Self::ArticulationReducedCoordinate>
)
fn add_articulation( &mut self, articulation: Owner<Self::ArticulationReducedCoordinate> )
Add an articulation to the scene.
sourcefn remove_articulation(
&mut self,
articulation: &mut Self::ArticulationReducedCoordinate,
wake_touching: bool
)
fn remove_articulation( &mut self, articulation: &mut Self::ArticulationReducedCoordinate, wake_touching: bool )
Remove an articulation from the scene.
sourcefn add_aggregate(&mut self, aggregate: Owner<Self::Aggregate>)
fn add_aggregate(&mut self, aggregate: Owner<Self::Aggregate>)
Add an aggregate to the scene.
sourcefn remove_aggregate(
&mut self,
aggregate: &mut Self::Aggregate,
wake_touching: bool
)
fn remove_aggregate( &mut self, aggregate: &mut Self::Aggregate, wake_touching: bool )
Remove an aggregate from the scene.
sourcefn add_pruning_structure(&mut self, pruning_structure: Owner<PruningStructure>)
fn add_pruning_structure(&mut self, pruning_structure: Owner<PruningStructure>)
Add a rpuning structure to the scene.
sourcefn simulate(
&mut self,
time_step: f32,
completion_task: Option<&mut PxBaseTask>,
scratch: Option<&mut ScratchBuffer>
)
fn simulate( &mut self, time_step: f32, completion_task: Option<&mut PxBaseTask>, scratch: Option<&mut ScratchBuffer> )
Run a simulation update step.
sourcefn fetch_results(&mut self, block: bool) -> Result<(), u32>
fn fetch_results(&mut self, block: bool) -> Result<(), u32>
Check if or wait until simulate
has completed. Returns Ok(()) when it has, Err otherwise.
sourcefn step(
&mut self,
time_step: f32,
completion_task: Option<&mut PxBaseTask>,
scratch: Option<&mut ScratchBuffer>,
block: bool
) -> Result<(), u32>
fn step( &mut self, time_step: f32, completion_task: Option<&mut PxBaseTask>, scratch: Option<&mut ScratchBuffer>, block: bool ) -> Result<(), u32>
Combines simulate
and fetch_results
into one call.
Examples found in repository?
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
fn main() {
// Holds a PxFoundation and a PxPhysics.
// Also has an optional Pvd and transport, not enabled by default.
// The default allocator is the one provided by PhysX.
let mut physics = PhysicsFoundation::<_, PxShape>::default();
physics.set_profiler(PrintProfilerCallback {
start: std::time::Instant::now(),
});
// Setup the scene object. The PxScene type alias makes this much cleaner.
// There are lots of unwrap calls due to potential null pointers.
let mut scene: Owner<PxScene> = physics
.create(SceneDescriptor {
gravity: PxVec3::new(0.0, -9.81, 0.0),
on_advance: Some(OnAdvance),
..SceneDescriptor::new(())
})
.unwrap();
let mut material = physics.create_material(0.5, 0.5, 0.6, ()).unwrap();
let ground_plane = physics
.create_plane(PxVec3::new(0.0, 1.0, 0.0), 0.0, material.as_mut(), ())
.unwrap();
// The scene owns actors that are added to it. They can be retrieved using the
// various getters on the scene.
scene.add_static_actor(ground_plane);
let sphere_geo = PxSphereGeometry::new(10.0);
let mut sphere_actor = physics
.create_rigid_dynamic(
PxTransform::from_translation(&PxVec3::new(0.0, 40.0, 100.0)),
&sphere_geo,
material.as_mut(),
10.0,
PxTransform::default(),
(),
)
.unwrap();
sphere_actor.set_angular_damping(0.5);
sphere_actor.set_rigid_body_flag(RigidBodyFlag::EnablePoseIntegrationPreview, true);
scene.add_dynamic_actor(sphere_actor);
for _ in 0..100 {
#[allow(unsafe_code)]
// SAFETY: it's unsafe /shrug
let mut sb = unsafe { ScratchBuffer::new(4) };
// Calls both simulate and fetch_results. More complex simulation update
// controls are not fully supported.
scene
.step(0.1, None::<&mut physx_sys::PxBaseTask>, Some(&mut sb), true)
.expect("error occured during simulation");
}
}
More examples
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
fn main() {
// Holds a PxFoundation and a PxPhysics.
// Also has an optional Pvd and transport, not enabled by default.
// The default allocator is the one provided by PhysX.
let mut physics = PhysicsFoundation::<_, PxShape>::default();
// Setup the scene object. The PxScene type alias makes this much cleaner.
// There are lots of unwrap calls due to potential null pointers.
let mut scene: Owner<PxScene> = physics
.create(SceneDescriptor {
gravity: PxVec3::new(0.0, -9.81, 0.0),
on_advance: Some(OnAdvance),
..SceneDescriptor::new(())
})
.unwrap();
let mut material = physics.create_material(0.5, 0.5, 0.6, ()).unwrap();
let ground_plane = physics
.create_plane(PxVec3::new(0.0, 1.0, 0.0), 0.0, material.as_mut(), ())
.unwrap();
// The scene owns actors that are added to it. They can be retrieved using the
// various getters on the scene.
scene.add_static_actor(ground_plane);
let sphere_geo = PxSphereGeometry::new(10.0);
let mut sphere_actor = physics
.create_rigid_dynamic(
PxTransform::from_translation(&PxVec3::new(0.0, 40.0, 100.0)),
&sphere_geo,
material.as_mut(),
10.0,
PxTransform::default(),
(),
)
.unwrap();
sphere_actor.set_angular_damping(0.5);
sphere_actor.set_rigid_body_flag(RigidBodyFlag::EnablePoseIntegrationPreview, true);
scene.add_dynamic_actor(sphere_actor);
// SAFETY: scratch buffer creation
#[allow(unsafe_code)]
let mut scratch = unsafe { ScratchBuffer::new(4) };
// Updating
let heights_over_time = (0..100)
.map(|_| {
// Calls both simulate and fetch_results. More complex simulation update
// controls are not fully supported.
scene
.step(
0.1,
None::<&mut physx_sys::PxBaseTask>,
Some(&mut scratch),
true,
)
.expect("error occured during simulation");
// For simplicity, just read out the only dynamic actor in the scene.
// getActiveActors is also supported, it returns a Vec<&mut ActorMap> which has
// a map method that takes a function for each actor type, and `as_<T>` methods
// that return an Option<&mut T>.
let actors = scene.get_dynamic_actors();
actors[0].get_global_position().y() as i32 - 10
})
.collect::<Vec<_>>();
// Draw to stdout
let max_h = 18;
(0..max_h)
.map(|h| {
let h = max_h - 1 - h;
heights_over_time
.iter()
.enumerate()
.map(|(_t, p)| if h == *p { 'o' } else { ' ' })
.collect::<String>()
})
.for_each(|line| println!("{}", line));
}
sourcefn get_articulations(&mut self) -> Vec<&mut Self::ArticulationReducedCoordinate>
fn get_articulations(&mut self) -> Vec<&mut Self::ArticulationReducedCoordinate>
Get a Vec of the articulations in the scene.
sourcefn get_actors(&mut self, actor_types: ActorTypeFlags) -> Vec<&mut Self::ActorMap>
fn get_actors(&mut self, actor_types: ActorTypeFlags) -> Vec<&mut Self::ActorMap>
Get the actors in the scene, filtered by ActorTypeFlags.
sourcefn get_active_actors(&mut self) -> &mut [&mut Self::ActorMap]
fn get_active_actors(&mut self) -> &mut [&mut Self::ActorMap]
Get the active actor buffer of actors that were updated during the last simulate
call.
sourcefn get_static_actors(&mut self) -> Vec<&mut Self::RigidStatic>
fn get_static_actors(&mut self) -> Vec<&mut Self::RigidStatic>
Get the static actors in the scene.
sourcefn get_dynamic_actors(&mut self) -> Vec<&mut Self::RigidDynamic>
fn get_dynamic_actors(&mut self) -> Vec<&mut Self::RigidDynamic>
Get the dynamic actors in the scene.
Examples found in repository?
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
fn main() {
// Holds a PxFoundation and a PxPhysics.
// Also has an optional Pvd and transport, not enabled by default.
// The default allocator is the one provided by PhysX.
let mut physics = PhysicsFoundation::<_, PxShape>::default();
// Setup the scene object. The PxScene type alias makes this much cleaner.
// There are lots of unwrap calls due to potential null pointers.
let mut scene: Owner<PxScene> = physics
.create(SceneDescriptor {
gravity: PxVec3::new(0.0, -9.81, 0.0),
on_advance: Some(OnAdvance),
..SceneDescriptor::new(())
})
.unwrap();
let mut material = physics.create_material(0.5, 0.5, 0.6, ()).unwrap();
let ground_plane = physics
.create_plane(PxVec3::new(0.0, 1.0, 0.0), 0.0, material.as_mut(), ())
.unwrap();
// The scene owns actors that are added to it. They can be retrieved using the
// various getters on the scene.
scene.add_static_actor(ground_plane);
let sphere_geo = PxSphereGeometry::new(10.0);
let mut sphere_actor = physics
.create_rigid_dynamic(
PxTransform::from_translation(&PxVec3::new(0.0, 40.0, 100.0)),
&sphere_geo,
material.as_mut(),
10.0,
PxTransform::default(),
(),
)
.unwrap();
sphere_actor.set_angular_damping(0.5);
sphere_actor.set_rigid_body_flag(RigidBodyFlag::EnablePoseIntegrationPreview, true);
scene.add_dynamic_actor(sphere_actor);
// SAFETY: scratch buffer creation
#[allow(unsafe_code)]
let mut scratch = unsafe { ScratchBuffer::new(4) };
// Updating
let heights_over_time = (0..100)
.map(|_| {
// Calls both simulate and fetch_results. More complex simulation update
// controls are not fully supported.
scene
.step(
0.1,
None::<&mut physx_sys::PxBaseTask>,
Some(&mut scratch),
true,
)
.expect("error occured during simulation");
// For simplicity, just read out the only dynamic actor in the scene.
// getActiveActors is also supported, it returns a Vec<&mut ActorMap> which has
// a map method that takes a function for each actor type, and `as_<T>` methods
// that return an Option<&mut T>.
let actors = scene.get_dynamic_actors();
actors[0].get_global_position().y() as i32 - 10
})
.collect::<Vec<_>>();
// Draw to stdout
let max_h = 18;
(0..max_h)
.map(|h| {
let h = max_h - 1 - h;
heights_over_time
.iter()
.enumerate()
.map(|(_t, p)| if h == *p { 'o' } else { ' ' })
.collect::<String>()
})
.for_each(|line| println!("{}", line));
}
sourcefn get_aggregates(&mut self) -> Vec<&mut Self::Aggregate>
fn get_aggregates(&mut self) -> Vec<&mut Self::Aggregate>
Get the aggregates in the scene.
sourcefn get_constraints(&mut self) -> Vec<&mut Constraint>
fn get_constraints(&mut self) -> Vec<&mut Constraint>
Get all the constraints currently in this scene.
sourceunsafe fn set_contact_modify_callback(
&mut self,
callback: &mut PxContactModifyCallback
)
unsafe fn set_contact_modify_callback( &mut self, callback: &mut PxContactModifyCallback )
sourceunsafe fn get_contact_modify_callback(&self) -> &PxContactModifyCallback
unsafe fn get_contact_modify_callback(&self) -> &PxContactModifyCallback
sourceunsafe fn set_ccd_contact_modify_callback(
&mut self,
callback: &mut PxCCDContactModifyCallback
)
unsafe fn set_ccd_contact_modify_callback( &mut self, callback: &mut PxCCDContactModifyCallback )
sourceunsafe fn get_ccd_contact_callback(&self) -> &PxCCDContactModifyCallback
unsafe fn get_ccd_contact_callback(&self) -> &PxCCDContactModifyCallback
sourceunsafe fn set_broad_phase_callback(
&mut self,
callback: &mut PxBroadPhaseCallback
)
unsafe fn set_broad_phase_callback( &mut self, callback: &mut PxBroadPhaseCallback )
sourceunsafe fn get_broad_phase_callback(&self) -> &PxBroadPhaseCallback
unsafe fn get_broad_phase_callback(&self) -> &PxBroadPhaseCallback
sourcefn reset_filtering(&mut self, actor: &mut impl Actor) -> bool
fn reset_filtering(&mut self, actor: &mut impl Actor) -> bool
Reset the collision filtering for an actor.
sourcefn reset_rigid_actor_filtering<R: RigidActor>(
&mut self,
actor: &mut R,
shapes: &[&mut R::Shape]
)
fn reset_rigid_actor_filtering<R: RigidActor>( &mut self, actor: &mut R, shapes: &[&mut R::Shape] )
Reset collision filtering for a RigidActor and shapes.
sourcefn get_kinematic_kinematic_filtering_mode(&self) -> PairFilteringMode
fn get_kinematic_kinematic_filtering_mode(&self) -> PairFilteringMode
Get the kinematic-kinematic filtering mode.
sourcefn get_static_kinematic_filtering_mode(&self) -> PairFilteringMode
fn get_static_kinematic_filtering_mode(&self) -> PairFilteringMode
Get the static-kinematic filtering mode.
sourcefn set_gravity(&mut self, x: f32, y: f32, z: f32)
fn set_gravity(&mut self, x: f32, y: f32, z: f32)
Sets the gravity vector.