#[repr(transparent)]pub struct PxVec3 { /* private fields */ }
Implementations§
source§impl PxVec3
impl PxVec3
pub fn x(&self) -> f32
sourcepub fn y(&self) -> f32
pub fn y(&self) -> f32
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));
}
pub fn z(&self) -> f32
pub fn x_mut(&mut self) -> &mut f32
pub fn y_mut(&mut self) -> &mut f32
pub fn z_mut(&mut self) -> &mut f32
sourcepub fn new(x: f32, y: f32, z: f32) -> PxVec3
pub fn new(x: f32, y: f32, z: f32) -> PxVec3
Examples found in repository?
examples/profiler.rs (line 112)
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
examples/ball_physx.rs (line 87)
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));
}
pub fn abs(&self) -> PxVec3
pub fn cross(&self, other: &PxVec3) -> PxVec3
pub fn dot(&self, other: &PxVec3) -> f32
pub fn get_normalized(&self) -> PxVec3
pub fn is_finite(&self) -> bool
pub fn is_normalized(&self) -> bool
pub fn is_zero(&self) -> bool
pub fn magnitude(&self) -> f32
pub fn magnitude_squared(&self) -> f32
pub fn max_element(&self) -> f32
pub fn maximum(&self, other: &PxVec3) -> PxVec3
pub fn min_element(&self) -> f32
pub fn minimum(&self, other: &PxVec3) -> PxVec3
pub fn multiply(&self, other: &PxVec3) -> PxVec3
Trait Implementations§
source§impl Class<PxVec3> for PxVec3
impl Class<PxVec3> for PxVec3
source§fn as_ptr(&self) -> *const PxVec3
fn as_ptr(&self) -> *const PxVec3
Returns a raw const pointer to the wrapped type.
Retrieving a raw pointer is safe. However, pretty much any use of a raw pointer is unsafe.
In particular: this pointer should not be used to construct a second owning wrapper around the pointer.
source§fn as_mut_ptr(&mut self) -> *mut PxVec3
fn as_mut_ptr(&mut self) -> *mut PxVec3
Returns a raw mut pointer to the wrapped type.
Retrieving a raw pointer is safe. However, pretty much any use of a raw pointer is unsafe.
In particular: this pointer should not be used to construct a second owning wrapper around the pointer.
source§impl From<PxExtendedVec3> for PxVec3
impl From<PxExtendedVec3> for PxVec3
source§fn from(vec3: PxExtendedVec3) -> Self
fn from(vec3: PxExtendedVec3) -> Self
Converts to this type from the input type.