Trait physx::rigid_actor::RigidActor
source · pub trait RigidActor: Class<PxRigidActor> + Actor {
type Shape: Shape;
Show 13 methods
// Provided methods
fn get_nb_constraints(&self) -> u32 { ... }
fn get_constraints(&mut self) -> Vec<&mut Constraint> { ... }
fn get_global_pose(&self) -> PxTransform { ... }
fn get_global_position(&self) -> PxVec3 { ... }
fn get_global_rotation(&self) -> PxQuat { ... }
fn set_global_pose(&mut self, pose: &PxTransform, autowake: bool) { ... }
fn get_nb_shapes(&self) -> u32 { ... }
fn get_shapes(&self) -> Vec<&Self::Shape> { ... }
fn get_shapes_mut(&mut self) -> Vec<&mut Self::Shape> { ... }
fn set_collision_filter(
&mut self,
this_layers: CollisionLayers,
other_layers: CollisionLayers,
word3: u32,
word4: u32
) { ... }
fn set_query_filter(&mut self, this_layers: CollisionLayers) { ... }
fn attach_shape(&mut self, shape: &mut Self::Shape) -> bool { ... }
fn detach_shape(&mut self, shape: &mut Self::Shape) { ... }
}
Required Associated Types§
Provided Methods§
sourcefn get_nb_constraints(&self) -> u32
fn get_nb_constraints(&self) -> u32
Get the number of constraints on this rigid actor.
sourcefn get_constraints(&mut self) -> Vec<&mut Constraint>
fn get_constraints(&mut self) -> Vec<&mut Constraint>
Get the constraints effecting this rigid actor.
sourcefn get_global_pose(&self) -> PxTransform
fn get_global_pose(&self) -> PxTransform
Get the global pose of this rigid actor. The scale is implicitly 1.0.
sourcefn get_global_position(&self) -> PxVec3
fn get_global_position(&self) -> PxVec3
Get the global pose of this rigid actor.
Examples found in repository?
examples/ball_physx.rs (line 140)
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_global_rotation(&self) -> PxQuat
fn get_global_rotation(&self) -> PxQuat
Get the global rotation of this rigid actor.
sourcefn set_global_pose(&mut self, pose: &PxTransform, autowake: bool)
fn set_global_pose(&mut self, pose: &PxTransform, autowake: bool)
Set the global pose of this rigid actor
sourcefn get_nb_shapes(&self) -> u32
fn get_nb_shapes(&self) -> u32
Get number of attached shapes
sourcefn get_shapes(&self) -> Vec<&Self::Shape>
fn get_shapes(&self) -> Vec<&Self::Shape>
Get a reference to every Shape attached to this actor.
sourcefn get_shapes_mut(&mut self) -> Vec<&mut Self::Shape>
fn get_shapes_mut(&mut self) -> Vec<&mut Self::Shape>
Get a mutable reference to every Shape attached to this actor.
sourcefn set_collision_filter(
&mut self,
this_layers: CollisionLayers,
other_layers: CollisionLayers,
word3: u32,
word4: u32
)
fn set_collision_filter( &mut self, this_layers: CollisionLayers, other_layers: CollisionLayers, word3: u32, word4: u32 )
Set the collision filter. Collisions will only occur if this_layers & other_layers != 0.
sourcefn set_query_filter(&mut self, this_layers: CollisionLayers)
fn set_query_filter(&mut self, this_layers: CollisionLayers)
Set the query filter. Queries will only find this item if queried with one of the flags.
sourcefn attach_shape(&mut self, shape: &mut Self::Shape) -> bool
fn attach_shape(&mut self, shape: &mut Self::Shape) -> bool
Attach a shape.
sourcefn detach_shape(&mut self, shape: &mut Self::Shape)
fn detach_shape(&mut self, shape: &mut Self::Shape)
Detach a shape.