Trait physx::physics::Physics

source ·
pub trait Physics: Class<PxPhysics> + Sized {
    type Shape: Shape;

Show 25 methods // Provided methods fn create<Desc: Descriptor<Self>>(&mut self, desc: Desc) -> Desc::Target { ... } fn create_scene<U, L, S, D, C, OC, OT, OCB, OWS, OA>( &mut self, scene_descriptor: SceneDescriptor<U, L, S, D, C, OC, OT, OCB, OWS, OA> ) -> Option<Owner<PxScene<U, L, S, D, C, OC, OT, OCB, OWS, OA>>> where L: ArticulationLink, S: RigidStatic, D: RigidDynamic, C: ArticulationReducedCoordinate, OC: CollisionCallback, OT: TriggerCallback, OCB: ConstraintBreakCallback, OWS: WakeSleepCallback<L, S, D>, OA: AdvanceCallback<L, D> { ... } fn create_aggregate<L, S, D, C>( &mut self, max_actors: u32, max_shapes: u32, filter_hint: AggregateFilterHint ) -> Option<Owner<PxAggregate<L, S, D, C>>> where L: ArticulationLink, S: RigidStatic, D: RigidDynamic, C: ArticulationReducedCoordinate { ... } fn create_articulation_reduced_coordinate<U, L: ArticulationLink>( &mut self, user_data: U ) -> Option<Owner<PxArticulationReducedCoordinate<U, L>>> { ... } fn create_bvh(&mut self, stream: &mut PxInputStream) -> Option<Owner<Bvh>> { ... } fn create_constraint( &mut self, first_actor: &mut impl RigidActor, second_actor: &mut impl RigidActor, connector: &mut PxConstraintConnector, shaders: &PxConstraintShaderTable, data_size: u32 ) -> Option<Owner<Constraint>> { ... } fn create_convex_mesh( &mut self, stream: &mut PxInputStream ) -> Option<Owner<ConvexMesh>> { ... } fn create_height_field( &mut self, stream: &mut PxInputStream ) -> Option<Owner<HeightField>> { ... } fn create_material( &mut self, static_friction: f32, dynamic_friction: f32, restitution: f32, user_data: <<Self::Shape as Shape>::Material as UserData>::UserData ) -> Option<Owner<<Self::Shape as Shape>::Material>> { ... } fn create_pruning_structure( &mut self, actors: Vec<&mut impl RigidActor> ) -> Option<Owner<PruningStructure>> { ... } fn create_dynamic<U>( &mut self, transform: &PxTransform, user_data: U ) -> Option<Owner<PxRigidDynamic<U, Self::Shape>>> { ... } fn create_static<U>( &mut self, transform: PxTransform, user_data: U ) -> Option<Owner<PxRigidStatic<U, Self::Shape>>> { ... } fn create_shape( &mut self, geometry: &impl Geometry, materials: &mut [&mut <Self::Shape as Shape>::Material], is_exclusive: bool, shape_flags: ShapeFlags, user_data: <Self::Shape as UserData>::UserData ) -> Option<Owner<Self::Shape>> { ... } fn create_triangle_mesh( &mut self, stream: &mut PxInputStream ) -> Option<Owner<TriangleMesh>> { ... } fn create_rigid_dynamic<U>( &mut self, transform: PxTransform, geometry: &impl Geometry, material: &mut <Self::Shape as Shape>::Material, density: f32, shape_transform: PxTransform, user_data: U ) -> Option<Owner<PxRigidDynamic<U, Self::Shape>>> { ... } fn create_rigid_static<U>( &mut self, transform: PxTransform, geometry: &impl Geometry, material: &mut <Self::Shape as Shape>::Material, shape_transform: PxTransform, user_data: U ) -> Option<Owner<PxRigidStatic<U, Self::Shape>>> { ... } fn create_plane<U>( &mut self, normal: PxVec3, offset: f32, material: &mut <Self::Shape as Shape>::Material, user_data: U ) -> Option<Owner<PxRigidStatic<U, Self::Shape>>> { ... } fn get_bvhs(&self) -> Vec<&Bvh> { ... } fn get_convex_meshes(&self) -> Vec<&ConvexMesh> { ... } fn get_height_fields(&self) -> Vec<&HeightField> { ... } fn get_materials(&self) -> Vec<&<Self::Shape as Shape>::Material> { ... } fn get_shapes(&self) -> Vec<&Self::Shape> { ... } fn get_triangle_meshes(&self) -> Vec<&TriangleMesh> { ... } fn get_tolerances_scale(&self) -> Option<&PxTolerancesScale> { ... } fn get_physics_insertion_callback( &mut self ) -> Option<&mut PxInsertionCallback> { ... }
}

Required Associated Types§

Provided Methods§

source

fn create<Desc: Descriptor<Self>>(&mut self, desc: Desc) -> Desc::Target

Examples found in repository?
examples/profiler.rs (lines 111-115)
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 (lines 86-90)
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 create_scene<U, L, S, D, C, OC, OT, OCB, OWS, OA>( &mut self, scene_descriptor: SceneDescriptor<U, L, S, D, C, OC, OT, OCB, OWS, OA> ) -> Option<Owner<PxScene<U, L, S, D, C, OC, OT, OCB, OWS, OA>>>where L: ArticulationLink, S: RigidStatic, D: RigidDynamic, C: ArticulationReducedCoordinate, OC: CollisionCallback, OT: TriggerCallback, OCB: ConstraintBreakCallback, OWS: WakeSleepCallback<L, S, D>, OA: AdvanceCallback<L, D>,

Create a new scene with from a descriptor.

source

fn create_aggregate<L, S, D, C>( &mut self, max_actors: u32, max_shapes: u32, filter_hint: AggregateFilterHint ) -> Option<Owner<PxAggregate<L, S, D, C>>>where L: ArticulationLink, S: RigidStatic, D: RigidDynamic, C: ArticulationReducedCoordinate,

Create a new aggregate.

Must be added to a scene with the same actor user data types.

source

fn create_articulation_reduced_coordinate<U, L: ArticulationLink>( &mut self, user_data: U ) -> Option<Owner<PxArticulationReducedCoordinate<U, L>>>

Create a new articulation. Must be added to a scene with the same user data types.

source

fn create_bvh(&mut self, stream: &mut PxInputStream) -> Option<Owner<Bvh>>

Create a new BVH.

source

fn create_constraint( &mut self, first_actor: &mut impl RigidActor, second_actor: &mut impl RigidActor, connector: &mut PxConstraintConnector, shaders: &PxConstraintShaderTable, data_size: u32 ) -> Option<Owner<Constraint>>

Create a new constraint. The constraint class-trait is not implemented yet.

source

fn create_convex_mesh( &mut self, stream: &mut PxInputStream ) -> Option<Owner<ConvexMesh>>

Create a new convex mesh. The convex mesh class-trait is not implemented yet.

source

fn create_height_field( &mut self, stream: &mut PxInputStream ) -> Option<Owner<HeightField>>

Create a new height field.

source

fn create_material( &mut self, static_friction: f32, dynamic_friction: f32, restitution: f32, user_data: <<Self::Shape as Shape>::Material as UserData>::UserData ) -> Option<Owner<<Self::Shape as Shape>::Material>>

Create a new material with ref count set to one.

Examples found in repository?
examples/profiler.rs (line 118)
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 93)
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 create_pruning_structure( &mut self, actors: Vec<&mut impl RigidActor> ) -> Option<Owner<PruningStructure>>

Create a new pruning structure. The pruning structure class-trait is not implemented yet.

source

fn create_dynamic<U>( &mut self, transform: &PxTransform, user_data: U ) -> Option<Owner<PxRigidDynamic<U, Self::Shape>>>

Create a dynamic actor with given transform and user data. Other fields are initialized to their defaults.

source

fn create_static<U>( &mut self, transform: PxTransform, user_data: U ) -> Option<Owner<PxRigidStatic<U, Self::Shape>>>

Create a static actor with given transform and user data. Other fields are initialized to their defaults.

source

fn create_shape( &mut self, geometry: &impl Geometry, materials: &mut [&mut <Self::Shape as Shape>::Material], is_exclusive: bool, shape_flags: ShapeFlags, user_data: <Self::Shape as UserData>::UserData ) -> Option<Owner<Self::Shape>>

Create a new shape.

source

fn create_triangle_mesh( &mut self, stream: &mut PxInputStream ) -> Option<Owner<TriangleMesh>>

Create a new pruning structure. The pruning structure class-trait is not implemented yet.

source

fn create_rigid_dynamic<U>( &mut self, transform: PxTransform, geometry: &impl Geometry, material: &mut <Self::Shape as Shape>::Material, density: f32, shape_transform: PxTransform, user_data: U ) -> Option<Owner<PxRigidDynamic<U, Self::Shape>>>

Create a new rigid dynamic actor.

Examples found in repository?
examples/profiler.rs (lines 130-137)
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 (lines 105-112)
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 create_rigid_static<U>( &mut self, transform: PxTransform, geometry: &impl Geometry, material: &mut <Self::Shape as Shape>::Material, shape_transform: PxTransform, user_data: U ) -> Option<Owner<PxRigidStatic<U, Self::Shape>>>

Create a new rigid static actor.

source

fn create_plane<U>( &mut self, normal: PxVec3, offset: f32, material: &mut <Self::Shape as Shape>::Material, user_data: U ) -> Option<Owner<PxRigidStatic<U, Self::Shape>>>

Create a plane, with plane equation normal.dot(v) + offset = 0.

Examples found in repository?
examples/profiler.rs (line 121)
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 96)
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_bvhs(&self) -> Vec<&Bvh>

Get the BVHs created by this physics object.

source

fn get_convex_meshes(&self) -> Vec<&ConvexMesh>

Get the convex meshes created by this physics object.

source

fn get_height_fields(&self) -> Vec<&HeightField>

Get the height fields created by this physics object.

source

fn get_materials(&self) -> Vec<&<Self::Shape as Shape>::Material>

Get the height fields created by this physics object.

source

fn get_shapes(&self) -> Vec<&Self::Shape>

Get the shapes created by this physics object.

source

fn get_triangle_meshes(&self) -> Vec<&TriangleMesh>

Get the triangle mesghes created by this object.

source

fn get_tolerances_scale(&self) -> Option<&PxTolerancesScale>

Get the tolerance scale.

source

fn get_physics_insertion_callback(&mut self) -> Option<&mut PxInsertionCallback>

Get the physics insertion callback, used for real-time cooking of physics meshes.

Implementors§

source§

impl<Allocator: AllocatorCallback, Geom: Shape> Physics for PhysicsFoundation<Allocator, Geom>

§

type Shape = Geom

source§

impl<Geom: Shape> Physics for PxPhysics<Geom>

§

type Shape = Geom