pub trait RigidBody: Class<PxRigidBody> + RigidActor {
Show 33 methods // Provided methods fn set_mass(&mut self, mass: f32) { ... } fn get_angular_velocity(&self) -> PxVec3 { ... } fn get_linear_velocity(&self) -> PxVec3 { ... } fn get_velocities(&self) -> (PxVec3, PxVec3) { ... } fn set_c_mass_local_pose(&mut self, pose: &PxTransform) { ... } fn get_c_mass_local_pose(&self) -> PxTransform { ... } fn get_mass(&self) -> f32 { ... } fn get_inv_mass(&self) -> f32 { ... } fn set_mass_space_inertia_tensor(&mut self, m: &PxVec3) { ... } fn get_mass_space_inertia_tensor(&self) -> PxVec3 { ... } fn get_mass_space_inv_inertia_tensor(&self) -> PxVec3 { ... } fn set_linear_damping(&mut self, lin_damp: f32) { ... } fn get_linear_damping(&self) -> f32 { ... } fn set_angular_damping(&mut self, ang_damp: f32) { ... } fn get_angular_damping(&self) -> f32 { ... } fn set_max_angular_velocity(&mut self, max_ang_vel: f32) { ... } fn get_max_angular_velocity(&self) -> f32 { ... } fn set_max_linear_velocity(&mut self, max_lin_vel: f32) { ... } fn get_max_linear_velocity(&self) -> f32 { ... } fn add_force(&mut self, force: &PxVec3, mode: ForceMode, autowake: bool) { ... } fn add_torque(&mut self, torque: &PxVec3, mode: ForceMode, autowake: bool) { ... } fn clear_force(&mut self, mode: ForceMode) { ... } fn clear_torque(&mut self, mode: ForceMode) { ... } fn set_force_and_torque( &mut self, force: &PxVec3, torque: &PxVec3, mode: ForceMode ) { ... } fn set_rigid_body_flag(&mut self, flag: RigidBodyFlag, value: bool) { ... } fn set_rigid_body_flags(&mut self, flags: RigidBodyFlags) { ... } fn get_rigid_body_flags(&self) -> RigidBodyFlags { ... } fn set_min_ccd_advance_coefficient(&mut self, advance_coefficient: f32) { ... } fn get_min_ccd_advance_coefficient(&self) -> f32 { ... } fn set_max_depenetration_velocity(&mut self, bias_clamp: f32) { ... } fn get_max_depenetration_velocity(&self) -> f32 { ... } fn set_max_contact_impulse(&mut self, max_impulse: f32) { ... } fn get_max_contact_impulse(&self) -> f32 { ... }
}

Provided Methods§

source

fn set_mass(&mut self, mass: f32)

Set the mass of this body

source

fn get_angular_velocity(&self) -> PxVec3

Get the angular velocity.

source

fn get_linear_velocity(&self) -> PxVec3

Get the linear velocity.

source

fn get_velocities(&self) -> (PxVec3, PxVec3)

Get the (linear, angular) velocities.

source

fn set_c_mass_local_pose(&mut self, pose: &PxTransform)

Set the pose of the position and orientation of the center of mass. This does not move tha body, Setting the center of mass too far away may cause instability.

source

fn get_c_mass_local_pose(&self) -> PxTransform

Get the pose of the center of mass.

source

fn get_mass(&self) -> f32

Get the mass of the body.

source

fn get_inv_mass(&self) -> f32

Get the inverse of the mass of this body.

source

fn set_mass_space_inertia_tensor(&mut self, m: &PxVec3)

Sets the inertia tensor using mass space coordinates. Non-diagonal space inertia tensors must be diagonalized, only the diagonal is passed in. The tensor elements must be non-negative. Values of 0 represent infinite inertia along that axis, and are not permitted for PxArticulationLinks.

source

fn get_mass_space_inertia_tensor(&self) -> PxVec3

Gets the diagonal of the inertia tensor relative to the body’s mass coordinate frame. A value of 0 represents infinite inertia along that axis.

source

fn get_mass_space_inv_inertia_tensor(&self) -> PxVec3

Gets the diagonal of the inverse inertia tensor relative to the body’s mass coordinate frame. A value of 0 represents infinite inertia along that axis.

source

fn set_linear_damping(&mut self, lin_damp: f32)

Sets the linear damping. Zero represents no damping. Values clamped to [0.0 .. ].

source

fn get_linear_damping(&self) -> f32

Gets the linear damping.

source

fn set_angular_damping(&mut self, ang_damp: f32)

Sets the angular damping. Zero represents no damping. Values clamped to (0.0, .. ).

Examples found in repository?
examples/profiler.rs (line 139)
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
Hide additional examples
examples/ball_physx.rs (line 114)
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));
}
source

fn get_angular_damping(&self) -> f32

Get the angular damping.

source

fn set_max_angular_velocity(&mut self, max_ang_vel: f32)

Set the maximum angular velocity. Very rapid rotation can cause simulation errors, setting this value will clamp velocty before the solver is ran (so velocty may briefly exceed this value).

source

fn get_max_angular_velocity(&self) -> f32

Get the maximum angular velocity.

source

fn set_max_linear_velocity(&mut self, max_lin_vel: f32)

Set the maximum linear velocity. Very rapid movement can cause simulation errors, setting this value will clamp velocty before the solver is ran (so velocty may briefly exceed this value).

source

fn get_max_linear_velocity(&self) -> f32

Get the maximum linear velocity.

source

fn add_force(&mut self, force: &PxVec3, mode: ForceMode, autowake: bool)

Apply a force to the actor. This will not cause torque. ForceMode determines how this force is applied. ForceMode::Acceleration and ForceMode::VelocityChange directly effect the acceleration and velocity change accumulators. ForceMode::Force and ForceMode::Impulse are multiplied by inverse mass first.

source

fn add_torque(&mut self, torque: &PxVec3, mode: ForceMode, autowake: bool)

Apply a torque to the actor. ForceMode determines how this force is applied. ForceMode::Acceleration and ForceMode::VelocityChange directly effect the angular acceleration and angular velocity change accumulators. ForceMode::Force and ForceMode::Impulse are multiplied by inverse mass first.

source

fn clear_force(&mut self, mode: ForceMode)

Clear the accumulated acceleration or velocity change. ForceMode::Acceleration and ForceMode::Force clear the same accumulator, as do ForceMode::VelocityChange and ForceMode::Impulse.

source

fn clear_torque(&mut self, mode: ForceMode)

Clear the accumulated angular acceleration or angular velocity change. ForceMode::Acceleration and ForceMode::Force clear the same accumulator, as do ForceMode::VelocityChange and ForceMode::Impulse.

source

fn set_force_and_torque( &mut self, force: &PxVec3, torque: &PxVec3, mode: ForceMode )

Set the force and torque accumulators.

source

fn set_rigid_body_flag(&mut self, flag: RigidBodyFlag, value: bool)

Set a rigid body flag.

Examples found in repository?
examples/profiler.rs (line 140)
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
Hide additional examples
examples/ball_physx.rs (line 115)
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));
}
source

fn set_rigid_body_flags(&mut self, flags: RigidBodyFlags)

Set all the rigid body flags.

source

fn get_rigid_body_flags(&self) -> RigidBodyFlags

Get the rigid body flags.

source

fn set_min_ccd_advance_coefficient(&mut self, advance_coefficient: f32)

Set the CCD advance coefficient, clamped to range [0.0 ..= 1.0]. Default is 0.15. Values near 1.0 ensures that some will be advanced, but objects may slowly drift through eachother. Values near 0.0 will never drift through eachother, but may “jam” ie. not advance through time during a given CCD pass.

source

fn get_min_ccd_advance_coefficient(&self) -> f32

Get the CCD advance coefficient.

source

fn set_max_depenetration_velocity(&mut self, bias_clamp: f32)

sET the maximum allowed depenetration velocity

source

fn get_max_depenetration_velocity(&self) -> f32

Get the maximum allowed depenetration velocity

source

fn set_max_contact_impulse(&mut self, max_impulse: f32)

Set the max number of contact impulses this body may experience

source

fn get_max_contact_impulse(&self) -> f32

Get the max number of contact impulses this body may experience

Implementors§

source§

impl<T> RigidBody for Twhere T: Class<PxRigidBody> + RigidActor,