64
CHANGELOG.md
64
CHANGELOG.md
@@ -1,7 +1,71 @@
|
||||
## v0.9.0
|
||||
The user-guide has been fully rewritten and is now exhaustive! Check it out on [rapier.rs](https://rapier.rs/)
|
||||
|
||||
### Added
|
||||
- A prelude has been added in order to simplify the most common imports. For example: `use rapier3d::prelude::*`
|
||||
- Add `RigidBody::set_translation` and `RigidBody.translation()`.
|
||||
- Add `RigidBody::set_rotation` and `RigidBody.rotation().
|
||||
- Add `RigidBody::set_next_translation` for setting the next translation of a position-based kinematic body.
|
||||
- Add `RigidBody::set_next_rotation` for setting the next rotation of a position-based kinematic body.
|
||||
- Add kinematic bodies controlled at the velocity level: use `RigidBodyBuilder::new_kinematic_velocity_based` or
|
||||
`RigidBodyType::KinematicVelocityBased`.
|
||||
|
||||
### Modified
|
||||
The use of `RigidBodySet, ColliderSet, RigidBody, Collider` is no longer mandatory. Rigid-bodies and colliders have
|
||||
been split into multiple components that can be stored in a user-defined set. This is useful for integrating Rapier
|
||||
with other engines (for example this allows use to use Bevy's Query as our rigid-body/collider sets).
|
||||
|
||||
The `RigidBodySet, ColliderSet, RigidBody, Collider` are still the best option for whoever doesn't want to
|
||||
provide their own component sets.
|
||||
|
||||
#### Rigid-bodies
|
||||
- Renamed `BodyStatus` to `RigidBodyType`.
|
||||
- `RigidBodyBuilder::translation` now takes a vector instead of individual components.
|
||||
- `RigidBodyBuilder::linvel` now takes a vector instead of individual components.
|
||||
- The `RigidBodyBuilder::new_kinematic` has be replaced by the `RigidBodyBuilder::new_kinematic_position_based` and
|
||||
`RigidBodyBuilder::new_kinematic_velocity_based` constructors.
|
||||
- The `RigidBodyType::Kinematic` variant has been replaced by two variants: `RigidBodyType::KinematicVelocityBased` and
|
||||
`RigidBodyType::KinematicPositionBased`.
|
||||
|
||||
#### Colliders
|
||||
- `Colliderbuilder::translation` now takes a vector instead of individual components.
|
||||
- The way `PhysicsHooks` are enabled changed. Now, a physics hooks is executed if any of the two
|
||||
colliders involved in the contact/intersection pair contains the related `PhysicsHooksFlag`.
|
||||
These flags are configured on each collider with `ColliderBuilder::active_hooks`. As a result,
|
||||
there is no `PhysicsHooks::active_hooks` method any more.
|
||||
- All events are now disabled for all colliders by default. Enable events for specific colliders by setting its
|
||||
`active_events` bit mask to `ActiveEvents::CONTACT_EVENTS` and/or `ActiveEvents::PROXIMITY_EVENTS`.
|
||||
- Add a simpler way of enabling collision-detection between colliders attached to two non-dynamic rigid-bodies: see
|
||||
`ColliderBuilder::active_collision_types`.
|
||||
- The `InteractionGroups` is now a structures with two `u32` integers: one integers for the groups
|
||||
membership and one for the group filter mask. (Before, both were only 16-bits wide, and were
|
||||
packed into a single `u32`).
|
||||
- Before, sensor colliders had a default density set to 0.0 whereas non-sensor colliders had a
|
||||
default density of 1.0. This has been unified by setting the default density to 1.0 for both
|
||||
sensor and non-sensor colliders.
|
||||
- Colliders are no longer required to be attached to a rigid-body. Therefore, `ColliderSet::insert`
|
||||
only takes the collider as argument now. In order to attach the collider to a rigid-body,
|
||||
(i.e., the old behavior of `ColliderSet::insert`), use `ColliderSet::insert_with_parent`.
|
||||
- Fixed a bug where collision groups were ignored by CCD.
|
||||
|
||||
#### Joints
|
||||
- The fields `FixedJoint::local_anchor1` and `FixedJoint::local_anchor2` have been renamed to
|
||||
`FixedJoint::local_frame1` and `FixedJoint::local_frame2`.
|
||||
|
||||
#### Pipelines and others
|
||||
- The field `ContactPair::pair` (which contained two collider handles) has been replaced by two
|
||||
fields: `ContactPair::collider1` and `ContactPair::collider2`.
|
||||
- The list of active dynamic bodies is no retrieved with `IslandManager::active_dynamic_bodies`
|
||||
instead of `RigidBodySet::iter_active_dynamic`.
|
||||
- The list of active kinematic bodies is no retrieved with `IslandManager::active_kinematic_bodies`
|
||||
instead of `RigidBodySet::iter_active_kinematic`.
|
||||
- `NarrowPhase::contacts_with` now returns an `impl Iterator<Item = &ContactPair>` instead of
|
||||
an `Option<impl Iterator<Item = (ColliderHandle, ColliderHandle, &ContactPair)>>`. The colliders
|
||||
handles can be read from the contact-pair itself.
|
||||
- `NarrowPhase::intersections_with` now returns an iterator directly instead of an `Option<impl Iterator>`.
|
||||
- Rename `PhysicsHooksFlags` to `ActiveHooks`.
|
||||
- Add the contact pair as an argument to `EventHandler::handle_contact_event`
|
||||
|
||||
|
||||
## v0.8.0
|
||||
### Modified
|
||||
|
||||
@@ -18,9 +18,6 @@ resolver = "2"
|
||||
#parry3d-f64 = { path = "../parry/build/parry3d-f64" }
|
||||
#nalgebra = { path = "../nalgebra" }
|
||||
|
||||
#bevy-orbit-controls = { path = "../bevy-orbit-controls" }
|
||||
bevy-orbit-controls = { git = "https://github.com/sebcrozet/bevy-orbit-controls" }
|
||||
|
||||
#kiss3d = { git = "https://github.com/sebcrozet/kiss3d" }
|
||||
#nalgebra = { git = "https://github.com/dimforge/nalgebra", branch = "dev" }
|
||||
#parry2d = { git = "https://github.com/dimforge/parry", branch = "special_cases" }
|
||||
|
||||
@@ -14,7 +14,7 @@ enhanced-determinism = [ "rapier2d/enhanced-determinism" ]
|
||||
[dependencies]
|
||||
rand = "0.8"
|
||||
Inflector = "0.11"
|
||||
nalgebra = "0.26"
|
||||
nalgebra = "0.27"
|
||||
|
||||
[dependencies.rapier_testbed2d]
|
||||
path = "../build/rapier_testbed2d"
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -22,7 +20,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let co = ColliderDesc::new(ground_shape)
|
||||
.translation(-Vector2::y())
|
||||
.build(BodyPartHandle(ground_handle, 0));
|
||||
colliders.insert(co);
|
||||
colliders.insert_with_parent(co);
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -48,10 +46,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
};
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,5 +59,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 2.5), 5.0);
|
||||
testbed.look_at(point![0.0, 2.5], 5.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -19,23 +17,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.rotation(std::f32::consts::FRAC_PI_2)
|
||||
.translation(ground_size, ground_size * 2.0)
|
||||
.translation(vector![ground_size, ground_size * 2.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.rotation(std::f32::consts::FRAC_PI_2)
|
||||
.translation(-ground_size, ground_size * 2.0)
|
||||
.translation(vector![-ground_size, ground_size * 2.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -53,10 +51,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = j as f32 * shift + centery + 2.0;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 50.0), 10.0);
|
||||
testbed.look_at(point![0.0, 50.0], 10.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -19,23 +17,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.rotation(std::f32::consts::FRAC_PI_2)
|
||||
.translation(ground_size, ground_size * 4.0)
|
||||
.translation(vector![ground_size, ground_size * 4.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size * 4.0, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.rotation(std::f32::consts::FRAC_PI_2)
|
||||
.translation(-ground_size, ground_size * 4.0)
|
||||
.translation(vector![-ground_size, ground_size * 4.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size * 4.0, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -55,10 +53,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = j as f32 * shifty + centery + 3.0;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_y(rad * 1.5, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,5 +66,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 50.0), 10.0);
|
||||
testbed.look_at(point![0.0, 50.0], 10.0);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use na::Point2;
|
||||
use rand::distributions::{Distribution, Standard};
|
||||
use rand::{rngs::StdRng, SeedableRng};
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -21,23 +19,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.rotation(std::f32::consts::FRAC_PI_2)
|
||||
.translation(ground_size, ground_size * 2.0)
|
||||
.translation(vector![ground_size, ground_size * 2.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.rotation(std::f32::consts::FRAC_PI_2)
|
||||
.translation(-ground_size, ground_size * 2.0)
|
||||
.translation(vector![-ground_size, ground_size * 2.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the convex polygons
|
||||
@@ -58,18 +56,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let x = i as f32 * shift - centerx;
|
||||
let y = j as f32 * shift * 2.0 + centery + 2.0;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let mut points = Vec::new();
|
||||
|
||||
for _ in 0..10 {
|
||||
let pt: Point2<f32> = distribution.sample(&mut rng);
|
||||
let pt: Point<f32> = distribution.sample(&mut rng);
|
||||
points.push(pt * scale);
|
||||
}
|
||||
|
||||
let collider = ColliderBuilder::convex_hull(&points).unwrap().build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,5 +77,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 50.0), 10.0);
|
||||
testbed.look_at(point![0.0, 50.0], 10.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use na::{DVector, Point2, Vector2};
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use na::DVector;
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = Vector2::new(50.0, 1.0);
|
||||
let ground_size = Vector::new(50.0, 1.0);
|
||||
let nsubdivs = 2000;
|
||||
|
||||
let heights = DVector::from_fn(nsubdivs + 1, |i, _| {
|
||||
@@ -28,7 +27,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::heightfield(heights, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -46,15 +45,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = j as f32 * shift + centery + 3.0;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
if j % 2 == 0 {
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
} else {
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 50.0), 10.0);
|
||||
testbed.look_at(point![0.0, 50.0], 10.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -34,16 +32,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(fk * shift, -fi * shift)
|
||||
.translation(vector![fk * shift, -fi * shift])
|
||||
.build();
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, child_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||
|
||||
// Vertical joint.
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint = BallJoint::new(Point2::origin(), Point2::new(0.0, shift));
|
||||
let joint = BallJoint::new(Point::origin(), point![0.0, shift]);
|
||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
|
||||
@@ -51,7 +49,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
if k > 0 {
|
||||
let parent_index = body_handles.len() - numi;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = BallJoint::new(Point2::origin(), Point2::new(-shift, 0.0));
|
||||
let joint = BallJoint::new(Point::origin(), point![-shift, 0.0]);
|
||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
|
||||
@@ -63,5 +61,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(numk as f32 * rad, numi as f32 * -rad), 5.0);
|
||||
testbed.look_at(point![numk as f32 * rad, numi as f32 * -rad], 5.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Isometry2, Point2};
|
||||
use rapier2d::dynamics::{FixedJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -39,18 +37,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(x + fk * shift, y - fi * shift)
|
||||
.translation(vector![x + fk * shift, y - fi * shift])
|
||||
.build();
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, child_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||
|
||||
// Vertical joint.
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint = FixedJoint::new(
|
||||
Isometry2::identity(),
|
||||
Isometry2::translation(0.0, shift),
|
||||
Isometry::identity(),
|
||||
Isometry::translation(0.0, shift),
|
||||
);
|
||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
@@ -60,8 +58,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let parent_index = body_handles.len() - num;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = FixedJoint::new(
|
||||
Isometry2::identity(),
|
||||
Isometry2::translation(-shift, 0.0),
|
||||
Isometry::identity(),
|
||||
Isometry::translation(-shift, 0.0),
|
||||
);
|
||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
@@ -76,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(50.0, 50.0), 5.0);
|
||||
testbed.look_at(point![50.0, 50.0], 5.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point2, Unit, Vector2};
|
||||
use rapier2d::dynamics::{JointSet, PrismaticJoint, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -25,27 +23,31 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
for j in 0..50 {
|
||||
let x = j as f32 * shift * 4.0;
|
||||
|
||||
let ground = RigidBodyBuilder::new_static().translation(x, y).build();
|
||||
let ground = RigidBodyBuilder::new_static()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, curr_parent, &mut bodies);
|
||||
colliders.insert_with_parent(collider, curr_parent, &mut bodies);
|
||||
|
||||
for i in 0..num {
|
||||
let y = y - (i + 1) as f32 * shift;
|
||||
let density = 1.0;
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let curr_child = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).density(density).build();
|
||||
colliders.insert(collider, curr_child, &mut bodies);
|
||||
colliders.insert_with_parent(collider, curr_child, &mut bodies);
|
||||
|
||||
let axis = if i % 2 == 0 {
|
||||
Unit::new_normalize(Vector2::new(1.0, 1.0))
|
||||
UnitVector::new_normalize(vector![1.0, 1.0])
|
||||
} else {
|
||||
Unit::new_normalize(Vector2::new(-1.0, 1.0))
|
||||
UnitVector::new_normalize(vector![-1.0, 1.0])
|
||||
};
|
||||
|
||||
let mut prism =
|
||||
PrismaticJoint::new(Point2::origin(), axis, Point2::new(0.0, shift), axis);
|
||||
PrismaticJoint::new(Point::origin(), axis, point![0.0, shift], axis);
|
||||
prism.limits_enabled = true;
|
||||
prism.limits[0] = -1.5;
|
||||
prism.limits[1] = 1.5;
|
||||
@@ -60,5 +62,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(80.0, 80.0), 15.0);
|
||||
testbed.look_at(point![80.0, 80.0], 15.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -20,7 +18,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -40,10 +38,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = fi * shift + centery;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,5 +51,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 2.5), 5.0);
|
||||
testbed.look_at(point![0.0, 2.5], 5.0);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ enhanced-determinism = [ "rapier3d/enhanced-determinism" ]
|
||||
[dependencies]
|
||||
rand = "0.8"
|
||||
Inflector = "0.11"
|
||||
nalgebra = "0.26"
|
||||
nalgebra = "0.27"
|
||||
|
||||
[dependencies.rapier_testbed3d]
|
||||
path = "../build/rapier_testbed3d"
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -37,10 +35,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let density = 0.477;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).density(density).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,5 +49,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -45,10 +43,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,5 +59,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -46,10 +44,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_y(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,5 +60,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -49,8 +47,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(x, y, z)
|
||||
.linvel(0.0, -1000.0, 0.0)
|
||||
.translation(vector![x, y, z])
|
||||
.linvel(vector![0.0, -1000.0, 0.0])
|
||||
.ccd_enabled(true)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
@@ -65,7 +63,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
_ => ColliderBuilder::capsule_y(rad, rad),
|
||||
};
|
||||
|
||||
colliders.insert(collider.build(), handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider.build(), handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -45,18 +43,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift * 2.0 - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad).build();
|
||||
let collider2 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
||||
.translation(rad * 10.0, rad * 10.0, 0.0)
|
||||
.translation(vector![rad * 10.0, rad * 10.0, 0.0])
|
||||
.build();
|
||||
let collider3 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
||||
.translation(-rad * 10.0, rad * 10.0, 0.0)
|
||||
.translation(vector![-rad * 10.0, rad * 10.0, 0.0])
|
||||
.build();
|
||||
colliders.insert(collider1, handle, &mut bodies);
|
||||
colliders.insert(collider2, handle, &mut bodies);
|
||||
colliders.insert(collider3, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider1, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider2, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider3, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,5 +67,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use na::Point3;
|
||||
use rand::distributions::{Distribution, Standard};
|
||||
use rand::{rngs::StdRng, SeedableRng};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -20,11 +18,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -53,17 +51,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
let mut points = Vec::new();
|
||||
for _ in 0..10 {
|
||||
let pt: Point3<f32> = distribution.sample(&mut rng);
|
||||
let pt: Point<f32> = distribution.sample(&mut rng);
|
||||
points.push(pt * scale);
|
||||
}
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::round_convex_hull(&points, border_rad)
|
||||
.unwrap()
|
||||
.build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use na::{ComplexField, DMatrix, Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use na::ComplexField;
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = Vector3::new(200.0, 1.0, 200.0);
|
||||
let ground_size = vector![200.0, 1.0, 200.0];
|
||||
let nsubdivs = 20;
|
||||
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
@@ -34,7 +33,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::heightfield(heights, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -55,15 +54,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
if j % 2 == 0 {
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
} else {
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -29,16 +27,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(fk * shift, 0.0, fi * shift)
|
||||
.translation(vector![fk * shift, 0.0, fi * shift])
|
||||
.build();
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, child_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||
|
||||
// Vertical joint.
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint = BallJoint::new(Point3::origin(), Point3::new(0.0, 0.0, -shift));
|
||||
let joint = BallJoint::new(Point::origin(), point![0.0, 0.0, -shift]);
|
||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
|
||||
@@ -46,7 +44,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
if k > 0 {
|
||||
let parent_index = body_handles.len() - num;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = BallJoint::new(Point3::origin(), Point3::new(-shift, 0.0, 0.0));
|
||||
let joint = BallJoint::new(Point::origin(), point![-shift, 0.0, 0.0]);
|
||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
|
||||
@@ -58,8 +56,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(
|
||||
Point3::new(-110.0, -46.0, 170.0),
|
||||
Point3::new(54.0, -38.0, 29.0),
|
||||
);
|
||||
testbed.look_at(point![-110.0, -46.0, 170.0], point![54.0, -38.0, 29.0]);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Isometry3, Point3};
|
||||
use rapier3d::dynamics::{FixedJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -42,18 +40,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(x + fk * shift, y, z + fi * shift)
|
||||
.translation(vector![x + fk * shift, y, z + fi * shift])
|
||||
.build();
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, child_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||
|
||||
// Vertical joint.
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint = FixedJoint::new(
|
||||
Isometry3::identity(),
|
||||
Isometry3::translation(0.0, 0.0, -shift),
|
||||
Isometry::identity(),
|
||||
Isometry::translation(0.0, 0.0, -shift),
|
||||
);
|
||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
@@ -63,8 +61,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let parent_index = body_handles.len() - num;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = FixedJoint::new(
|
||||
Isometry3::identity(),
|
||||
Isometry3::translation(-shift, 0.0, 0.0),
|
||||
Isometry::identity(),
|
||||
Isometry::translation(-shift, 0.0, 0.0),
|
||||
);
|
||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
@@ -80,8 +78,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(
|
||||
Point3::new(-38.0, 14.0, 108.0),
|
||||
Point3::new(46.0, 12.0, 23.0),
|
||||
);
|
||||
testbed.look_at(point![-38.0, 14.0, 108.0], point![46.0, 12.0, 23.0]);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point3, Unit, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, PrismaticJoint, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -24,33 +22,37 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
for j in 0..50 {
|
||||
let x = j as f32 * shift * 4.0;
|
||||
|
||||
let ground = RigidBodyBuilder::new_static().translation(x, y, z).build();
|
||||
let ground = RigidBodyBuilder::new_static()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, curr_parent, &mut bodies);
|
||||
colliders.insert_with_parent(collider, curr_parent, &mut bodies);
|
||||
|
||||
for i in 0..num {
|
||||
let z = z + (i + 1) as f32 * shift;
|
||||
let density = 1.0;
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let curr_child = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad)
|
||||
.density(density)
|
||||
.build();
|
||||
colliders.insert(collider, curr_child, &mut bodies);
|
||||
colliders.insert_with_parent(collider, curr_child, &mut bodies);
|
||||
|
||||
let axis = if i % 2 == 0 {
|
||||
Unit::new_normalize(Vector3::new(1.0, 1.0, 0.0))
|
||||
UnitVector::new_normalize(vector![1.0, 1.0, 0.0])
|
||||
} else {
|
||||
Unit::new_normalize(Vector3::new(-1.0, 1.0, 0.0))
|
||||
UnitVector::new_normalize(vector![-1.0, 1.0, 0.0])
|
||||
};
|
||||
|
||||
let z = Vector3::z();
|
||||
let z = Vector::z();
|
||||
let mut prism = PrismaticJoint::new(
|
||||
Point3::origin(),
|
||||
Point::origin(),
|
||||
axis,
|
||||
z,
|
||||
Point3::new(0.0, 0.0, -shift),
|
||||
point![0.0, 0.0, -shift],
|
||||
axis,
|
||||
z,
|
||||
);
|
||||
@@ -69,8 +71,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(
|
||||
Point3::new(262.0, 63.0, 124.0),
|
||||
Point3::new(101.0, 4.0, -3.0),
|
||||
);
|
||||
testbed.look_at(point![262.0, 63.0, 124.0], point![101.0, 4.0, -3.0]);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Isometry3, Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RevoluteJoint, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -22,20 +20,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let x = j as f32 * shift * 4.0;
|
||||
|
||||
let ground = RigidBodyBuilder::new_static()
|
||||
.translation(x, y, 0.0)
|
||||
.translation(vector![x, y, 0.0])
|
||||
.build();
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, curr_parent, &mut bodies);
|
||||
colliders.insert_with_parent(collider, curr_parent, &mut bodies);
|
||||
|
||||
for i in 0..num {
|
||||
// Create four bodies.
|
||||
let z = i as f32 * shift * 2.0 + shift;
|
||||
let positions = [
|
||||
Isometry3::translation(x, y, z),
|
||||
Isometry3::translation(x + shift, y, z),
|
||||
Isometry3::translation(x + shift, y, z + shift),
|
||||
Isometry3::translation(x, y, z + shift),
|
||||
Isometry::translation(x, y, z),
|
||||
Isometry::translation(x + shift, y, z),
|
||||
Isometry::translation(x + shift, y, z + shift),
|
||||
Isometry::translation(x, y, z + shift),
|
||||
];
|
||||
|
||||
let mut handles = [curr_parent; 4];
|
||||
@@ -48,19 +46,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad)
|
||||
.density(density)
|
||||
.build();
|
||||
colliders.insert(collider, handles[k], &mut bodies);
|
||||
colliders.insert_with_parent(collider, handles[k], &mut bodies);
|
||||
}
|
||||
|
||||
// Setup four joints.
|
||||
let o = Point3::origin();
|
||||
let x = Vector3::x_axis();
|
||||
let z = Vector3::z_axis();
|
||||
let o = Point::origin();
|
||||
let x = Vector::x_axis();
|
||||
let z = Vector::z_axis();
|
||||
|
||||
let revs = [
|
||||
RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z),
|
||||
RevoluteJoint::new(o, x, Point3::new(-shift, 0.0, 0.0), x),
|
||||
RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z),
|
||||
RevoluteJoint::new(o, x, Point3::new(shift, 0.0, 0.0), x),
|
||||
RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z),
|
||||
RevoluteJoint::new(o, x, point![-shift, 0.0, 0.0], x),
|
||||
RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z),
|
||||
RevoluteJoint::new(o, x, point![shift, 0.0, 0.0], x),
|
||||
];
|
||||
|
||||
joints.insert(&mut bodies, curr_parent, handles[0], revs[0]);
|
||||
@@ -77,8 +75,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(
|
||||
Point3::new(478.0, 83.0, 228.0),
|
||||
Point3::new(134.0, 83.0, -116.0),
|
||||
);
|
||||
testbed.look_at(point![478.0, 83.0, 228.0], point![134.0, 83.0, -116.0]);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn build_block(
|
||||
testbed: &mut Testbed,
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
half_extents: Vector3<f32>,
|
||||
shift: Vector3<f32>,
|
||||
half_extents: Vector<f32>,
|
||||
shift: Vector<f32>,
|
||||
mut numx: usize,
|
||||
numy: usize,
|
||||
mut numz: usize,
|
||||
@@ -17,8 +15,8 @@ pub fn build_block(
|
||||
let block_width = 2.0 * half_extents.z * numx as f32;
|
||||
let block_height = 2.0 * half_extents.y * numy as f32;
|
||||
let spacing = (half_extents.z * numx as f32 - half_extents.x) / (numz as f32 - 1.0);
|
||||
let mut color0 = Point3::new(0.7, 0.5, 0.9);
|
||||
let mut color1 = Point3::new(0.6, 1.0, 0.6);
|
||||
let mut color0 = [0.7, 0.5, 0.9];
|
||||
let mut color1 = [0.6, 1.0, 0.6];
|
||||
|
||||
for i in 0..numy {
|
||||
std::mem::swap(&mut numx, &mut numz);
|
||||
@@ -41,15 +39,15 @@ pub fn build_block(
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(
|
||||
.translation(vector![
|
||||
x + dim.x + shift.x,
|
||||
y + dim.y + shift.y,
|
||||
z + dim.z + shift.z,
|
||||
)
|
||||
z + dim.z + shift.z
|
||||
])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
|
||||
colliders.insert(collider, handle, bodies);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
|
||||
testbed.set_initial_body_color(handle, color0);
|
||||
std::mem::swap(&mut color0, &mut color1);
|
||||
@@ -64,15 +62,15 @@ pub fn build_block(
|
||||
for j in 0..(block_width / (dim.z as f32 * 2.0)) as usize {
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(
|
||||
.translation(vector![
|
||||
i as f32 * dim.x * 2.0 + dim.x + shift.x,
|
||||
dim.y + shift.y + block_height,
|
||||
j as f32 * dim.z * 2.0 + dim.z + shift.z,
|
||||
)
|
||||
j as f32 * dim.z * 2.0 + dim.z + shift.z
|
||||
])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
|
||||
colliders.insert(collider, handle, bodies);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
testbed.set_initial_body_color(handle, color0);
|
||||
std::mem::swap(&mut color0, &mut color1);
|
||||
}
|
||||
@@ -94,16 +92,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let half_extents = Vector3::new(0.02, 0.1, 0.4) / 2.0 * 10.0;
|
||||
let half_extents = vector![0.02, 0.1, 0.4] / 2.0 * 10.0;
|
||||
let mut block_height = 0.0;
|
||||
// These should only be set to odd values otherwise
|
||||
// the blocks won't align in the nicest way.
|
||||
@@ -120,7 +118,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
half_extents,
|
||||
Vector3::new(-block_width / 2.0, block_height, -block_width / 2.0),
|
||||
vector![-block_width / 2.0, block_height, -block_width / 2.0],
|
||||
numx,
|
||||
numy,
|
||||
numz,
|
||||
@@ -135,5 +133,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
fn create_pyramid(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vector3<f32>,
|
||||
offset: Vector<f32>,
|
||||
stack_height: usize,
|
||||
half_extents: Vector3<f32>,
|
||||
half_extents: Vector<f32>,
|
||||
) {
|
||||
let shift = half_extents * 2.5;
|
||||
for i in 0usize..stack_height {
|
||||
@@ -24,12 +22,14 @@ fn create_pyramid(
|
||||
- stack_height as f32 * half_extents.z;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let rigid_body_handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider =
|
||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
|
||||
colliders.insert(collider, rigid_body_handle, bodies);
|
||||
colliders.insert_with_parent(collider, rigid_body_handle, bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,22 +50,22 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let cube_size = 1.0;
|
||||
let hext = Vector3::repeat(cube_size);
|
||||
let hext = Vector::repeat(cube_size);
|
||||
let bottomy = cube_size;
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(0.0, bottomy, 0.0),
|
||||
vector![0.0, bottomy, 0.0],
|
||||
24,
|
||||
hext,
|
||||
);
|
||||
@@ -74,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
use na::{Point3, Translation3, UnitQuaternion, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
fn create_tower_circle(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vector3<f32>,
|
||||
offset: Vector<f32>,
|
||||
stack_height: usize,
|
||||
nsubdivs: usize,
|
||||
half_extents: Vector3<f32>,
|
||||
half_extents: Vector<f32>,
|
||||
) {
|
||||
let ang_step = std::f32::consts::PI * 2.0 / nsubdivs as f32;
|
||||
let radius = 1.3 * nsubdivs as f32 * half_extents.x / std::f32::consts::PI;
|
||||
@@ -20,16 +18,16 @@ fn create_tower_circle(
|
||||
let fj = j as f32;
|
||||
let fi = i as f32;
|
||||
let y = fi * shift.y;
|
||||
let pos = Translation3::from(offset)
|
||||
* UnitQuaternion::new(Vector3::y() * (fi / 2.0 + fj) * ang_step)
|
||||
* Translation3::new(0.0, y, radius);
|
||||
let pos = Translation::from(offset)
|
||||
* Rotation::new(Vector::y() * (fi / 2.0 + fj) * ang_step)
|
||||
* Translation::new(0.0, y, radius);
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().position(pos).build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider =
|
||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
|
||||
colliders.insert(collider, handle, bodies);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,9 +35,9 @@ fn create_tower_circle(
|
||||
fn create_wall(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vector3<f32>,
|
||||
offset: Vector<f32>,
|
||||
stack_height: usize,
|
||||
half_extents: Vector3<f32>,
|
||||
half_extents: Vector<f32>,
|
||||
) {
|
||||
let shift = half_extents * 2.0;
|
||||
for i in 0usize..stack_height {
|
||||
@@ -52,11 +50,13 @@ fn create_wall(
|
||||
- stack_height as f32 * half_extents.z;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider =
|
||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
|
||||
colliders.insert(collider, handle, bodies);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,9 +64,9 @@ fn create_wall(
|
||||
fn create_pyramid(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vector3<f32>,
|
||||
offset: Vector<f32>,
|
||||
stack_height: usize,
|
||||
half_extents: Vector3<f32>,
|
||||
half_extents: Vector<f32>,
|
||||
) {
|
||||
let shift = half_extents * 2.0;
|
||||
|
||||
@@ -83,11 +83,13 @@ fn create_pyramid(
|
||||
- stack_height as f32 * half_extents.z;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider =
|
||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
|
||||
colliders.insert(collider, handle, bodies);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,71 +110,71 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let cube_size = 1.0;
|
||||
let hext = Vector3::repeat(cube_size);
|
||||
let hext = Vector::repeat(cube_size);
|
||||
let bottomy = cube_size * 50.0;
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(-110.0, bottomy, 0.0),
|
||||
vector![-110.0, bottomy, 0.0],
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(-80.0, bottomy, 0.0),
|
||||
vector![-80.0, bottomy, 0.0],
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(-50.0, bottomy, 0.0),
|
||||
vector![-50.0, bottomy, 0.0],
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(-20.0, bottomy, 0.0),
|
||||
vector![-20.0, bottomy, 0.0],
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_wall(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(-2.0, bottomy, 0.0),
|
||||
vector![-2.0, bottomy, 0.0],
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_wall(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(4.0, bottomy, 0.0),
|
||||
vector![4.0, bottomy, 0.0],
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_wall(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(10.0, bottomy, 0.0),
|
||||
vector![10.0, bottomy, 0.0],
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_tower_circle(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(25.0, bottomy, 0.0),
|
||||
vector![25.0, bottomy, 0.0],
|
||||
8,
|
||||
24,
|
||||
hext,
|
||||
@@ -182,5 +184,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use na::{ComplexField, DMatrix, Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, HeightField};
|
||||
use na::ComplexField;
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = Vector3::new(200.0, 1.0, 200.0);
|
||||
let ground_size = vector![200.0, 1.0, 200.0];
|
||||
let nsubdivs = 20;
|
||||
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
@@ -39,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::trimesh(vertices, indices).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -60,15 +59,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
if j % 2 == 0 {
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
} else {
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,5 +79,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -44,13 +44,13 @@ required-features = [ "dim2", "f64" ]
|
||||
vec_map = { version = "0.8", optional = true }
|
||||
instant = { version = "0.1", features = [ "now" ]}
|
||||
num-traits = "0.2"
|
||||
nalgebra = "0.26"
|
||||
parry2d-f64 = "0.4"
|
||||
simba = "0.4"
|
||||
approx = "0.4"
|
||||
nalgebra = "0.27"
|
||||
parry2d-f64 = "0.5"
|
||||
simba = "0.5"
|
||||
approx = "0.5"
|
||||
rayon = { version = "1", optional = true }
|
||||
crossbeam = "0.8"
|
||||
arrayvec = "0.6"
|
||||
arrayvec = "0.7"
|
||||
bit-vec = "0.6"
|
||||
rustc-hash = "1"
|
||||
serde = { version = "1", features = [ "derive" ], optional = true }
|
||||
|
||||
@@ -44,13 +44,13 @@ required-features = [ "dim2", "f32" ]
|
||||
vec_map = { version = "0.8", optional = true }
|
||||
instant = { version = "0.1", features = [ "now" ]}
|
||||
num-traits = "0.2"
|
||||
nalgebra = "0.26"
|
||||
parry2d = "0.4"
|
||||
simba = "0.4"
|
||||
approx = "0.4"
|
||||
nalgebra = "0.27"
|
||||
parry2d = "0.5"
|
||||
simba = "0.5"
|
||||
approx = "0.5"
|
||||
rayon = { version = "1", optional = true }
|
||||
crossbeam = "0.8"
|
||||
arrayvec = "0.6"
|
||||
arrayvec = "0.7"
|
||||
bit-vec = "0.6"
|
||||
rustc-hash = "1"
|
||||
serde = { version = "1", features = [ "derive" ], optional = true }
|
||||
|
||||
@@ -44,13 +44,13 @@ required-features = [ "dim3", "f64" ]
|
||||
vec_map = { version = "0.8", optional = true }
|
||||
instant = { version = "0.1", features = [ "now" ]}
|
||||
num-traits = "0.2"
|
||||
nalgebra = "0.26"
|
||||
parry3d-f64 = "0.4"
|
||||
simba = "0.4"
|
||||
approx = "0.4"
|
||||
nalgebra = "0.27"
|
||||
parry3d-f64 = "0.5"
|
||||
simba = "0.5"
|
||||
approx = "0.5"
|
||||
rayon = { version = "1", optional = true }
|
||||
crossbeam = "0.8"
|
||||
arrayvec = "0.6"
|
||||
arrayvec = "0.7"
|
||||
bit-vec = "0.6"
|
||||
rustc-hash = "1"
|
||||
serde = { version = "1", features = [ "derive" ], optional = true }
|
||||
|
||||
@@ -44,13 +44,13 @@ required-features = [ "dim3", "f32" ]
|
||||
vec_map = { version = "0.8", optional = true }
|
||||
instant = { version = "0.1", features = [ "now" ]}
|
||||
num-traits = "0.2"
|
||||
nalgebra = "0.26"
|
||||
parry3d = "0.4"
|
||||
simba = "0.4"
|
||||
approx = "0.4"
|
||||
nalgebra = "0.27"
|
||||
parry3d = "0.5"
|
||||
simba = "0.5"
|
||||
approx = "0.5"
|
||||
rayon = { version = "1", optional = true }
|
||||
crossbeam = "0.8"
|
||||
arrayvec = "0.6"
|
||||
arrayvec = "0.7"
|
||||
bit-vec = "0.6"
|
||||
rustc-hash = "1"
|
||||
serde = { version = "1", features = [ "derive" ], optional = true }
|
||||
|
||||
@@ -26,23 +26,22 @@ other-backends = [ "wrapped2d", "nphysics2d" ]
|
||||
|
||||
|
||||
[dependencies]
|
||||
nalgebra = { version = "0.26", features = [ "rand" ] }
|
||||
nalgebra = { version = "0.27", features = [ "rand" ] }
|
||||
rand = "0.8"
|
||||
rand_pcg = "0.3"
|
||||
instant = { version = "0.1", features = [ "web-sys", "now" ]}
|
||||
bitflags = "1"
|
||||
num_cpus = { version = "1", optional = true }
|
||||
wrapped2d = { version = "0.4", optional = true }
|
||||
parry2d = "0.4"
|
||||
ncollide2d = "0.29"
|
||||
nphysics2d = { version = "0.21", optional = true }
|
||||
parry2d = "0.5"
|
||||
ncollide2d = "0.30"
|
||||
nphysics2d = { version = "0.22", optional = true }
|
||||
crossbeam = "0.8"
|
||||
bincode = "1"
|
||||
Inflector = "0.11"
|
||||
md5 = "0.7"
|
||||
|
||||
bevy_egui = "0.4"
|
||||
bevy-orbit-controls = "2"
|
||||
bevy_egui = "0.5"
|
||||
|
||||
# Dependencies for native only.
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
|
||||
@@ -25,16 +25,16 @@ parallel = [ "rapier3d/parallel", "num_cpus" ]
|
||||
other-backends = [ "physx", "physx-sys", "glam", "nphysics3d" ]
|
||||
|
||||
[dependencies]
|
||||
nalgebra = { version = "0.26", features = [ "rand" ] }
|
||||
nalgebra = { version = "0.27", features = [ "rand" ] }
|
||||
rand = "0.8"
|
||||
rand_pcg = "0.3"
|
||||
instant = { version = "0.1", features = [ "web-sys", "now" ]}
|
||||
bitflags = "1"
|
||||
glam = { version = "0.12", optional = true }
|
||||
num_cpus = { version = "1", optional = true }
|
||||
parry3d = "0.4"
|
||||
ncollide3d = "0.29"
|
||||
nphysics3d = { version = "0.21", optional = true }
|
||||
parry3d = "0.5"
|
||||
ncollide3d = "0.30"
|
||||
nphysics3d = { version = "0.22", optional = true }
|
||||
physx = { version = "0.11", optional = true }
|
||||
physx-sys = { version = "0.4", optional = true }
|
||||
crossbeam = "0.8"
|
||||
@@ -43,8 +43,7 @@ md5 = "0.7"
|
||||
Inflector = "0.11"
|
||||
serde = { version = "1", features = [ "derive" ] }
|
||||
|
||||
bevy_egui = "0.4"
|
||||
bevy-orbit-controls = "2"
|
||||
bevy_egui = "0.5"
|
||||
|
||||
# Dependencies for native only.
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
|
||||
@@ -15,7 +15,7 @@ enhanced-determinism = [ "rapier2d/enhanced-determinism" ]
|
||||
[dependencies]
|
||||
rand = "0.8"
|
||||
Inflector = "0.11"
|
||||
nalgebra = "0.26"
|
||||
nalgebra = "0.27"
|
||||
lyon = "0.17"
|
||||
usvg = "0.13"
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -12,13 +10,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// Callback that will be executed on the main loop to handle proximities.
|
||||
testbed.add_callback(move |mut graphics, physics, _, _| {
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 10.0)
|
||||
.translation(vector![0.0, 10.0])
|
||||
.build();
|
||||
let handle = physics.bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
physics
|
||||
.colliders
|
||||
.insert(collider, handle, &mut physics.bodies);
|
||||
.insert_with_parent(collider, handle, &mut physics.bodies);
|
||||
|
||||
if let Some(graphics) = &mut graphics {
|
||||
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
||||
@@ -48,5 +46,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 0.0), 20.0);
|
||||
testbed.look_at(point![0.0, 0.0], 20.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Isometry2, Point2, Point3};
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -21,23 +19,24 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
let collider = ColliderBuilder::cuboid(ground_thickness, ground_size)
|
||||
.translation(-3.0, 0.0)
|
||||
.translation(vector![-3.0, 0.0])
|
||||
.build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
let collider = ColliderBuilder::cuboid(ground_thickness, ground_size)
|
||||
.translation(6.0, 0.0)
|
||||
.translation(vector![6.0, 0.0])
|
||||
.build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
let collider = ColliderBuilder::cuboid(ground_thickness, ground_size)
|
||||
.translation(2.5, 0.0)
|
||||
.translation(vector![2.5, 0.0])
|
||||
.sensor(true)
|
||||
.active_events(ActiveEvents::INTERSECTION_EVENTS)
|
||||
.build();
|
||||
let sensor_handle = colliders.insert(collider, ground_handle, &mut bodies);
|
||||
let sensor_handle = colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the shapes
|
||||
@@ -45,9 +44,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let radx = 0.4;
|
||||
let rady = 0.05;
|
||||
|
||||
let delta1 = Isometry2::translation(0.0, radx - rady);
|
||||
let delta2 = Isometry2::translation(-radx + rady, 0.0);
|
||||
let delta3 = Isometry2::translation(radx - rady, 0.0);
|
||||
let delta1 = Isometry::translation(0.0, radx - rady);
|
||||
let delta2 = Isometry::translation(-radx + rady, 0.0);
|
||||
let delta3 = Isometry::translation(radx - rady, 0.0);
|
||||
|
||||
let mut compound_parts = Vec::new();
|
||||
let vertical = SharedShape::cuboid(rady, radx);
|
||||
@@ -70,8 +69,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(x, y)
|
||||
.linvel(100.0, -10.0)
|
||||
.translation(vector![x, y])
|
||||
.linvel(vector![100.0, -10.0])
|
||||
.ccd_enabled(true)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
@@ -80,12 +79,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// let collider = ColliderBuilder::new(part.1.clone())
|
||||
// .position_wrt_parent(part.0)
|
||||
// .build();
|
||||
// colliders.insert(collider, handle, &mut bodies);
|
||||
// colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
// }
|
||||
|
||||
let collider = ColliderBuilder::new(compound_shape.clone()).build();
|
||||
// let collider = ColliderBuilder::cuboid(radx, rady).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,13 +92,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
testbed.add_callback(move |mut graphics, physics, events, _| {
|
||||
while let Ok(prox) = events.intersection_events.try_recv() {
|
||||
let color = if prox.intersecting {
|
||||
Point3::new(1.0, 1.0, 0.0)
|
||||
[1.0, 1.0, 0.0]
|
||||
} else {
|
||||
Point3::new(0.5, 0.5, 1.0)
|
||||
[0.5, 0.5, 1.0]
|
||||
};
|
||||
|
||||
let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent();
|
||||
let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
|
||||
let parent_handle1 = physics
|
||||
.colliders
|
||||
.get(prox.collider1)
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap();
|
||||
let parent_handle2 = physics
|
||||
.colliders
|
||||
.get(prox.collider2)
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap();
|
||||
if let Some(graphics) = &mut graphics {
|
||||
if parent_handle1 != ground_handle && prox.collider1 != sensor_handle {
|
||||
graphics.set_body_color(parent_handle1, color);
|
||||
@@ -115,5 +124,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 2.5), 20.0);
|
||||
testbed.look_at(point![0.0, 2.5], 20.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point2, Point3};
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet, InteractionGroups};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height)
|
||||
.translation(vector![0.0, -ground_height])
|
||||
.build();
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height).build();
|
||||
colliders.insert(collider, floor_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Setup groups
|
||||
@@ -34,23 +32,24 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* A green floor that will collide with the GREEN group only.
|
||||
*/
|
||||
let green_floor = ColliderBuilder::cuboid(1.0, 0.1)
|
||||
.translation(0.0, 1.0)
|
||||
.translation(vector![0.0, 1.0])
|
||||
.collision_groups(GREEN_GROUP)
|
||||
.build();
|
||||
let green_collider_handle = colliders.insert(green_floor, floor_handle, &mut bodies);
|
||||
let green_collider_handle =
|
||||
colliders.insert_with_parent(green_floor, floor_handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_collider_color(green_collider_handle, Point3::new(0.0, 1.0, 0.0));
|
||||
testbed.set_initial_collider_color(green_collider_handle, [0.0, 1.0, 0.0]);
|
||||
|
||||
/*
|
||||
* A blue floor that will collide with the BLUE group only.
|
||||
*/
|
||||
let blue_floor = ColliderBuilder::cuboid(1.0, 0.1)
|
||||
.translation(0.0, 2.0)
|
||||
.translation(vector![0.0, 2.0])
|
||||
.collision_groups(BLUE_GROUP)
|
||||
.build();
|
||||
let blue_collider_handle = colliders.insert(blue_floor, floor_handle, &mut bodies);
|
||||
let blue_collider_handle = colliders.insert_with_parent(blue_floor, floor_handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_collider_color(blue_collider_handle, Point3::new(0.0, 0.0, 1.0));
|
||||
testbed.set_initial_collider_color(blue_collider_handle, [0.0, 0.0, 1.0]);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -69,17 +68,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Alternate between the green and blue groups.
|
||||
let (group, color) = if i % 2 == 0 {
|
||||
(GREEN_GROUP, Point3::new(0.0, 1.0, 0.0))
|
||||
(GREEN_GROUP, [0.0, 1.0, 0.0])
|
||||
} else {
|
||||
(BLUE_GROUP, Point3::new(0.0, 0.0, 1.0))
|
||||
(BLUE_GROUP, [0.0, 0.0, 1.0])
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad)
|
||||
.collision_groups(group)
|
||||
.build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_body_color(handle, color);
|
||||
}
|
||||
@@ -89,5 +90,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 1.0), 100.0);
|
||||
testbed.look_at(point![0.0, 1.0], 100.0);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use na::Point2;
|
||||
use rand::distributions::{Distribution, Standard};
|
||||
use rand::{rngs::StdRng, SeedableRng};
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -21,23 +19,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.rotation(std::f32::consts::FRAC_PI_2)
|
||||
.translation(ground_size, ground_size * 2.0)
|
||||
.translation(vector![ground_size, ground_size * 2.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.rotation(std::f32::consts::FRAC_PI_2)
|
||||
.translation(-ground_size, ground_size * 2.0)
|
||||
.translation(vector![-ground_size, ground_size * 2.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the convex polygons
|
||||
@@ -58,18 +56,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let x = i as f32 * shift - centerx;
|
||||
let y = j as f32 * shift * 2.0 + centery + 2.0;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let mut points = Vec::new();
|
||||
|
||||
for _ in 0..10 {
|
||||
let pt: Point2<f32> = distribution.sample(&mut rng);
|
||||
let pt: Point<f32> = distribution.sample(&mut rng);
|
||||
points.push(pt * scale);
|
||||
}
|
||||
|
||||
let collider = ColliderBuilder::convex_hull(&points).unwrap().build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,5 +77,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 50.0), 10.0);
|
||||
testbed.look_at(point![0.0, 50.0], 10.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point2, Vector2};
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -24,8 +22,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Build the rigid body.
|
||||
let rb = RigidBodyBuilder::new_dynamic()
|
||||
.translation(x, y)
|
||||
.linvel(x * 10.0, y * 10.0)
|
||||
.translation(vector![x, y])
|
||||
.linvel(vector![x * 10.0, y * 10.0])
|
||||
.angvel(100.0)
|
||||
.linear_damping((i + 1) as f32 * subdiv * 10.0)
|
||||
.angular_damping((num - i) as f32 * subdiv * 10.0)
|
||||
@@ -34,12 +32,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Build the collider.
|
||||
let co = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(co, rb_handle, &mut bodies);
|
||||
colliders.insert_with_parent(co, rb_handle, &mut bodies);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world_with_params(bodies, colliders, joints, Vector2::zeros(), ());
|
||||
testbed.look_at(Point2::new(3.0, 2.0), 50.0);
|
||||
testbed.set_world_with_params(bodies, colliders, joints, Vector::zeros(), ());
|
||||
testbed.look_at(point![3.0, 2.0], 50.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -16,25 +14,25 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
let rad = 1.0;
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -rad)
|
||||
.translation(vector![0.0, -rad])
|
||||
.rotation(std::f32::consts::PI / 4.0)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
// Build the dynamic box rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 3.0 * rad)
|
||||
.translation(vector![0.0, 3.0 * rad])
|
||||
.can_sleep(false)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 0.0), 50.0);
|
||||
testbed.look_at(point![0.0, 0.0], 50.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use na::{DVector, Point2, Vector2};
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use na::DVector;
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = Vector2::new(50.0, 1.0);
|
||||
let ground_size = Vector::new(50.0, 1.0);
|
||||
let nsubdivs = 2000;
|
||||
|
||||
let heights = DVector::from_fn(nsubdivs + 1, |i, _| {
|
||||
@@ -28,7 +27,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::heightfield(heights, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -46,15 +45,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = j as f32 * shift + centery + 3.0;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
if j % 2 == 0 {
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
} else {
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 0.0), 10.0);
|
||||
testbed.look_at(point![0.0, 0.0], 10.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -15,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Create the balls
|
||||
*/
|
||||
// Build the rigid body.
|
||||
// NOTE: a smaller radius (e.g. 0.1) breaks Box2D so
|
||||
// NOTE: a smaller radius (e.g. 0.1) breaks Box2D so
|
||||
// in order to be able to compare rapier with Box2D,
|
||||
// we set it to 0.4.
|
||||
let rad = 0.4;
|
||||
@@ -37,16 +35,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(fk * shift, -fi * shift)
|
||||
.translation(vector![fk * shift, -fi * shift])
|
||||
.build();
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, child_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||
|
||||
// Vertical joint.
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint = BallJoint::new(Point2::origin(), Point2::new(0.0, shift));
|
||||
let joint = BallJoint::new(Point::origin(), point![0.0, shift]);
|
||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
|
||||
@@ -54,7 +52,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
if k > 0 {
|
||||
let parent_index = body_handles.len() - numi;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = BallJoint::new(Point2::origin(), Point2::new(-shift, 0.0));
|
||||
let joint = BallJoint::new(Point::origin(), point![-shift, 0.0]);
|
||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
|
||||
@@ -66,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(numk as f32 * rad, numi as f32 * -rad), 20.0);
|
||||
testbed.look_at(point![numk as f32 * rad, numi as f32 * -rad], 20.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
// This shows a bug when a cylinder is in contact with a very large
|
||||
@@ -21,38 +19,38 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height)
|
||||
.translation(vector![0.0, -ground_height])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* A rectangle that only rotate.
|
||||
*/
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 3.0)
|
||||
.translation(vector![0.0, 3.0])
|
||||
.lock_translations()
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(2.0, 0.6).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* A tilted capsule that cannot rotate.
|
||||
*/
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 5.0)
|
||||
.translation(vector![0.0, 5.0])
|
||||
.rotation(1.0)
|
||||
.lock_rotations()
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_y(0.6, 0.4).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 0.0), 40.0);
|
||||
testbed.look_at(point![0.0, 0.0], 40.0);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
use na::{Point2, Vector2};
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderHandle, ColliderSet};
|
||||
use rapier2d::pipeline::{ContactModificationContext, PhysicsHooks, PhysicsHooksFlags};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
struct OneWayPlatformHook {
|
||||
@@ -10,10 +7,6 @@ struct OneWayPlatformHook {
|
||||
}
|
||||
|
||||
impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
|
||||
fn active_hooks(&self) -> PhysicsHooksFlags {
|
||||
PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS
|
||||
}
|
||||
|
||||
fn modify_solver_contacts(
|
||||
&self,
|
||||
context: &mut ContactModificationContext<RigidBodySet, ColliderSet>,
|
||||
@@ -30,20 +23,20 @@ impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
|
||||
// - If context.collider_handle2 == self.platform1 then the allowed normal is -y.
|
||||
// - If context.collider_handle1 == self.platform2 then its allowed normal +y needs to be flipped to -y.
|
||||
// - If context.collider_handle2 == self.platform2 then the allowed normal -y needs to be flipped to +y.
|
||||
let mut allowed_local_n1 = Vector2::zeros();
|
||||
let mut allowed_local_n1 = Vector::zeros();
|
||||
|
||||
if context.collider1 == self.platform1 {
|
||||
allowed_local_n1 = Vector2::y();
|
||||
allowed_local_n1 = Vector::y();
|
||||
} else if context.collider2 == self.platform1 {
|
||||
// Flip the allowed direction.
|
||||
allowed_local_n1 = -Vector2::y();
|
||||
allowed_local_n1 = -Vector::y();
|
||||
}
|
||||
|
||||
if context.collider1 == self.platform2 {
|
||||
allowed_local_n1 = -Vector2::y();
|
||||
allowed_local_n1 = -Vector::y();
|
||||
} else if context.collider2 == self.platform2 {
|
||||
// Flip the allowed direction.
|
||||
allowed_local_n1 = Vector2::y();
|
||||
allowed_local_n1 = Vector::y();
|
||||
}
|
||||
|
||||
// Call the helper function that simulates one-way platforms.
|
||||
@@ -78,15 +71,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = ColliderBuilder::cuboid(25.0, 0.5)
|
||||
.translation(30.0, 2.0)
|
||||
.modify_solver_contacts(true)
|
||||
.translation(vector![30.0, 2.0])
|
||||
.active_hooks(ActiveHooks::MODIFY_SOLVER_CONTACTS)
|
||||
.build();
|
||||
let platform1 = colliders.insert(collider, handle, &mut bodies);
|
||||
let platform1 = colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
let collider = ColliderBuilder::cuboid(25.0, 0.5)
|
||||
.translation(-30.0, -2.0)
|
||||
.modify_solver_contacts(true)
|
||||
.translation(vector![-30.0, -2.0])
|
||||
.active_hooks(ActiveHooks::MODIFY_SOLVER_CONTACTS)
|
||||
.build();
|
||||
let platform2 = colliders.insert(collider, handle, &mut bodies);
|
||||
let platform2 = colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Setup the one-way platform hook.
|
||||
@@ -105,12 +98,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// Spawn a new cube.
|
||||
let collider = ColliderBuilder::cuboid(1.5, 2.0).build();
|
||||
let body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(20.0, 10.0)
|
||||
.translation(vector![20.0, 10.0])
|
||||
.build();
|
||||
let handle = physics.bodies.insert(body);
|
||||
physics
|
||||
.colliders
|
||||
.insert(collider, handle, &mut physics.bodies);
|
||||
.insert_with_parent(collider, handle, &mut physics.bodies);
|
||||
|
||||
if let Some(graphics) = graphics {
|
||||
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
||||
@@ -134,8 +127,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
bodies,
|
||||
colliders,
|
||||
joints,
|
||||
Vector2::new(0.0, -9.81),
|
||||
vector![0.0, -9.81],
|
||||
physics_hooks,
|
||||
);
|
||||
testbed.look_at(Point2::new(0.0, 0.0), 20.0);
|
||||
testbed.look_at(point![0.0, 0.0], 20.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height)
|
||||
.translation(vector![0.0, -ground_height])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the boxes
|
||||
@@ -40,47 +38,57 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = j as f32 * shift + centery;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup a kinematic rigid body.
|
||||
* Setup a position-based kinematic rigid body.
|
||||
*/
|
||||
let platform_body = RigidBodyBuilder::new_kinematic()
|
||||
.translation(-10.0 * rad, 1.5 + 0.8)
|
||||
let platform_body = RigidBodyBuilder::new_kinematic_velocity_based()
|
||||
.translation(vector![-10.0 * rad, 1.5 + 0.8])
|
||||
.build();
|
||||
let platform_handle = bodies.insert(platform_body);
|
||||
let velocity_based_platform_handle = bodies.insert(platform_body);
|
||||
let collider = ColliderBuilder::cuboid(rad * 10.0, rad).build();
|
||||
colliders.insert(collider, platform_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, velocity_based_platform_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Setup a velocity-based kinematic rigid body.
|
||||
*/
|
||||
let platform_body = RigidBodyBuilder::new_kinematic_position_based()
|
||||
.translation(vector![-10.0 * rad, 2.0 + 1.5 + 0.8])
|
||||
.build();
|
||||
let position_based_platform_handle = bodies.insert(platform_body);
|
||||
let collider = ColliderBuilder::cuboid(rad * 10.0, rad).build();
|
||||
colliders.insert_with_parent(collider, position_based_platform_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Setup a callback to control the platform.
|
||||
*/
|
||||
testbed.add_callback(move |_, physics, _, run_state| {
|
||||
let platform = physics.bodies.get_mut(platform_handle).unwrap();
|
||||
let mut next_pos = *platform.position();
|
||||
let velocity = vector![run_state.time.sin() * 5.0, (run_state.time * 5.0).sin()];
|
||||
|
||||
let dt = 0.016;
|
||||
next_pos.translation.vector.y += (run_state.time * 5.0).sin() * dt;
|
||||
next_pos.translation.vector.x += run_state.time.sin() * 5.0 * dt;
|
||||
|
||||
if next_pos.translation.vector.x >= rad * 10.0 {
|
||||
next_pos.translation.vector.x -= dt;
|
||||
}
|
||||
if next_pos.translation.vector.x <= -rad * 10.0 {
|
||||
next_pos.translation.vector.x += dt;
|
||||
// Update the velocity-based kinematic body by setting its velocity.
|
||||
if let Some(platform) = physics.bodies.get_mut(velocity_based_platform_handle) {
|
||||
platform.set_linvel(velocity, true);
|
||||
}
|
||||
|
||||
platform.set_next_kinematic_position(next_pos);
|
||||
// Update the position-based kinematic body by setting its next position.
|
||||
if let Some(platform) = physics.bodies.get_mut(position_based_platform_handle) {
|
||||
let mut next_tra = *platform.translation();
|
||||
next_tra += velocity * physics.integration_parameters.dt;
|
||||
platform.set_next_kinematic_translation(next_tra);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Run the simulation.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 1.0), 40.0);
|
||||
testbed.look_at(point![0.0, 1.0], 40.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use na::{ComplexField, Point2};
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use na::ComplexField;
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -19,18 +18,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let step_size = ground_size / (nsubdivs as f32);
|
||||
let mut points = Vec::new();
|
||||
|
||||
points.push(Point2::new(-ground_size / 2.0, 40.0));
|
||||
points.push(point![-ground_size / 2.0, 40.0]);
|
||||
for i in 1..nsubdivs - 1 {
|
||||
let x = -ground_size / 2.0 + i as f32 * step_size;
|
||||
let y = ComplexField::cos(i as f32 * step_size) * 2.0;
|
||||
points.push(Point2::new(x, y));
|
||||
points.push(point![x, y]);
|
||||
}
|
||||
points.push(Point2::new(ground_size / 2.0, 40.0));
|
||||
points.push(point![ground_size / 2.0, 40.0]);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::polyline(points, None).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -48,15 +47,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = j as f32 * shift + centery + 3.0;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
if j % 2 == 0 {
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
} else {
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,5 +66,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 0.0), 10.0);
|
||||
testbed.look_at(point![0.0, 0.0], 10.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -20,7 +18,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -40,10 +38,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = fi * shift + centery;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,5 +51,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 2.5), 20.0);
|
||||
testbed.look_at(point![0.0, 2.5], 20.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,13 +16,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 1.0;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height)
|
||||
.translation(vector![0.0, -ground_height])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height)
|
||||
.restitution(1.0)
|
||||
.build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let num = 10;
|
||||
let rad = 0.5;
|
||||
@@ -33,13 +31,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
for i in 0..=num {
|
||||
let x = (i as f32) - num as f32 / 2.0;
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(x * 2.0, 10.0 * (j as f32 + 1.0))
|
||||
.translation(vector![x * 2.0, 10.0 * (j as f32 + 1.0)])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad)
|
||||
.restitution((i as f32) / (num as f32))
|
||||
.build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,5 +45,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 1.0), 25.0);
|
||||
testbed.look_at(point![0.0, 1.0], 25.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point2, Point3};
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height)
|
||||
.translation(vector![0.0, -ground_height])
|
||||
.build();
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height).build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create some boxes.
|
||||
@@ -38,12 +36,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = 3.0;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_body_color(handle, Point3::new(0.5, 0.5, 1.0));
|
||||
testbed.set_initial_body_color(handle, [0.5, 0.5, 1.0]);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -52,33 +52,38 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Rigid body so that the sensor can move.
|
||||
let sensor = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 10.0)
|
||||
.translation(vector![0.0, 10.0])
|
||||
.build();
|
||||
let sensor_handle = bodies.insert(sensor);
|
||||
|
||||
// Solid cube attached to the sensor which
|
||||
// other colliders can touch.
|
||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||
colliders.insert(collider, sensor_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, sensor_handle, &mut bodies);
|
||||
|
||||
// We create a collider desc without density because we don't
|
||||
// want it to contribute to the rigid body mass.
|
||||
let sensor_collider = ColliderBuilder::ball(rad * 5.0).sensor(true).build();
|
||||
colliders.insert(sensor_collider, sensor_handle, &mut bodies);
|
||||
let sensor_collider = ColliderBuilder::ball(rad * 5.0)
|
||||
.density(0.0)
|
||||
.sensor(true)
|
||||
.active_events(ActiveEvents::INTERSECTION_EVENTS)
|
||||
.build();
|
||||
colliders.insert_with_parent(sensor_collider, sensor_handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0));
|
||||
testbed.set_initial_body_color(sensor_handle, [0.5, 1.0, 1.0]);
|
||||
|
||||
// Callback that will be executed on the main loop to handle proximities.
|
||||
testbed.add_callback(move |mut graphics, physics, events, _| {
|
||||
while let Ok(prox) = events.intersection_events.try_recv() {
|
||||
let color = if prox.intersecting {
|
||||
Point3::new(1.0, 1.0, 0.0)
|
||||
[1.0, 1.0, 0.0]
|
||||
} else {
|
||||
Point3::new(0.5, 0.5, 1.0)
|
||||
[0.5, 0.5, 1.0]
|
||||
};
|
||||
|
||||
let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent();
|
||||
let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
|
||||
let parent_handle1 = physics.colliders[prox.collider1].parent().unwrap();
|
||||
let parent_handle2 = physics.colliders[prox.collider2].parent().unwrap();
|
||||
|
||||
if let Some(graphics) = &mut graphics {
|
||||
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
||||
graphics.set_body_color(parent_handle1, color);
|
||||
@@ -94,5 +99,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 1.0), 100.0);
|
||||
testbed.look_at(point![0.0, 1.0], 100.0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point2;
|
||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier2d::prelude::*;
|
||||
use rapier_testbed2d::Testbed;
|
||||
|
||||
use lyon::math::Point;
|
||||
@@ -25,23 +23,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.rotation(std::f32::consts::FRAC_PI_2)
|
||||
.translation(ground_size, ground_size)
|
||||
.translation(vector![ground_size, ground_size])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.rotation(std::f32::consts::FRAC_PI_2)
|
||||
.translation(-ground_size, ground_size)
|
||||
.translation(vector![-ground_size, ground_size])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the trimeshes from a tesselated SVG.
|
||||
@@ -83,18 +81,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let vertices: Vec<_> = mesh
|
||||
.vertices
|
||||
.iter()
|
||||
.map(|v| Point2::new(v.position[0] * sx, v.position[1] * -sy))
|
||||
.map(|v| point![v.position[0] * sx, v.position[1] * -sy])
|
||||
.collect();
|
||||
|
||||
for k in 0..5 {
|
||||
let collider =
|
||||
ColliderBuilder::trimesh(vertices.clone(), indices.clone()).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(ith as f32 * 8.0 - 20.0, 20.0 + k as f32 * 11.0)
|
||||
.translation(vector![ith as f32 * 8.0 - 20.0, 20.0 + k as f32 * 11.0])
|
||||
.rotation(angle)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
|
||||
ith += 1;
|
||||
@@ -106,7 +104,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point2::new(0.0, 20.0), 17.0);
|
||||
testbed.look_at(point![0.0, 20.0], 17.0);
|
||||
}
|
||||
|
||||
const RAPIER_SVG_STR: &'static str = r#"
|
||||
|
||||
@@ -16,7 +16,7 @@ enhanced-determinism = [ "rapier3d/enhanced-determinism" ]
|
||||
rand = "0.8"
|
||||
getrandom = { version = "0.2", features = [ "js" ] }
|
||||
Inflector = "0.11"
|
||||
nalgebra = "0.26"
|
||||
nalgebra = "0.27"
|
||||
wasm-bindgen = "0.2"
|
||||
obj-rs = { version = "0.6", default-features = false }
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
fn create_wall(
|
||||
testbed: &mut Testbed,
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vector3<f32>,
|
||||
offset: Vector<f32>,
|
||||
stack_height: usize,
|
||||
half_extents: Vector3<f32>,
|
||||
half_extents: Vector<f32>,
|
||||
) {
|
||||
let shift = half_extents * 2.0;
|
||||
let mut k = 0;
|
||||
@@ -23,22 +21,18 @@ fn create_wall(
|
||||
- stack_height as f32 * half_extents.z;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider =
|
||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
|
||||
colliders.insert(collider, handle, bodies);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
k += 1;
|
||||
if k % 2 == 0 {
|
||||
testbed.set_initial_body_color(
|
||||
handle,
|
||||
Point3::new(255. / 255., 131. / 255., 244.0 / 255.),
|
||||
);
|
||||
testbed.set_initial_body_color(handle, [255. / 255., 131. / 255., 244.0 / 255.]);
|
||||
} else {
|
||||
testbed.set_initial_body_color(
|
||||
handle,
|
||||
Point3::new(131. / 255., 255. / 255., 244.0 / 255.),
|
||||
);
|
||||
testbed.set_initial_body_color(handle, [131. / 255., 255. / 255., 244.0 / 255.]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,11 +53,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the pyramids.
|
||||
@@ -79,18 +73,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
testbed,
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(x, shift_y, 0.0),
|
||||
vector![x, shift_y, 0.0],
|
||||
num_z,
|
||||
Vector3::new(0.5, 0.5, 1.0),
|
||||
vector![0.5, 0.5, 1.0],
|
||||
);
|
||||
|
||||
create_wall(
|
||||
testbed,
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vector3::new(x, shift_y, shift_z),
|
||||
vector![x, shift_y, shift_z],
|
||||
num_z,
|
||||
Vector3::new(0.5, 0.5, 1.0),
|
||||
vector![0.5, 0.5, 1.0],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -102,37 +96,48 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let collider = ColliderBuilder::ball(1.0)
|
||||
.density(10.0)
|
||||
.sensor(true)
|
||||
.active_events(ActiveEvents::INTERSECTION_EVENTS)
|
||||
.build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.linvel(1000.0, 0.0, 0.0)
|
||||
.translation(-20.0, shift_y + 2.0, 0.0)
|
||||
.linvel(vector![1000.0, 0.0, 0.0])
|
||||
.translation(vector![-20.0, shift_y + 2.0, 0.0])
|
||||
.ccd_enabled(true)
|
||||
.build();
|
||||
let sensor_handle = bodies.insert(rigid_body);
|
||||
colliders.insert(collider, sensor_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, sensor_handle, &mut bodies);
|
||||
|
||||
// Second rigid-body with CCD enabled.
|
||||
let collider = ColliderBuilder::ball(1.0).density(10.0).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.linvel(1000.0, 0.0, 0.0)
|
||||
.translation(-20.0, shift_y + 2.0, shift_z)
|
||||
.linvel(vector![1000.0, 0.0, 0.0])
|
||||
.translation(vector![-20.0, shift_y + 2.0, shift_z])
|
||||
.ccd_enabled(true)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
colliders.insert(collider.clone(), handle, &mut bodies);
|
||||
testbed.set_initial_body_color(handle, Point3::new(0.2, 0.2, 1.0));
|
||||
colliders.insert_with_parent(collider.clone(), handle, &mut bodies);
|
||||
testbed.set_initial_body_color(handle, [0.2, 0.2, 1.0]);
|
||||
|
||||
// Callback that will be executed on the main loop to handle proximities.
|
||||
testbed.add_callback(move |mut graphics, physics, events, _| {
|
||||
while let Ok(prox) = events.intersection_events.try_recv() {
|
||||
let color = if prox.intersecting {
|
||||
Point3::new(1.0, 1.0, 0.0)
|
||||
[1.0, 1.0, 0.0]
|
||||
} else {
|
||||
Point3::new(0.5, 0.5, 1.0)
|
||||
[0.5, 0.5, 1.0]
|
||||
};
|
||||
|
||||
let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent();
|
||||
let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
|
||||
let parent_handle1 = physics
|
||||
.colliders
|
||||
.get(prox.collider1)
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap();
|
||||
let parent_handle2 = physics
|
||||
.colliders
|
||||
.get(prox.collider2)
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap();
|
||||
|
||||
if let Some(graphics) = &mut graphics {
|
||||
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
||||
@@ -149,5 +154,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, InteractionGroups};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, floor_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Setup groups
|
||||
@@ -34,23 +32,24 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* A green floor that will collide with the GREEN group only.
|
||||
*/
|
||||
let green_floor = ColliderBuilder::cuboid(1.0, 0.1, 1.0)
|
||||
.translation(0.0, 1.0, 0.0)
|
||||
.translation(vector![0.0, 1.0, 0.0])
|
||||
.collision_groups(GREEN_GROUP)
|
||||
.build();
|
||||
let green_collider_handle = colliders.insert(green_floor, floor_handle, &mut bodies);
|
||||
let green_collider_handle =
|
||||
colliders.insert_with_parent(green_floor, floor_handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_collider_color(green_collider_handle, Point3::new(0.0, 1.0, 0.0));
|
||||
testbed.set_initial_collider_color(green_collider_handle, [0.0, 1.0, 0.0]);
|
||||
|
||||
/*
|
||||
* A blue floor that will collide with the BLUE group only.
|
||||
*/
|
||||
let blue_floor = ColliderBuilder::cuboid(1.0, 0.1, 1.0)
|
||||
.translation(0.0, 2.0, 0.0)
|
||||
.translation(vector![0.0, 2.0, 0.0])
|
||||
.collision_groups(BLUE_GROUP)
|
||||
.build();
|
||||
let blue_collider_handle = colliders.insert(blue_floor, floor_handle, &mut bodies);
|
||||
let blue_collider_handle = colliders.insert_with_parent(blue_floor, floor_handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_collider_color(blue_collider_handle, Point3::new(0.0, 0.0, 1.0));
|
||||
testbed.set_initial_collider_color(blue_collider_handle, [0.0, 0.0, 1.0]);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -72,17 +71,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Alternate between the green and blue groups.
|
||||
let (group, color) = if k % 2 == 0 {
|
||||
(GREEN_GROUP, Point3::new(0.0, 1.0, 0.0))
|
||||
(GREEN_GROUP, [0.0, 1.0, 0.0])
|
||||
} else {
|
||||
(BLUE_GROUP, Point3::new(0.0, 0.0, 1.0))
|
||||
(BLUE_GROUP, [0.0, 0.0, 1.0])
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad)
|
||||
.collision_groups(group)
|
||||
.build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_body_color(handle, color);
|
||||
}
|
||||
@@ -93,5 +94,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
|
||||
testbed.look_at(point!(10.0, 10.0, 10.0), Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Isometry3, Point3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -46,40 +44,42 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift * 2.0 - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
// First option: attach several colliders to a single rigid-body.
|
||||
if j < numy / 2 {
|
||||
let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad).build();
|
||||
let collider2 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
||||
.translation(rad * 10.0, rad * 10.0, 0.0)
|
||||
.translation(vector![rad * 10.0, rad * 10.0, 0.0])
|
||||
.build();
|
||||
let collider3 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
||||
.translation(-rad * 10.0, rad * 10.0, 0.0)
|
||||
.translation(vector![-rad * 10.0, rad * 10.0, 0.0])
|
||||
.build();
|
||||
colliders.insert(collider1, handle, &mut bodies);
|
||||
colliders.insert(collider2, handle, &mut bodies);
|
||||
colliders.insert(collider3, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider1, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider2, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider3, handle, &mut bodies);
|
||||
} else {
|
||||
// Second option: create a compound shape and attach it to a single collider.
|
||||
let shapes = vec![
|
||||
(
|
||||
Isometry3::identity(),
|
||||
Isometry::identity(),
|
||||
SharedShape::cuboid(rad * 10.0, rad, rad),
|
||||
),
|
||||
(
|
||||
Isometry3::translation(rad * 10.0, rad * 10.0, 0.0),
|
||||
Isometry::translation(rad * 10.0, rad * 10.0, 0.0),
|
||||
SharedShape::cuboid(rad, rad * 10.0, rad),
|
||||
),
|
||||
(
|
||||
Isometry3::translation(-rad * 10.0, rad * 10.0, 0.0),
|
||||
Isometry::translation(-rad * 10.0, rad * 10.0, 0.0),
|
||||
SharedShape::cuboid(rad, rad * 10.0, rad),
|
||||
),
|
||||
];
|
||||
|
||||
let collider = ColliderBuilder::compound(shapes).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,5 +91,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use na::Point3;
|
||||
use obj::raw::object::Polygon;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
|
||||
use rapier3d::parry::bounding_volume;
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
@@ -26,11 +24,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the convex decompositions.
|
||||
@@ -52,7 +50,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let mut vertices: Vec<_> = model
|
||||
.positions
|
||||
.iter()
|
||||
.map(|v| Point3::new(v.0, v.1, v.2))
|
||||
.map(|v| point![v.0, v.1, v.2])
|
||||
.collect();
|
||||
use std::iter::FromIterator;
|
||||
let indices: Vec<_> = model
|
||||
@@ -90,12 +88,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = (igeom / width) as f32 * shift + 4.0;
|
||||
let z = k as f32 * shift;
|
||||
|
||||
let body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(body);
|
||||
|
||||
for shape in &shapes {
|
||||
let collider = ColliderBuilder::new(shape.clone()).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
fn models() -> Vec<String> {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use na::Point3;
|
||||
use rand::distributions::{Distribution, Standard};
|
||||
use rand::{rngs::StdRng, SeedableRng};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -20,11 +18,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the polyhedra
|
||||
@@ -50,17 +48,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
let mut points = Vec::new();
|
||||
for _ in 0..10 {
|
||||
let pt: Point3<f32> = distribution.sample(&mut rng);
|
||||
let pt: Point<f32> = distribution.sample(&mut rng);
|
||||
points.push(pt * scale);
|
||||
}
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::round_convex_hull(&points, border_rad)
|
||||
.unwrap()
|
||||
.build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,5 +69,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(30.0, 30.0, 30.0), Point3::origin());
|
||||
testbed.look_at(point![30.0, 30.0, 30.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -24,9 +22,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Build the rigid body.
|
||||
let rb = RigidBodyBuilder::new_dynamic()
|
||||
.translation(x, y, 0.0)
|
||||
.linvel(x * 10.0, y * 10.0, 0.0)
|
||||
.angvel(Vector3::z() * 100.0)
|
||||
.translation(vector![x, y, 0.0])
|
||||
.linvel(vector![x * 10.0, y * 10.0, 0.0])
|
||||
.angvel(Vector::z() * 100.0)
|
||||
.linear_damping((i + 1) as f32 * subdiv * 10.0)
|
||||
.angular_damping((num - i) as f32 * subdiv * 10.0)
|
||||
.build();
|
||||
@@ -34,12 +32,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Build the collider.
|
||||
let co = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(co, rb_handle, &mut bodies);
|
||||
colliders.insert_with_parent(co, rb_handle, &mut bodies);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world_with_params(bodies, colliders, joints, Vector3::zeros(), ());
|
||||
testbed.look_at(Point3::new(2.0, 2.5, 20.0), Point3::new(2.0, 2.5, 0.0));
|
||||
testbed.set_world_with_params(bodies, colliders, joints, Vector::zeros(), ());
|
||||
testbed.look_at(point![2.0, 2.5, 20.0], point![2.0, 2.5, 0.0]);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -17,22 +15,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4).build();
|
||||
let mut ground_collider_handle = colliders.insert(collider, ground_handle, &mut bodies);
|
||||
let mut ground_collider_handle =
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Rolling ball
|
||||
*/
|
||||
let ball_rad = 0.1;
|
||||
let rb = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 0.2, 0.0)
|
||||
.translation(vector![0.0, 0.2, 0.0])
|
||||
.build();
|
||||
let ball_handle = bodies.insert(rb);
|
||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
|
||||
colliders.insert(collider, ball_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ball_handle, &mut bodies);
|
||||
|
||||
testbed.add_callback(move |_, physics, _, _| {
|
||||
// Remove then re-add the ground collider.
|
||||
@@ -46,14 +45,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
true,
|
||||
)
|
||||
.unwrap();
|
||||
ground_collider_handle = physics
|
||||
.colliders
|
||||
.insert(coll, ground_handle, &mut physics.bodies);
|
||||
ground_collider_handle =
|
||||
physics
|
||||
.colliders
|
||||
.insert_with_parent(coll, ground_handle, &mut physics.bodies);
|
||||
});
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, HalfSpace, SharedShape};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -16,9 +14,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let halfspace = SharedShape::new(HalfSpace::new(Vector3::y_axis()));
|
||||
let halfspace = SharedShape::new(HalfSpace::new(Vector::y_axis()));
|
||||
let collider = ColliderBuilder::new(halfspace).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let mut curr_y = 0.0;
|
||||
let mut curr_width = 10_000.0;
|
||||
@@ -28,11 +26,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
curr_y += curr_height * 4.0;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, curr_y, 0.0)
|
||||
.translation(vector![0.0, curr_y, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(curr_width, curr_height, curr_width).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
curr_width /= 5.0;
|
||||
}
|
||||
@@ -41,5 +39,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -19,28 +17,28 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
for _ in 0..6 {
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
|
||||
// Build the dynamic box rigid body.
|
||||
for _ in 0..6 {
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(1.1, 0.0, 0.0)
|
||||
.rotation(Vector3::new(0.8, 0.2, 0.1))
|
||||
.translation(vector![1.1, 0.0, 0.0])
|
||||
.rotation(vector![0.8, 0.2, 0.1])
|
||||
.can_sleep(false)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(2.0, 0.1, 1.0).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
// This shows a bug when a cylinder is in contact with a very large
|
||||
@@ -21,11 +19,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -47,14 +45,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = -centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cylinder(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Isometry3, Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -17,30 +15,30 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4)
|
||||
.friction(0.15)
|
||||
// .restitution(0.5)
|
||||
.build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Rolling ball
|
||||
*/
|
||||
let ball_rad = 0.1;
|
||||
let rb = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 0.2, 0.0)
|
||||
.linvel(10.0, 0.0, 0.0)
|
||||
.translation(vector![0.0, 0.2, 0.0])
|
||||
.linvel(vector![10.0, 0.0, 0.0])
|
||||
.build();
|
||||
let ball_handle = bodies.insert(rb);
|
||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
|
||||
colliders.insert(collider, ball_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ball_handle, &mut bodies);
|
||||
|
||||
let mut linvel = Vector3::zeros();
|
||||
let mut angvel = Vector3::zeros();
|
||||
let mut pos = Isometry3::identity();
|
||||
let mut linvel = Vector::zeros();
|
||||
let mut angvel = Vector::zeros();
|
||||
let mut pos = Isometry::identity();
|
||||
let mut step = 0;
|
||||
let mut extra_colliders = Vec::new();
|
||||
let snapped_frame = 51;
|
||||
@@ -55,7 +53,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let new_ball_collider_handle =
|
||||
physics
|
||||
.colliders
|
||||
.insert(collider, ball_handle, &mut physics.bodies);
|
||||
.insert_with_parent(collider, ball_handle, &mut physics.bodies);
|
||||
|
||||
if let Some(graphics) = &mut graphics {
|
||||
graphics.add_collider(new_ball_collider_handle, &physics.colliders);
|
||||
@@ -93,7 +91,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Remove then re-add the ground collider.
|
||||
// let ground = physics.bodies.get_mut(ground_handle).unwrap();
|
||||
// ground.set_position(Isometry3::translation(0.0, step as f32 * 0.001, 0.0), false);
|
||||
// ground.set_position(Isometry::translation(0.0, step as f32 * 0.001, 0.0), false);
|
||||
// let coll = physics
|
||||
// .colliders
|
||||
// .remove(ground_collider_handle, &mut physics.bodies, true)
|
||||
@@ -104,7 +102,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let new_ground_collider_handle =
|
||||
physics
|
||||
.colliders
|
||||
.insert(coll, ground_handle, &mut physics.bodies);
|
||||
.insert_with_parent(coll, ground_handle, &mut physics.bodies);
|
||||
|
||||
if let Some(graphics) = &mut graphics {
|
||||
graphics.add_collider(new_ground_collider_handle, &physics.colliders);
|
||||
@@ -117,5 +115,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -22,24 +20,24 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size)
|
||||
.friction(1.5)
|
||||
.build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
// Build a dynamic box rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 1.1, 0.0)
|
||||
.rotation(Vector3::y() * 0.3)
|
||||
.translation(vector![0.0, 1.1, 0.0])
|
||||
.rotation(Vector::y() * 0.3)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(2.0, 1.0, 3.0).friction(1.5).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = &mut bodies[handle];
|
||||
let force = rigid_body.position() * Vector3::z() * 50.0;
|
||||
let force = rigid_body.position() * Vector::z() * 50.0;
|
||||
rigid_body.set_linvel(force, true);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,33 +16,33 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 2.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, 4.0, 0.0)
|
||||
.translation(vector![0.0, 4.0, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rad = 1.0;
|
||||
// Build the dynamic box rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 7.0 * rad, 0.0)
|
||||
.translation(vector![0.0, 7.0 * rad, 0.0])
|
||||
.can_sleep(false)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 2.0 * rad, 0.0)
|
||||
.translation(vector![0.0, 2.0 * rad, 0.0])
|
||||
.can_sleep(false)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.look_at(Point3::new(100.0, -10.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, -10.0, 100.0], Point::origin());
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
fn prismatic_repro(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
joints: &mut JointSet,
|
||||
box_center: Point3<f32>,
|
||||
box_center: Point<f32>,
|
||||
) {
|
||||
let box_rb = bodies.insert(
|
||||
RigidBodyBuilder::new_dynamic()
|
||||
.translation(box_center.x, box_center.y, box_center.z)
|
||||
.translation(vector![box_center.x, box_center.y, box_center.z])
|
||||
.build(),
|
||||
);
|
||||
colliders.insert(
|
||||
colliders.insert_with_parent(
|
||||
ColliderBuilder::cuboid(1.0, 0.25, 1.0).build(),
|
||||
box_rb,
|
||||
bodies,
|
||||
@@ -22,32 +20,32 @@ fn prismatic_repro(
|
||||
|
||||
let wheel_y = -1.0;
|
||||
let wheel_positions = vec![
|
||||
Vector3::new(1.0, wheel_y, -1.0),
|
||||
Vector3::new(-1.0, wheel_y, -1.0),
|
||||
Vector3::new(1.0, wheel_y, 1.0),
|
||||
Vector3::new(-1.0, wheel_y, 1.0),
|
||||
vector![1.0, wheel_y, -1.0],
|
||||
vector![-1.0, wheel_y, -1.0],
|
||||
vector![1.0, wheel_y, 1.0],
|
||||
vector![-1.0, wheel_y, 1.0],
|
||||
];
|
||||
|
||||
for pos in wheel_positions {
|
||||
let wheel_pos_in_world = box_center + pos;
|
||||
let wheel_rb = bodies.insert(
|
||||
RigidBodyBuilder::new_dynamic()
|
||||
.translation(
|
||||
.translation(vector![
|
||||
wheel_pos_in_world.x,
|
||||
wheel_pos_in_world.y,
|
||||
wheel_pos_in_world.z,
|
||||
)
|
||||
wheel_pos_in_world.z
|
||||
])
|
||||
.build(),
|
||||
);
|
||||
colliders.insert(ColliderBuilder::ball(0.5).build(), wheel_rb, bodies);
|
||||
colliders.insert_with_parent(ColliderBuilder::ball(0.5).build(), wheel_rb, bodies);
|
||||
|
||||
let mut prismatic = rapier3d::dynamics::PrismaticJoint::new(
|
||||
Point3::new(pos.x, pos.y, pos.z),
|
||||
Vector3::y_axis(),
|
||||
Vector3::default(),
|
||||
Point3::new(0.0, 0.0, 0.0),
|
||||
Vector3::y_axis(),
|
||||
Vector3::default(),
|
||||
point![pos.x, pos.y, pos.z],
|
||||
Vector::y_axis(),
|
||||
Vector::zeros(),
|
||||
Point::origin(),
|
||||
Vector::y_axis(),
|
||||
Vector::default(),
|
||||
);
|
||||
prismatic.configure_motor_model(rapier3d::dynamics::SpringModel::VelocityBased);
|
||||
let (stiffness, damping) = (0.05, 0.2);
|
||||
@@ -59,10 +57,10 @@ fn prismatic_repro(
|
||||
// put a small box under one of the wheels
|
||||
let gravel = bodies.insert(
|
||||
RigidBodyBuilder::new_dynamic()
|
||||
.translation(box_center.x + 1.0, box_center.y - 2.4, -1.0)
|
||||
.translation(vector![box_center.x + 1.0, box_center.y - 2.4, -1.0])
|
||||
.build(),
|
||||
);
|
||||
colliders.insert(
|
||||
colliders.insert_with_parent(
|
||||
ColliderBuilder::cuboid(0.5, 0.1, 0.5).build(),
|
||||
gravel,
|
||||
bodies,
|
||||
@@ -84,22 +82,22 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
prismatic_repro(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
&mut joints,
|
||||
Point3::new(0.0, 5.0, 0.0),
|
||||
point![0.0, 5.0, 0.0],
|
||||
);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Isometry3, Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -17,30 +15,30 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4)
|
||||
.friction(0.15)
|
||||
// .restitution(0.5)
|
||||
.build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Rolling ball
|
||||
*/
|
||||
let ball_rad = 0.1;
|
||||
let rb = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 0.2, 0.0)
|
||||
.linvel(10.0, 0.0, 0.0)
|
||||
.translation(vector![0.0, 0.2, 0.0])
|
||||
.linvel(vector![10.0, 0.0, 0.0])
|
||||
.build();
|
||||
let ball_handle = bodies.insert(rb);
|
||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
|
||||
colliders.insert(collider, ball_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ball_handle, &mut bodies);
|
||||
|
||||
let mut linvel = Vector3::zeros();
|
||||
let mut angvel = Vector3::zeros();
|
||||
let mut pos = Isometry3::identity();
|
||||
let mut linvel = Vector::zeros();
|
||||
let mut angvel = Vector::zeros();
|
||||
let mut pos = Isometry::identity();
|
||||
let mut step = 0;
|
||||
let snapped_frame = 51;
|
||||
|
||||
@@ -68,5 +66,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Isometry3, Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -17,30 +15,30 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size)
|
||||
.friction(0.15)
|
||||
// .restitution(0.5)
|
||||
.build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Rolling ball
|
||||
*/
|
||||
let ball_rad = 0.1;
|
||||
let rb = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 0.2, 0.0)
|
||||
.linvel(10.0, 0.0, 0.0)
|
||||
.translation(vector![0.0, 0.2, 0.0])
|
||||
.linvel(vector![10.0, 0.0, 0.0])
|
||||
.build();
|
||||
let ball_handle = bodies.insert(rb);
|
||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
|
||||
let ball_coll_handle = colliders.insert(collider, ball_handle, &mut bodies);
|
||||
let ball_coll_handle = colliders.insert_with_parent(collider, ball_handle, &mut bodies);
|
||||
|
||||
let mut linvel = Vector3::zeros();
|
||||
let mut angvel = Vector3::zeros();
|
||||
let mut pos = Isometry3::identity();
|
||||
let mut linvel = Vector::zeros();
|
||||
let mut angvel = Vector::zeros();
|
||||
let mut pos = Isometry::identity();
|
||||
let mut step = 0;
|
||||
let snapped_frame = 51;
|
||||
|
||||
@@ -90,7 +88,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shiftz - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = match j % 5 {
|
||||
@@ -103,7 +103,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
_ => ColliderBuilder::capsule_y(rad, rad).build(),
|
||||
};
|
||||
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,5 +114,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -13,31 +11,31 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Triangle ground.
|
||||
let vtx = [
|
||||
Point3::new(-10.0, 0.0, -10.0),
|
||||
Point3::new(10.0, 0.0, -10.0),
|
||||
Point3::new(0.0, 0.0, 10.0),
|
||||
point![-10.0, 0.0, -10.0],
|
||||
point![10.0, 0.0, -10.0],
|
||||
point![0.0, 0.0, 10.0],
|
||||
];
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, 0.0, 0.0)
|
||||
.translation(vector![0.0, 0.0, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::triangle(vtx[0], vtx[1], vtx[2]).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
// Dynamic box rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(1.1, 0.01, 0.0)
|
||||
.translation(vector![1.1, 0.01, 0.0])
|
||||
// .rotation(Vector3::new(0.8, 0.2, 0.1))
|
||||
.can_sleep(false)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(20.0, 0.1, 1.0).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -14,14 +12,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// Triangle ground.
|
||||
let width = 0.5;
|
||||
let vtx = vec![
|
||||
Point3::new(-width, 0.0, -width),
|
||||
Point3::new(width, 0.0, -width),
|
||||
Point3::new(width, 0.0, width),
|
||||
Point3::new(-width, 0.0, width),
|
||||
Point3::new(-width, -width, -width),
|
||||
Point3::new(width, -width, -width),
|
||||
Point3::new(width, -width, width),
|
||||
Point3::new(-width, -width, width),
|
||||
point![-width, 0.0, -width],
|
||||
point![width, 0.0, -width],
|
||||
point![width, 0.0, width],
|
||||
point![-width, 0.0, width],
|
||||
point![-width, -width, -width],
|
||||
point![width, -width, -width],
|
||||
point![width, -width, width],
|
||||
point![-width, -width, width],
|
||||
];
|
||||
let idx = vec![
|
||||
[0, 2, 1],
|
||||
@@ -40,25 +38,25 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Dynamic box rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 35.0, 0.0)
|
||||
.translation(vector![0.0, 35.0, 0.0])
|
||||
// .rotation(Vector3::new(0.8, 0.2, 0.1))
|
||||
.can_sleep(false)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.0).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, 0.0, 0.0)
|
||||
.translation(vector![0.0, 0.0, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::trimesh(vtx, idx).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
testbed.set_initial_body_color(handle, Point3::new(0.3, 0.3, 0.3));
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
testbed.set_initial_body_color(handle, [0.3, 0.3, 0.3]);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point3, Translation3, UnitQuaternion, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -31,7 +29,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let width = 1.0;
|
||||
let thickness = 0.1;
|
||||
|
||||
let colors = [Point3::new(0.7, 0.5, 0.9), Point3::new(0.6, 1.0, 0.6)];
|
||||
let colors = [[0.7, 0.5, 0.9], [0.6, 1.0, 0.6]];
|
||||
|
||||
let mut curr_angle = 0.0;
|
||||
let mut curr_rad = 10.0;
|
||||
@@ -50,16 +48,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let tilt = if nudged || i == num - 1 { 0.2 } else { 0.0 };
|
||||
|
||||
if skip == 0 {
|
||||
let rot = UnitQuaternion::new(Vector3::y() * curr_angle);
|
||||
let tilt = UnitQuaternion::new(rot * Vector3::z() * tilt);
|
||||
let rot = Rotation::new(Vector::y() * curr_angle);
|
||||
let tilt = Rotation::new(rot * Vector::z() * tilt);
|
||||
let position =
|
||||
Translation3::new(x * curr_rad, width * 2.0 + ground_height, z * curr_rad)
|
||||
Translation::new(x * curr_rad, width * 2.0 + ground_height, z * curr_rad)
|
||||
* tilt
|
||||
* rot;
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().position(position).build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(thickness, width * 2.0, width).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
testbed.set_initial_body_color(handle, colors[i % 2]);
|
||||
} else {
|
||||
skip -= 1;
|
||||
@@ -76,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
const MAX_NUMBER_OF_BODIES: usize = 400;
|
||||
@@ -18,16 +16,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 2.1; // 16.0;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
// Callback that will be executed on the main loop to handle proximities.
|
||||
testbed.add_callback(move |mut graphics, physics, _, run_state| {
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 10.0, 0.0)
|
||||
.translation(vector![0.0, 10.0, 0.0])
|
||||
.build();
|
||||
let handle = physics.bodies.insert(rigid_body);
|
||||
let collider = match run_state.timestep_id % 3 {
|
||||
@@ -38,7 +36,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
physics
|
||||
.colliders
|
||||
.insert(collider, handle, &mut physics.bodies);
|
||||
.insert_with_parent(collider, handle, &mut physics.bodies);
|
||||
|
||||
if let Some(graphics) = &mut graphics {
|
||||
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
||||
@@ -83,5 +81,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// .physics_state_mut()
|
||||
// .integration_parameters
|
||||
// .velocity_based_erp = 0.2;
|
||||
testbed.look_at(Point3::new(-30.0, 4.0, -30.0), Point3::new(0.0, 1.0, 0.0));
|
||||
testbed.look_at(point![-30.0, 4.0, -30.0], point![0.0, 1.0, 0.0]);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
extern crate nalgebra as na;
|
||||
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::harness::Harness;
|
||||
|
||||
pub fn init_world(harness: &mut Harness) {
|
||||
@@ -19,11 +16,11 @@ pub fn init_world(harness: &mut Harness) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -47,10 +44,12 @@ pub fn init_world(harness: &mut Harness) {
|
||||
let z = k as f32 * shift - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_y(rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use na::{ComplexField, DMatrix, Isometry3, Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
|
||||
use na::ComplexField;
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = Vector3::new(100.0, 1.0, 100.0);
|
||||
let ground_size = Vector::new(100.0, 1.0, 100.0);
|
||||
let nsubdivs = 20;
|
||||
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
@@ -34,7 +33,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::heightfield(heights, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -55,7 +54,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = match j % 6 {
|
||||
@@ -69,15 +70,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
_ => {
|
||||
let shapes = vec![
|
||||
(
|
||||
Isometry3::identity(),
|
||||
Isometry::identity(),
|
||||
SharedShape::cuboid(rad, rad / 2.0, rad / 2.0),
|
||||
),
|
||||
(
|
||||
Isometry3::translation(rad, 0.0, 0.0),
|
||||
Isometry::translation(rad, 0.0, 0.0),
|
||||
SharedShape::cuboid(rad / 2.0, rad, rad / 2.0),
|
||||
),
|
||||
(
|
||||
Isometry3::translation(-rad, 0.0, 0.0),
|
||||
Isometry::translation(-rad, 0.0, 0.0),
|
||||
SharedShape::cuboid(rad / 2.0, rad, rad / 2.0),
|
||||
),
|
||||
];
|
||||
@@ -86,7 +87,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
}
|
||||
};
|
||||
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,5 +96,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,49 +1,44 @@
|
||||
use na::{Isometry3, Point3, Unit, UnitQuaternion, Vector3};
|
||||
use rapier3d::dynamics::{
|
||||
BallJoint, FixedJoint, JointSet, PrismaticJoint, RevoluteJoint, RigidBodyBuilder,
|
||||
RigidBodyHandle, RigidBodySet, RigidBodyType,
|
||||
};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
fn create_prismatic_joints(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
joints: &mut JointSet,
|
||||
origin: Point3<f32>,
|
||||
origin: Point<f32>,
|
||||
num: usize,
|
||||
) {
|
||||
let rad = 0.4;
|
||||
let shift = 2.0;
|
||||
|
||||
let ground = RigidBodyBuilder::new_static()
|
||||
.translation(origin.x, origin.y, origin.z)
|
||||
.translation(vector![origin.x, origin.y, origin.z])
|
||||
.build();
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, curr_parent, bodies);
|
||||
colliders.insert_with_parent(collider, curr_parent, bodies);
|
||||
|
||||
for i in 0..num {
|
||||
let z = origin.z + (i + 1) as f32 * shift;
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(origin.x, origin.y, z)
|
||||
.translation(vector![origin.x, origin.y, z])
|
||||
.build();
|
||||
let curr_child = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, curr_child, bodies);
|
||||
colliders.insert_with_parent(collider, curr_child, bodies);
|
||||
|
||||
let axis = if i % 2 == 0 {
|
||||
Unit::new_normalize(Vector3::new(1.0, 1.0, 0.0))
|
||||
UnitVector::new_normalize(vector![1.0, 1.0, 0.0])
|
||||
} else {
|
||||
Unit::new_normalize(Vector3::new(-1.0, 1.0, 0.0))
|
||||
UnitVector::new_normalize(vector![-1.0, 1.0, 0.0])
|
||||
};
|
||||
|
||||
let z = Vector3::z();
|
||||
let z = Vector::z();
|
||||
let mut prism = PrismaticJoint::new(
|
||||
Point3::new(0.0, 0.0, 0.0),
|
||||
point![0.0, 0.0, 0.0],
|
||||
axis,
|
||||
z,
|
||||
Point3::new(0.0, 0.0, -shift),
|
||||
point![0.0, 0.0, -shift],
|
||||
axis,
|
||||
z,
|
||||
);
|
||||
@@ -61,40 +56,40 @@ fn create_actuated_prismatic_joints(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
joints: &mut JointSet,
|
||||
origin: Point3<f32>,
|
||||
origin: Point<f32>,
|
||||
num: usize,
|
||||
) {
|
||||
let rad = 0.4;
|
||||
let shift = 2.0;
|
||||
|
||||
let ground = RigidBodyBuilder::new_static()
|
||||
.translation(origin.x, origin.y, origin.z)
|
||||
.translation(vector![origin.x, origin.y, origin.z])
|
||||
.build();
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, curr_parent, bodies);
|
||||
colliders.insert_with_parent(collider, curr_parent, bodies);
|
||||
|
||||
for i in 0..num {
|
||||
let z = origin.z + (i + 1) as f32 * shift;
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(origin.x, origin.y, z)
|
||||
.translation(vector![origin.x, origin.y, z])
|
||||
.build();
|
||||
let curr_child = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, curr_child, bodies);
|
||||
colliders.insert_with_parent(collider, curr_child, bodies);
|
||||
|
||||
let axis = if i % 2 == 0 {
|
||||
Unit::new_normalize(Vector3::new(1.0, 1.0, 0.0))
|
||||
UnitVector::new_normalize(vector![1.0, 1.0, 0.0])
|
||||
} else {
|
||||
Unit::new_normalize(Vector3::new(-1.0, 1.0, 0.0))
|
||||
UnitVector::new_normalize(vector![-1.0, 1.0, 0.0])
|
||||
};
|
||||
|
||||
let z = Vector3::z();
|
||||
let z = Vector::z();
|
||||
let mut prism = PrismaticJoint::new(
|
||||
Point3::new(0.0, 0.0, 0.0),
|
||||
point![0.0, 0.0, 0.0],
|
||||
axis,
|
||||
z,
|
||||
Point3::new(0.0, 0.0, -shift),
|
||||
point![0.0, 0.0, -shift],
|
||||
axis,
|
||||
z,
|
||||
);
|
||||
@@ -128,27 +123,27 @@ fn create_revolute_joints(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
joints: &mut JointSet,
|
||||
origin: Point3<f32>,
|
||||
origin: Point<f32>,
|
||||
num: usize,
|
||||
) {
|
||||
let rad = 0.4;
|
||||
let shift = 2.0;
|
||||
|
||||
let ground = RigidBodyBuilder::new_static()
|
||||
.translation(origin.x, origin.y, 0.0)
|
||||
.translation(vector![origin.x, origin.y, 0.0])
|
||||
.build();
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, curr_parent, bodies);
|
||||
colliders.insert_with_parent(collider, curr_parent, bodies);
|
||||
|
||||
for i in 0..num {
|
||||
// Create four bodies.
|
||||
let z = origin.z + i as f32 * shift * 2.0 + shift;
|
||||
let positions = [
|
||||
Isometry3::translation(origin.x, origin.y, z),
|
||||
Isometry3::translation(origin.x + shift, origin.y, z),
|
||||
Isometry3::translation(origin.x + shift, origin.y, z + shift),
|
||||
Isometry3::translation(origin.x, origin.y, z + shift),
|
||||
Isometry::translation(origin.x, origin.y, z),
|
||||
Isometry::translation(origin.x + shift, origin.y, z),
|
||||
Isometry::translation(origin.x + shift, origin.y, z + shift),
|
||||
Isometry::translation(origin.x, origin.y, z + shift),
|
||||
];
|
||||
|
||||
let mut handles = [curr_parent; 4];
|
||||
@@ -158,19 +153,19 @@ fn create_revolute_joints(
|
||||
.build();
|
||||
handles[k] = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, handles[k], bodies);
|
||||
colliders.insert_with_parent(collider, handles[k], bodies);
|
||||
}
|
||||
|
||||
// Setup four joints.
|
||||
let o = Point3::origin();
|
||||
let x = Vector3::x_axis();
|
||||
let z = Vector3::z_axis();
|
||||
let o = Point::origin();
|
||||
let x = Vector::x_axis();
|
||||
let z = Vector::z_axis();
|
||||
|
||||
let revs = [
|
||||
RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z),
|
||||
RevoluteJoint::new(o, x, Point3::new(-shift, 0.0, 0.0), x),
|
||||
RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z),
|
||||
RevoluteJoint::new(o, x, Point3::new(shift, 0.0, 0.0), x),
|
||||
RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z),
|
||||
RevoluteJoint::new(o, x, point![-shift, 0.0, 0.0], x),
|
||||
RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z),
|
||||
RevoluteJoint::new(o, x, point![shift, 0.0, 0.0], x),
|
||||
];
|
||||
|
||||
joints.insert(bodies, curr_parent, handles[0], revs[0]);
|
||||
@@ -186,7 +181,7 @@ fn create_fixed_joints(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
joints: &mut JointSet,
|
||||
origin: Point3<f32>,
|
||||
origin: Point<f32>,
|
||||
num: usize,
|
||||
) {
|
||||
let rad = 0.4;
|
||||
@@ -209,18 +204,22 @@ fn create_fixed_joints(
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(origin.x + fk * shift, origin.y, origin.z + fi * shift)
|
||||
.translation(vector![
|
||||
origin.x + fk * shift,
|
||||
origin.y,
|
||||
origin.z + fi * shift
|
||||
])
|
||||
.build();
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).build();
|
||||
colliders.insert(collider, child_handle, bodies);
|
||||
colliders.insert_with_parent(collider, child_handle, bodies);
|
||||
|
||||
// Vertical joint.
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint = FixedJoint::new(
|
||||
Isometry3::identity(),
|
||||
Isometry3::translation(0.0, 0.0, -shift),
|
||||
Isometry::identity(),
|
||||
Isometry::translation(0.0, 0.0, -shift),
|
||||
);
|
||||
joints.insert(bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
@@ -230,8 +229,8 @@ fn create_fixed_joints(
|
||||
let parent_index = body_handles.len() - num;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = FixedJoint::new(
|
||||
Isometry3::identity(),
|
||||
Isometry3::translation(-shift, 0.0, 0.0),
|
||||
Isometry::identity(),
|
||||
Isometry::translation(-shift, 0.0, 0.0),
|
||||
);
|
||||
joints.insert(bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
@@ -264,16 +263,16 @@ fn create_ball_joints(
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(fk * shift, 0.0, fi * shift * 2.0)
|
||||
.translation(vector![fk * shift, 0.0, fi * shift * 2.0])
|
||||
.build();
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_z(rad * 1.25, rad).build();
|
||||
colliders.insert(collider, child_handle, bodies);
|
||||
colliders.insert_with_parent(collider, child_handle, bodies);
|
||||
|
||||
// Vertical joint.
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint = BallJoint::new(Point3::origin(), Point3::new(0.0, 0.0, -shift * 2.0));
|
||||
let joint = BallJoint::new(Point::origin(), point![0.0, 0.0, -shift * 2.0]);
|
||||
joints.insert(bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
|
||||
@@ -281,7 +280,7 @@ fn create_ball_joints(
|
||||
if k > 0 {
|
||||
let parent_index = body_handles.len() - num;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = BallJoint::new(Point3::origin(), Point3::new(-shift, 0.0, 0.0));
|
||||
let joint = BallJoint::new(Point::origin(), point![-shift, 0.0, 0.0]);
|
||||
joints.insert(bodies, parent_handle, child_handle, joint);
|
||||
}
|
||||
|
||||
@@ -294,7 +293,7 @@ fn create_actuated_revolute_joints(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
joints: &mut JointSet,
|
||||
origin: Point3<f32>,
|
||||
origin: Point<f32>,
|
||||
num: usize,
|
||||
) {
|
||||
let rad = 0.4;
|
||||
@@ -302,10 +301,10 @@ fn create_actuated_revolute_joints(
|
||||
|
||||
// We will reuse this base configuration for all the joints here.
|
||||
let joint_template = RevoluteJoint::new(
|
||||
Point3::origin(),
|
||||
Vector3::z_axis(),
|
||||
Point3::new(0.0, 0.0, -shift),
|
||||
Vector3::z_axis(),
|
||||
Point::origin(),
|
||||
Vector::z_axis(),
|
||||
point![0.0, 0.0, -shift],
|
||||
Vector::z_axis(),
|
||||
);
|
||||
|
||||
let mut parent_handle = RigidBodyHandle::invalid();
|
||||
@@ -325,13 +324,13 @@ fn create_actuated_revolute_joints(
|
||||
let shifty = (i >= 1) as u32 as f32 * -2.0;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(origin.x, origin.y + shifty, origin.z + fi * shift)
|
||||
.translation(vector![origin.x, origin.y + shifty, origin.z + fi * shift])
|
||||
// .rotation(Vector3::new(0.0, fi * 1.1, 0.0))
|
||||
.build();
|
||||
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad * 2.0, rad * 6.0 / (fi + 1.0), rad).build();
|
||||
colliders.insert(collider, child_handle, bodies);
|
||||
colliders.insert_with_parent(collider, child_handle, bodies);
|
||||
|
||||
if i > 0 {
|
||||
let mut joint = joint_template.clone();
|
||||
@@ -360,14 +359,14 @@ fn create_actuated_ball_joints(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
joints: &mut JointSet,
|
||||
origin: Point3<f32>,
|
||||
origin: Point<f32>,
|
||||
num: usize,
|
||||
) {
|
||||
let rad = 0.4;
|
||||
let shift = 2.0;
|
||||
|
||||
// We will reuse this base configuration for all the joints here.
|
||||
let joint_template = BallJoint::new(Point3::new(0.0, 0.0, shift), Point3::origin());
|
||||
let joint_template = BallJoint::new(point![0.0, 0.0, shift], Point::origin());
|
||||
|
||||
let mut parent_handle = RigidBodyHandle::invalid();
|
||||
|
||||
@@ -384,24 +383,24 @@ fn create_actuated_ball_joints(
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(origin.x, origin.y, origin.z + fi * shift)
|
||||
.translation(vector![origin.x, origin.y, origin.z + fi * shift])
|
||||
// .rotation(Vector3::new(0.0, fi * 1.1, 0.0))
|
||||
.build();
|
||||
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_y(rad * 2.0 / (fi + 1.0), rad).build();
|
||||
colliders.insert(collider, child_handle, bodies);
|
||||
colliders.insert_with_parent(collider, child_handle, bodies);
|
||||
|
||||
if i > 0 {
|
||||
let mut joint = joint_template.clone();
|
||||
|
||||
if i == 1 {
|
||||
joint.configure_motor_velocity(Vector3::new(0.0, 0.5, -2.0), 0.1);
|
||||
joint.configure_motor_velocity(vector![0.0, 0.5, -2.0], 0.1);
|
||||
} else if i == num - 1 {
|
||||
let stiffness = 0.2;
|
||||
let damping = 1.0;
|
||||
joint.configure_motor_position(
|
||||
UnitQuaternion::new(Vector3::new(0.0, 1.0, 3.14 / 2.0)),
|
||||
Rotation::new(vector![0.0, 1.0, 3.14 / 2.0]),
|
||||
stiffness,
|
||||
damping,
|
||||
);
|
||||
@@ -426,42 +425,42 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
&mut joints,
|
||||
Point3::new(20.0, 5.0, 0.0),
|
||||
point![20.0, 5.0, 0.0],
|
||||
4,
|
||||
);
|
||||
create_actuated_prismatic_joints(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
&mut joints,
|
||||
Point3::new(25.0, 5.0, 0.0),
|
||||
point![25.0, 5.0, 0.0],
|
||||
4,
|
||||
);
|
||||
create_revolute_joints(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
&mut joints,
|
||||
Point3::new(20.0, 0.0, 0.0),
|
||||
point![20.0, 0.0, 0.0],
|
||||
3,
|
||||
);
|
||||
create_fixed_joints(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
&mut joints,
|
||||
Point3::new(0.0, 10.0, 0.0),
|
||||
point![0.0, 10.0, 0.0],
|
||||
10,
|
||||
);
|
||||
create_actuated_revolute_joints(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
&mut joints,
|
||||
Point3::new(20.0, 10.0, 0.0),
|
||||
point![20.0, 10.0, 0.0],
|
||||
6,
|
||||
);
|
||||
create_actuated_ball_joints(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
&mut joints,
|
||||
Point3::new(13.0, 10.0, 0.0),
|
||||
point![13.0, 10.0, 0.0],
|
||||
3,
|
||||
);
|
||||
create_ball_joints(&mut bodies, &mut colliders, &mut joints, 15);
|
||||
@@ -470,5 +469,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(15.0, 5.0, 42.0), Point3::new(13.0, 1.0, 1.0));
|
||||
testbed.look_at(point![15.0, 5.0, 42.0], point![13.0, 1.0, 1.0]);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn build_block(
|
||||
testbed: &mut Testbed,
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
half_extents: Vector3<f32>,
|
||||
shift: Vector3<f32>,
|
||||
half_extents: Vector<f32>,
|
||||
shift: Vector<f32>,
|
||||
mut numx: usize,
|
||||
numy: usize,
|
||||
mut numz: usize,
|
||||
@@ -17,8 +15,8 @@ pub fn build_block(
|
||||
let block_width = 2.0 * half_extents.z * numx as f32;
|
||||
let block_height = 2.0 * half_extents.y * numy as f32;
|
||||
let spacing = (half_extents.z * numx as f32 - half_extents.x) / (numz as f32 - 1.0);
|
||||
let mut color0 = Point3::new(0.7, 0.5, 0.9);
|
||||
let mut color1 = Point3::new(0.6, 1.0, 0.6);
|
||||
let mut color0 = [0.7, 0.5, 0.9];
|
||||
let mut color1 = [0.6, 1.0, 0.6];
|
||||
|
||||
for i in 0..numy {
|
||||
std::mem::swap(&mut numx, &mut numz);
|
||||
@@ -41,15 +39,15 @@ pub fn build_block(
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(
|
||||
.translation(vector![
|
||||
x + dim.x + shift.x,
|
||||
y + dim.y + shift.y,
|
||||
z + dim.z + shift.z,
|
||||
)
|
||||
z + dim.z + shift.z
|
||||
])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
|
||||
colliders.insert(collider, handle, bodies);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
|
||||
testbed.set_initial_body_color(handle, color0);
|
||||
std::mem::swap(&mut color0, &mut color1);
|
||||
@@ -64,15 +62,15 @@ pub fn build_block(
|
||||
for j in 0..(block_width / (dim.z as f32 * 2.0)) as usize {
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(
|
||||
.translation(vector![
|
||||
i as f32 * dim.x * 2.0 + dim.x + shift.x,
|
||||
dim.y + shift.y + block_height,
|
||||
j as f32 * dim.z * 2.0 + dim.z + shift.z,
|
||||
)
|
||||
j as f32 * dim.z * 2.0 + dim.z + shift.z
|
||||
])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
|
||||
colliders.insert(collider, handle, bodies);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
testbed.set_initial_body_color(handle, color0);
|
||||
std::mem::swap(&mut color0, &mut color1);
|
||||
}
|
||||
@@ -94,16 +92,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let half_extents = Vector3::new(0.02, 0.1, 0.4) / 2.0 * 10.0;
|
||||
let half_extents = vector![0.02, 0.1, 0.4] / 2.0 * 10.0;
|
||||
let mut block_height = 0.0;
|
||||
// These should only be set to odd values otherwise
|
||||
// the blocks won't align in the nicest way.
|
||||
@@ -120,7 +118,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
half_extents,
|
||||
Vector3::new(-block_width / 2.0, block_height, -block_width / 2.0),
|
||||
vector![-block_width / 2.0, block_height, -block_width / 2.0],
|
||||
numx,
|
||||
numy,
|
||||
numz,
|
||||
@@ -135,5 +133,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
// This shows a bug when a cylinder is in contact with a very large
|
||||
@@ -21,41 +19,41 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* A rectangle that only rotates along the `x` axis.
|
||||
*/
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 3.0, 0.0)
|
||||
.translation(vector![0.0, 3.0, 0.0])
|
||||
.lock_translations()
|
||||
.restrict_rotations(true, false, false)
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(0.2, 0.6, 2.0).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* A tilted capsule that cannot rotate.
|
||||
*/
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 5.0, 0.0)
|
||||
.rotation(Vector3::x() * 1.0)
|
||||
.translation(vector![0.0, 5.0, 0.0])
|
||||
.rotation(Vector::x() * 1.0)
|
||||
.lock_rotations()
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_y(0.6, 0.4).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
let collider = ColliderBuilder::capsule_x(0.6, 0.4).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(10.0, 3.0, 0.0), Point3::new(0.0, 3.0, 0.0));
|
||||
testbed.look_at(point![10.0, 3.0, 0.0], point![0.0, 3.0, 0.0]);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
use na::{Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderHandle, ColliderSet};
|
||||
use rapier3d::pipeline::{ContactModificationContext, PhysicsHooks, PhysicsHooksFlags};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
struct OneWayPlatformHook {
|
||||
@@ -10,10 +7,6 @@ struct OneWayPlatformHook {
|
||||
}
|
||||
|
||||
impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
|
||||
fn active_hooks(&self) -> PhysicsHooksFlags {
|
||||
PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS
|
||||
}
|
||||
|
||||
fn modify_solver_contacts(
|
||||
&self,
|
||||
context: &mut ContactModificationContext<RigidBodySet, ColliderSet>,
|
||||
@@ -30,20 +23,20 @@ impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
|
||||
// - If context.collider2 == self.platform1 then the allowed normal is -y.
|
||||
// - If context.collider1 == self.platform2 then its allowed normal +y needs to be flipped to -y.
|
||||
// - If context.collider2 == self.platform2 then the allowed normal -y needs to be flipped to +y.
|
||||
let mut allowed_local_n1 = Vector3::zeros();
|
||||
let mut allowed_local_n1 = Vector::zeros();
|
||||
|
||||
if context.collider1 == self.platform1 {
|
||||
allowed_local_n1 = Vector3::y();
|
||||
allowed_local_n1 = Vector::y();
|
||||
} else if context.collider2 == self.platform1 {
|
||||
// Flip the allowed direction.
|
||||
allowed_local_n1 = -Vector3::y();
|
||||
allowed_local_n1 = -Vector::y();
|
||||
}
|
||||
|
||||
if context.collider1 == self.platform2 {
|
||||
allowed_local_n1 = -Vector3::y();
|
||||
allowed_local_n1 = -Vector::y();
|
||||
} else if context.collider2 == self.platform2 {
|
||||
// Flip the allowed direction.
|
||||
allowed_local_n1 = Vector3::y();
|
||||
allowed_local_n1 = Vector::y();
|
||||
}
|
||||
|
||||
// Call the helper function that simulates one-way platforms.
|
||||
@@ -78,15 +71,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0)
|
||||
.translation(0.0, 2.0, 30.0)
|
||||
.modify_solver_contacts(true)
|
||||
.translation(vector![0.0, 2.0, 30.0])
|
||||
.active_hooks(ActiveHooks::MODIFY_SOLVER_CONTACTS)
|
||||
.build();
|
||||
let platform1 = colliders.insert(collider, handle, &mut bodies);
|
||||
let platform1 = colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0)
|
||||
.translation(0.0, -2.0, -30.0)
|
||||
.modify_solver_contacts(true)
|
||||
.translation(vector![0.0, -2.0, -30.0])
|
||||
.active_hooks(ActiveHooks::MODIFY_SOLVER_CONTACTS)
|
||||
.build();
|
||||
let platform2 = colliders.insert(collider, handle, &mut bodies);
|
||||
let platform2 = colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Setup the one-way platform hook.
|
||||
@@ -105,12 +98,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// Spawn a new cube.
|
||||
let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.5).build();
|
||||
let body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 6.0, 20.0)
|
||||
.translation(vector![0.0, 6.0, 20.0])
|
||||
.build();
|
||||
let handle = physics.bodies.insert(body);
|
||||
physics
|
||||
.colliders
|
||||
.insert(collider, handle, &mut physics.bodies);
|
||||
.insert_with_parent(collider, handle, &mut physics.bodies);
|
||||
|
||||
if let Some(graphics) = graphics {
|
||||
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
||||
@@ -134,8 +127,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
bodies,
|
||||
colliders,
|
||||
joints,
|
||||
Vector3::new(0.0, -9.81, 0.0),
|
||||
vector![0.0, -9.81, 0.0],
|
||||
physics_hooks,
|
||||
);
|
||||
testbed.look_at(Point3::new(-100.0, 0.0, 0.0), Point3::origin());
|
||||
testbed.look_at(point![-100.0, 0.0, 0.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the boxes
|
||||
@@ -43,23 +41,35 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup a kinematic rigid body.
|
||||
* Setup a velocity-based kinematic rigid body.
|
||||
*/
|
||||
let platform_body = RigidBodyBuilder::new_kinematic()
|
||||
.translation(0.0, 1.5 + 0.8, -10.0 * rad)
|
||||
let platform_body = RigidBodyBuilder::new_kinematic_velocity_based()
|
||||
.translation(vector![0.0, 1.5 + 0.8, -10.0 * rad])
|
||||
.build();
|
||||
let platform_handle = bodies.insert(platform_body);
|
||||
let velocity_based_platform_handle = bodies.insert(platform_body);
|
||||
let collider = ColliderBuilder::cuboid(rad * 10.0, rad, rad * 10.0).build();
|
||||
colliders.insert(collider, platform_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, velocity_based_platform_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Setup a position-based kinematic rigid body.
|
||||
*/
|
||||
let platform_body = RigidBodyBuilder::new_kinematic_position_based()
|
||||
.translation(vector![0.0, 2.0 + 1.5 + 0.8, -10.0 * rad])
|
||||
.build();
|
||||
let position_based_platform_handle = bodies.insert(platform_body);
|
||||
let collider = ColliderBuilder::cuboid(rad * 10.0, rad, rad * 10.0).build();
|
||||
colliders.insert_with_parent(collider, position_based_platform_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Setup a callback to control the platform.
|
||||
@@ -71,21 +81,22 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(platform) = physics.bodies.get_mut(platform_handle) {
|
||||
let mut next_pos = *platform.position();
|
||||
let velocity = vector![
|
||||
0.0,
|
||||
(run_state.time * 5.0).sin(),
|
||||
run_state.time.sin() * 5.0
|
||||
];
|
||||
|
||||
let dt = 0.016;
|
||||
next_pos.translation.vector.y += (run_state.time * 5.0).sin() * dt;
|
||||
next_pos.translation.vector.z += run_state.time.sin() * 5.0 * dt;
|
||||
// Update the velocity-based kinematic body by setting its velocity.
|
||||
if let Some(platform) = physics.bodies.get_mut(velocity_based_platform_handle) {
|
||||
platform.set_linvel(velocity, true);
|
||||
}
|
||||
|
||||
if next_pos.translation.vector.z >= rad * 10.0 {
|
||||
next_pos.translation.vector.z -= dt;
|
||||
}
|
||||
if next_pos.translation.vector.z <= -rad * 10.0 {
|
||||
next_pos.translation.vector.z += dt;
|
||||
}
|
||||
|
||||
platform.set_next_kinematic_position(next_pos);
|
||||
// Update the position-based kinematic body by setting its next position.
|
||||
if let Some(platform) = physics.bodies.get_mut(position_based_platform_handle) {
|
||||
let mut next_tra = *platform.translation();
|
||||
next_tra += velocity * physics.integration_parameters.dt;
|
||||
platform.set_next_kinematic_translation(next_tra);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -93,5 +104,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Run the simulation.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(-10.0, 5.0, -10.0), Point3::origin());
|
||||
testbed.look_at(point![-10.0, 5.0, -10.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 2.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the primitives
|
||||
@@ -47,7 +45,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shiftz - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = match j % 5 {
|
||||
@@ -60,7 +60,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
_ => ColliderBuilder::capsule_y(rad, rad).build(),
|
||||
};
|
||||
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,5 +71,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,13 +16,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 1.0;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 2.0)
|
||||
.restitution(1.0)
|
||||
.build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let num = 10;
|
||||
let rad = 0.5;
|
||||
@@ -33,13 +31,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
for i in 0..=num {
|
||||
let x = (i as f32) - num as f32 / 2.0;
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(x * 2.0, 10.0 * (j as f32 + 1.0), 0.0)
|
||||
.translation(vector![x * 2.0, 10.0 * (j as f32 + 1.0), 0.0])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad)
|
||||
.restitution((i as f32) / (num as f32))
|
||||
.build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,5 +45,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(0.0, 3.0, 30.0), Point3::new(0.0, 3.0, 0.0));
|
||||
testbed.look_at(point![0.0, 3.0, 30.0], point![0.0, 3.0, 0.0]);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use na::Point3;
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -18,11 +16,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static()
|
||||
.translation(0.0, -ground_height, 0.0)
|
||||
.translation(vector![0.0, -ground_height, 0.0])
|
||||
.build();
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
||||
colliders.insert(collider, ground_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create some boxes.
|
||||
@@ -41,12 +39,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_body_color(handle, Point3::new(0.5, 0.5, 1.0));
|
||||
testbed.set_initial_body_color(handle, [0.5, 0.5, 1.0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,33 +56,37 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Rigid body so that the sensor can move.
|
||||
let sensor = RigidBodyBuilder::new_dynamic()
|
||||
.translation(0.0, 5.0, 0.0)
|
||||
.translation(vector![0.0, 5.0, 0.0])
|
||||
.build();
|
||||
let sensor_handle = bodies.insert(sensor);
|
||||
|
||||
// Solid cube attached to the sensor which
|
||||
// other colliders can touch.
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||
colliders.insert(collider, sensor_handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, sensor_handle, &mut bodies);
|
||||
|
||||
// We create a collider desc without density because we don't
|
||||
// want it to contribute to the rigid body mass.
|
||||
let sensor_collider = ColliderBuilder::ball(rad * 5.0).sensor(true).build();
|
||||
colliders.insert(sensor_collider, sensor_handle, &mut bodies);
|
||||
let sensor_collider = ColliderBuilder::ball(rad * 5.0)
|
||||
.density(0.0)
|
||||
.sensor(true)
|
||||
.active_events(ActiveEvents::INTERSECTION_EVENTS)
|
||||
.build();
|
||||
colliders.insert_with_parent(sensor_collider, sensor_handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_body_color(sensor_handle, Point3::new(0.5, 1.0, 1.0));
|
||||
testbed.set_initial_body_color(sensor_handle, [0.5, 1.0, 1.0]);
|
||||
|
||||
// Callback that will be executed on the main loop to handle proximities.
|
||||
testbed.add_callback(move |mut graphics, physics, events, _| {
|
||||
while let Ok(prox) = events.intersection_events.try_recv() {
|
||||
let color = if prox.intersecting {
|
||||
Point3::new(1.0, 1.0, 0.0)
|
||||
[1.0, 1.0, 0.0]
|
||||
} else {
|
||||
Point3::new(0.5, 0.5, 1.0)
|
||||
[0.5, 0.5, 1.0]
|
||||
};
|
||||
|
||||
let parent_handle1 = physics.colliders.get(prox.collider1).unwrap().parent();
|
||||
let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
|
||||
let parent_handle1 = physics.colliders[prox.collider1].parent().unwrap();
|
||||
let parent_handle2 = physics.colliders[prox.collider2].parent().unwrap();
|
||||
|
||||
if let Some(graphics) = &mut graphics {
|
||||
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
||||
@@ -99,5 +103,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(-6.0, 4.0, -6.0), Point3::new(0.0, 1.0, 0.0));
|
||||
testbed.look_at(point![-6.0, 4.0, -6.0], point![0.0, 1.0, 0.0]);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use na::{ComplexField, DMatrix, Isometry3, Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, HeightField, SharedShape};
|
||||
use na::ComplexField;
|
||||
use rapier3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = Vector3::new(100.0, 1.0, 100.0);
|
||||
let ground_size = vector![100.0, 1.0, 100.0];
|
||||
let nsubdivs = 20;
|
||||
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
@@ -39,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::trimesh(vertices, indices).build();
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -60,7 +59,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic().translation(x, y, z).build();
|
||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||
.translation(vector![x, y, z])
|
||||
.build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = match j % 6 {
|
||||
@@ -74,15 +75,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
_ => {
|
||||
let shapes = vec![
|
||||
(
|
||||
Isometry3::identity(),
|
||||
Isometry::identity(),
|
||||
SharedShape::cuboid(rad, rad / 2.0, rad / 2.0),
|
||||
),
|
||||
(
|
||||
Isometry3::translation(rad, 0.0, 0.0),
|
||||
Isometry::translation(rad, 0.0, 0.0),
|
||||
SharedShape::cuboid(rad / 2.0, rad, rad / 2.0),
|
||||
),
|
||||
(
|
||||
Isometry3::translation(-rad, 0.0, 0.0),
|
||||
Isometry::translation(-rad, 0.0, 0.0),
|
||||
SharedShape::cuboid(rad / 2.0, rad, rad / 2.0),
|
||||
),
|
||||
];
|
||||
@@ -91,7 +92,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
}
|
||||
};
|
||||
|
||||
colliders.insert(collider, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,5 +101,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, joints);
|
||||
testbed.look_at(Point3::new(100.0, 100.0, 100.0), Point3::origin());
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
}
|
||||
|
||||
35
publish.sh
Executable file
35
publish.sh
Executable file
@@ -0,0 +1,35 @@
|
||||
#! /bin/bash
|
||||
|
||||
tmp=$(mktemp -d)
|
||||
|
||||
echo "$tmp"
|
||||
|
||||
cp -r src "$tmp"/.
|
||||
cp -r LICENSE README.md "$tmp"/.
|
||||
|
||||
### Publish the 2D version.
|
||||
sed 's#\.\./\.\./src#src#g' build/rapier2d/Cargo.toml > "$tmp"/Cargo.toml
|
||||
currdir=$(pwd)
|
||||
cd "$tmp" && cargo publish
|
||||
cd "$currdir" || exit
|
||||
|
||||
|
||||
### Publish the 3D version.
|
||||
sed 's#\.\./\.\./src#src#g' build/rapier3d/Cargo.toml > "$tmp"/Cargo.toml
|
||||
cp -r LICENSE README.md "$tmp"/.
|
||||
cd "$tmp" && cargo publish
|
||||
cd "$currdir" || exit
|
||||
|
||||
### Publish the 2D f64 version.
|
||||
sed 's#\.\./\.\./src#src#g' build/rapier2d-f64/Cargo.toml > "$tmp"/Cargo.toml
|
||||
currdir=$(pwd)
|
||||
cd "$tmp" && cargo publish
|
||||
cd "$currdir" || exit
|
||||
|
||||
|
||||
### Publish the 3D f64 version.
|
||||
sed 's#\.\./\.\./src#src#g' build/rapier3d-f64/Cargo.toml > "$tmp"/Cargo.toml
|
||||
cp -r LICENSE README.md "$tmp"/.
|
||||
cd "$tmp" && cargo publish
|
||||
|
||||
rm -rf "$tmp"
|
||||
@@ -13,6 +13,14 @@ impl<T> Coarena<T> {
|
||||
Self { data: Vec::new() }
|
||||
}
|
||||
|
||||
/// Gets a specific element from the coarena without specifying its generation number.
|
||||
///
|
||||
/// It is strongly encouraged to use `Coarena::get` instead of this method because this method
|
||||
/// can suffer from the ABA problem.
|
||||
pub fn get_unknown_gen(&self, index: u32) -> Option<&T> {
|
||||
self.data.get(index as usize).map(|(_, t)| t)
|
||||
}
|
||||
|
||||
/// Gets a specific element from the coarena, if it exists.
|
||||
pub fn get(&self, index: Index) -> Option<&T> {
|
||||
let (i, g) = index.into_raw_parts();
|
||||
|
||||
@@ -10,6 +10,7 @@ use crate::geometry::{
|
||||
use crate::math::Real;
|
||||
use crate::parry::utils::SortedPair;
|
||||
use crate::pipeline::{EventHandler, QueryPipeline, QueryPipelineMode};
|
||||
use crate::prelude::{ActiveEvents, ColliderFlags};
|
||||
use parry::query::{DefaultQueryDispatcher, QueryDispatcher};
|
||||
use parry::utils::hashmap::HashMap;
|
||||
use std::collections::BinaryHeap;
|
||||
@@ -66,7 +67,7 @@ impl CCDSolver {
|
||||
&RigidBodyCcd,
|
||||
&RigidBodyMassProps,
|
||||
) = bodies.index_bundle(handle.0);
|
||||
let local_com = &mprops.mass_properties.local_com;
|
||||
let local_com = &mprops.local_mprops.local_com;
|
||||
|
||||
let min_toi = (ccd.ccd_thickness
|
||||
* 0.15
|
||||
@@ -139,7 +140,8 @@ impl CCDSolver {
|
||||
Colliders: ComponentSetOption<ColliderParent>
|
||||
+ ComponentSet<ColliderPosition>
|
||||
+ ComponentSet<ColliderShape>
|
||||
+ ComponentSet<ColliderType>,
|
||||
+ ComponentSet<ColliderType>
|
||||
+ ComponentSet<ColliderFlags>,
|
||||
{
|
||||
// Update the query pipeline.
|
||||
self.query_pipeline.update_with_mode(
|
||||
@@ -200,16 +202,21 @@ impl CCDSolver {
|
||||
{
|
||||
let co_parent1: Option<&ColliderParent> = colliders.get(ch1.0);
|
||||
let co_parent2: Option<&ColliderParent> = colliders.get(ch2.0);
|
||||
let c1: (_, _, _) = colliders.index_bundle(ch1.0);
|
||||
let c2: (_, _, _) = colliders.index_bundle(ch2.0);
|
||||
let c1: (_, _, _, &ColliderFlags) = colliders.index_bundle(ch1.0);
|
||||
let c2: (_, _, _, &ColliderFlags) = colliders.index_bundle(ch2.0);
|
||||
let co_type1: &ColliderType = colliders.index(ch1.0);
|
||||
let co_type2: &ColliderType = colliders.index(ch1.0);
|
||||
|
||||
let bh1 = co_parent1.map(|p| p.handle);
|
||||
let bh2 = co_parent2.map(|p| p.handle);
|
||||
|
||||
if bh1 == bh2 || (co_type1.is_sensor() || co_type2.is_sensor()) {
|
||||
// Ignore self-intersection and sensors.
|
||||
// Ignore self-intersection and sensors and apply collision groups filter.
|
||||
if bh1 == bh2 // Ignore self-intersection.
|
||||
|| (co_type1.is_sensor() || co_type2.is_sensor()) // Ignore sensors.
|
||||
|| !c1.3.collision_groups.test(c2.3.collision_groups) // Apply collision groups.
|
||||
|| !c1.3.solver_groups.test(c2.3.solver_groups)
|
||||
// Apply solver groups.
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -225,8 +232,8 @@ impl CCDSolver {
|
||||
self.query_pipeline.query_dispatcher(),
|
||||
*ch1,
|
||||
*ch2,
|
||||
(c1.0, c1.1, c1.2, co_parent1),
|
||||
(c2.0, c2.1, c2.2, co_parent2),
|
||||
(c1.0, c1.1, c1.2, c1.3, co_parent1),
|
||||
(c2.0, c2.1, c2.2, c2.3, co_parent2),
|
||||
Some((rb_pos1, rb_vels1, rb_mprops1, rb_ccd1)),
|
||||
b2,
|
||||
None,
|
||||
@@ -272,7 +279,9 @@ impl CCDSolver {
|
||||
Colliders: ComponentSetOption<ColliderParent>
|
||||
+ ComponentSet<ColliderPosition>
|
||||
+ ComponentSet<ColliderShape>
|
||||
+ ComponentSet<ColliderType>,
|
||||
+ ComponentSet<ColliderType>
|
||||
+ ComponentSet<ColliderFlags>
|
||||
+ ComponentSet<ColliderFlags>,
|
||||
{
|
||||
let mut frozen = HashMap::<_, Real>::default();
|
||||
let mut all_toi = BinaryHeap::new();
|
||||
@@ -334,14 +343,15 @@ impl CCDSolver {
|
||||
{
|
||||
let co_parent1: Option<&ColliderParent> = colliders.get(ch1.0);
|
||||
let co_parent2: Option<&ColliderParent> = colliders.get(ch2.0);
|
||||
let c1: (_, _, _) = colliders.index_bundle(ch1.0);
|
||||
let c2: (_, _, _) = colliders.index_bundle(ch2.0);
|
||||
let c1: (_, _, _, &ColliderFlags) = colliders.index_bundle(ch1.0);
|
||||
let c2: (_, _, _, &ColliderFlags) = colliders.index_bundle(ch2.0);
|
||||
|
||||
let bh1 = co_parent1.map(|p| p.handle);
|
||||
let bh2 = co_parent2.map(|p| p.handle);
|
||||
|
||||
if bh1 == bh2 {
|
||||
// Ignore self-intersection.
|
||||
// Ignore self-intersections and apply groups filter.
|
||||
if bh1 == bh2 || !c1.3.collision_groups.test(c2.3.collision_groups)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -358,8 +368,8 @@ impl CCDSolver {
|
||||
self.query_pipeline.query_dispatcher(),
|
||||
*ch1,
|
||||
*ch2,
|
||||
(c1.0, c1.1, c1.2, co_parent1),
|
||||
(c2.0, c2.1, c2.2, co_parent2),
|
||||
(c1.0, c1.1, c1.2, c1.3, co_parent1),
|
||||
(c2.0, c2.1, c2.2, c2.3, co_parent2),
|
||||
b1,
|
||||
b2,
|
||||
None,
|
||||
@@ -398,7 +408,7 @@ impl CCDSolver {
|
||||
|
||||
// NOTE: all static bodies (and kinematic bodies?) should be considered as "frozen", this
|
||||
// may avoid some resweeps.
|
||||
let mut intersections_to_check = vec![];
|
||||
let mut pseudo_intersections_to_check = vec![];
|
||||
|
||||
while let Some(toi) = all_toi.pop() {
|
||||
assert!(toi.toi <= dt);
|
||||
@@ -420,7 +430,7 @@ impl CCDSolver {
|
||||
continue;
|
||||
}
|
||||
|
||||
if toi.is_intersection_test {
|
||||
if toi.is_pseudo_intersection_test {
|
||||
// NOTE: this test is redundant with the previous `if !should_freeze && ...`
|
||||
// but let's keep it to avoid tricky regressions if we end up swapping both
|
||||
// `if` for some reasons in the future.
|
||||
@@ -428,7 +438,7 @@ impl CCDSolver {
|
||||
// This is only an intersection so we don't have to freeze and there is no
|
||||
// need to resweep. However we will need to see if we have to generate
|
||||
// intersection events, so push the TOI for further testing.
|
||||
intersections_to_check.push(toi);
|
||||
pseudo_intersections_to_check.push(toi);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -460,14 +470,14 @@ impl CCDSolver {
|
||||
.colliders_with_aabb_intersecting_aabb(&aabb, |ch2| {
|
||||
let co_parent1: Option<&ColliderParent> = colliders.get(ch1.0);
|
||||
let co_parent2: Option<&ColliderParent> = colliders.get(ch2.0);
|
||||
let c1: (_, _, _) = colliders.index_bundle(ch1.0);
|
||||
let c2: (_, _, _) = colliders.index_bundle(ch2.0);
|
||||
let c1: (_, _, _, &ColliderFlags) = colliders.index_bundle(ch1.0);
|
||||
let c2: (_, _, _, &ColliderFlags) = colliders.index_bundle(ch2.0);
|
||||
|
||||
let bh1 = co_parent1.map(|p| p.handle);
|
||||
let bh2 = co_parent2.map(|p| p.handle);
|
||||
|
||||
if bh1 == bh2 {
|
||||
// Ignore self-intersection.
|
||||
// Ignore self-intersection and apply groups filter.
|
||||
if bh1 == bh2 || !c1.3.collision_groups.test(c2.3.collision_groups) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -496,8 +506,8 @@ impl CCDSolver {
|
||||
self.query_pipeline.query_dispatcher(),
|
||||
*ch1,
|
||||
*ch2,
|
||||
(c1.0, c1.1, c1.2, co_parent1),
|
||||
(c2.0, c2.1, c2.2, co_parent2),
|
||||
(c1.0, c1.1, c1.2, c1.3, co_parent1),
|
||||
(c2.0, c2.1, c2.2, c2.3, co_parent2),
|
||||
b1,
|
||||
b2,
|
||||
frozen1.copied(),
|
||||
@@ -514,7 +524,7 @@ impl CCDSolver {
|
||||
}
|
||||
}
|
||||
|
||||
for toi in intersections_to_check {
|
||||
for toi in pseudo_intersections_to_check {
|
||||
// See if the intersection is still active once the bodies
|
||||
// reach their final positions.
|
||||
// - If the intersection is still active, don't report it yet. It will be
|
||||
@@ -522,10 +532,29 @@ impl CCDSolver {
|
||||
// - If the intersection isn't active anymore, and it wasn't intersecting
|
||||
// before, then we need to generate one interaction-start and one interaction-stop
|
||||
// events because it will never be detected by the narrow-phase because of tunneling.
|
||||
let (co_pos1, co_shape1): (&ColliderPosition, &ColliderShape) =
|
||||
colliders.index_bundle(toi.c1.0);
|
||||
let (co_pos2, co_shape2): (&ColliderPosition, &ColliderShape) =
|
||||
colliders.index_bundle(toi.c2.0);
|
||||
let (co_type1, co_pos1, co_shape1, co_flags1): (
|
||||
&ColliderType,
|
||||
&ColliderPosition,
|
||||
&ColliderShape,
|
||||
&ColliderFlags,
|
||||
) = colliders.index_bundle(toi.c1.0);
|
||||
let (co_type2, co_pos2, co_shape2, co_flags2): (
|
||||
&ColliderType,
|
||||
&ColliderPosition,
|
||||
&ColliderShape,
|
||||
&ColliderFlags,
|
||||
) = colliders.index_bundle(toi.c2.0);
|
||||
|
||||
if !co_type1.is_sensor() && !co_type2.is_sensor() {
|
||||
// TODO: this happens if we found a TOI between two non-sensor
|
||||
// colliders with mismatching solver_flags. It is not clear
|
||||
// what we should do in this case: we could report a
|
||||
// contact started/contact stopped event for example. But in
|
||||
// that case, what contact pair should be pass to these events?
|
||||
// For now we just ignore this special case. Let's wait for an actual
|
||||
// use-case to come up before we determine what we want to do here.
|
||||
continue;
|
||||
}
|
||||
|
||||
let co_next_pos1 = if let Some(b1) = toi.b1 {
|
||||
let co_parent1: &ColliderParent = colliders.get(toi.c1.0).unwrap();
|
||||
@@ -535,7 +564,7 @@ impl CCDSolver {
|
||||
&RigidBodyMassProps,
|
||||
) = bodies.index_bundle(b1.0);
|
||||
|
||||
let local_com1 = &rb_mprops1.mass_properties.local_com;
|
||||
let local_com1 = &rb_mprops1.local_mprops.local_com;
|
||||
let frozen1 = frozen.get(&b1);
|
||||
let pos1 = frozen1
|
||||
.map(|t| rb_vels1.integrate(*t, &rb_pos1.position, local_com1))
|
||||
@@ -553,7 +582,7 @@ impl CCDSolver {
|
||||
&RigidBodyMassProps,
|
||||
) = bodies.index_bundle(b2.0);
|
||||
|
||||
let local_com2 = &rb_mprops2.mass_properties.local_com;
|
||||
let local_com2 = &rb_mprops2.local_mprops.local_com;
|
||||
let frozen2 = frozen.get(&b2);
|
||||
let pos2 = frozen2
|
||||
.map(|t| rb_vels2.integrate(*t, &rb_pos2.position, local_com2))
|
||||
@@ -575,7 +604,11 @@ impl CCDSolver {
|
||||
.intersection_test(&next_coll_pos12, co_shape1.as_ref(), co_shape2.as_ref())
|
||||
.unwrap_or(false);
|
||||
|
||||
if !intersect_before && !intersect_after {
|
||||
if !intersect_before
|
||||
&& !intersect_after
|
||||
&& (co_flags1.active_events | co_flags2.active_events)
|
||||
.contains(ActiveEvents::INTERSECTION_EVENTS)
|
||||
{
|
||||
// Emit one intersection-started and one intersection-stopped event.
|
||||
events.handle_intersection_event(IntersectionEvent::new(toi.c1, toi.c2, true));
|
||||
events.handle_intersection_event(IntersectionEvent::new(toi.c1, toi.c2, false));
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::dynamics::{
|
||||
RigidBodyCcd, RigidBodyHandle, RigidBodyMassProps, RigidBodyPosition, RigidBodyVelocity,
|
||||
};
|
||||
use crate::geometry::{
|
||||
ColliderHandle, ColliderParent, ColliderPosition, ColliderShape, ColliderType,
|
||||
ColliderFlags, ColliderHandle, ColliderParent, ColliderPosition, ColliderShape, ColliderType,
|
||||
};
|
||||
use crate::math::Real;
|
||||
use parry::query::{NonlinearRigidMotion, QueryDispatcher};
|
||||
@@ -14,7 +14,9 @@ pub struct TOIEntry {
|
||||
pub b1: Option<RigidBodyHandle>,
|
||||
pub c2: ColliderHandle,
|
||||
pub b2: Option<RigidBodyHandle>,
|
||||
pub is_intersection_test: bool,
|
||||
// We call this "pseudo" intersection because this also
|
||||
// includes colliders pairs with mismatching solver_groups.
|
||||
pub is_pseudo_intersection_test: bool,
|
||||
pub timestamp: usize,
|
||||
}
|
||||
|
||||
@@ -25,7 +27,7 @@ impl TOIEntry {
|
||||
b1: Option<RigidBodyHandle>,
|
||||
c2: ColliderHandle,
|
||||
b2: Option<RigidBodyHandle>,
|
||||
is_intersection_test: bool,
|
||||
is_pseudo_intersection_test: bool,
|
||||
timestamp: usize,
|
||||
) -> Self {
|
||||
Self {
|
||||
@@ -34,7 +36,7 @@ impl TOIEntry {
|
||||
b1,
|
||||
c2,
|
||||
b2,
|
||||
is_intersection_test,
|
||||
is_pseudo_intersection_test,
|
||||
timestamp,
|
||||
}
|
||||
}
|
||||
@@ -47,12 +49,14 @@ impl TOIEntry {
|
||||
&ColliderType,
|
||||
&ColliderShape,
|
||||
&ColliderPosition,
|
||||
&ColliderFlags,
|
||||
Option<&ColliderParent>,
|
||||
),
|
||||
c2: (
|
||||
&ColliderType,
|
||||
&ColliderShape,
|
||||
&ColliderPosition,
|
||||
&ColliderFlags,
|
||||
Option<&ColliderParent>,
|
||||
),
|
||||
b1: Option<(
|
||||
@@ -78,8 +82,8 @@ impl TOIEntry {
|
||||
return None;
|
||||
}
|
||||
|
||||
let (co_type1, co_shape1, co_pos1, co_parent1) = c1;
|
||||
let (co_type2, co_shape2, co_pos2, co_parent2) = c2;
|
||||
let (co_type1, co_shape1, co_pos1, co_flags1, co_parent1) = c1;
|
||||
let (co_type2, co_shape2, co_pos2, co_flags2, co_parent2) = c2;
|
||||
|
||||
let linvel1 =
|
||||
frozen1.is_none() as u32 as Real * b1.map(|b| b.1.linvel).unwrap_or(na::zero());
|
||||
@@ -104,7 +108,9 @@ impl TOIEntry {
|
||||
// keep it since more conservatism is good at this stage.
|
||||
let thickness = (co_shape1.0.ccd_thickness() + co_shape2.0.ccd_thickness())
|
||||
+ smallest_contact_dist.max(0.0);
|
||||
let is_intersection_test = co_type1.is_sensor() || co_type2.is_sensor();
|
||||
let is_pseudo_intersection_test = co_type1.is_sensor()
|
||||
|| co_type2.is_sensor()
|
||||
|| !co_flags1.solver_groups.test(co_flags2.solver_groups);
|
||||
|
||||
if (end_time - start_time) * vel12 < thickness {
|
||||
return None;
|
||||
@@ -135,7 +141,7 @@ impl TOIEntry {
|
||||
// If the TOI search involves two non-sensor colliders then
|
||||
// we don't want to stop the TOI search at the first penetration
|
||||
// because the colliders may be in a separating trajectory.
|
||||
let stop_at_penetration = is_intersection_test;
|
||||
let stop_at_penetration = is_pseudo_intersection_test;
|
||||
|
||||
let res_toi = query_dispatcher
|
||||
.nonlinear_time_of_impact(
|
||||
@@ -157,7 +163,7 @@ impl TOIEntry {
|
||||
co_parent1.map(|p| p.handle),
|
||||
ch2,
|
||||
co_parent2.map(|p| p.handle),
|
||||
is_intersection_test,
|
||||
is_pseudo_intersection_test,
|
||||
0,
|
||||
))
|
||||
}
|
||||
@@ -173,7 +179,7 @@ impl TOIEntry {
|
||||
if ccd.ccd_active {
|
||||
NonlinearRigidMotion::new(
|
||||
poss.position,
|
||||
mprops.mass_properties.local_com,
|
||||
mprops.local_mprops.local_com,
|
||||
vels.linvel,
|
||||
vels.angvel,
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@ pub struct IntegrationParameters {
|
||||
///
|
||||
/// When CCD with multiple substeps is enabled, the timestep is subdivided
|
||||
/// into smaller pieces. This timestep subdivision won't generate timestep
|
||||
/// lengths smaller than `min_dt`.
|
||||
/// lengths smaller than `min_ccd_dt`.
|
||||
///
|
||||
/// Setting this to a large value will reduce the opportunity to performing
|
||||
/// CCD substepping, resulting in potentially more time dropped by the
|
||||
@@ -18,17 +18,6 @@ pub struct IntegrationParameters {
|
||||
/// to numerical instabilities.
|
||||
pub min_ccd_dt: Real,
|
||||
|
||||
// /// If `true` and if rapier is compiled with the `parallel` feature, this will enable rayon-based multithreading (default: `true`).
|
||||
// ///
|
||||
// /// This parameter is ignored if rapier is not compiled with is `parallel` feature.
|
||||
// /// Refer to rayon's documentation regarding how to configure the number of threads with either
|
||||
// /// `rayon::ThreadPoolBuilder::new().num_threads(4).build_global().unwrap()` or `ThreadPool::install`.
|
||||
// /// Note that using only one thread with `multithreading_enabled` set to `true` will result on a slower
|
||||
// /// simulation than setting `multithreading_enabled` to `false`.
|
||||
// pub multithreading_enabled: bool,
|
||||
// /// If `true`, the world's `step` method will stop right after resolving exactly one CCD event (default: `false`).
|
||||
// /// This allows the user to take action during a timestep, in-between two CCD events.
|
||||
// pub return_after_ccd_substep: bool,
|
||||
/// The Error Reduction Parameter in `[0, 1]` is the proportion of
|
||||
/// the positional error to be corrected at each time step (default: `0.2`).
|
||||
pub erp: Real,
|
||||
|
||||
@@ -229,19 +229,17 @@ impl IslandManager {
|
||||
stack: &mut Vec<RigidBodyHandle>,
|
||||
) {
|
||||
for collider_handle in &rb_colliders.0 {
|
||||
if let Some(contacts) = narrow_phase.contacts_with(*collider_handle) {
|
||||
for inter in contacts {
|
||||
for manifold in &inter.2.manifolds {
|
||||
if !manifold.data.solver_contacts.is_empty() {
|
||||
let other = crate::utils::select_other(
|
||||
(inter.0, inter.1),
|
||||
*collider_handle,
|
||||
);
|
||||
if let Some(other_body) = colliders.get(other.0) {
|
||||
stack.push(other_body.handle);
|
||||
}
|
||||
break;
|
||||
for inter in narrow_phase.contacts_with(*collider_handle) {
|
||||
for manifold in &inter.manifolds {
|
||||
if !manifold.data.solver_contacts.is_empty() {
|
||||
let other = crate::utils::select_other(
|
||||
(inter.collider1, inter.collider2),
|
||||
*collider_handle,
|
||||
);
|
||||
if let Some(other_body) = colliders.get(other.0) {
|
||||
stack.push(other_body.handle);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ use crate::math::{Isometry, Real, SpacialVector};
|
||||
pub struct FixedJoint {
|
||||
/// The frame of reference for the first body affected by this joint, expressed in the local frame
|
||||
/// of the first body.
|
||||
pub local_anchor1: Isometry<Real>,
|
||||
pub local_frame1: Isometry<Real>,
|
||||
/// The frame of reference for the second body affected by this joint, expressed in the local frame
|
||||
/// of the first body.
|
||||
pub local_anchor2: Isometry<Real>,
|
||||
pub local_frame2: Isometry<Real>,
|
||||
/// The impulse applied to the first body affected by this joint.
|
||||
///
|
||||
/// The impulse applied to the second body affected by this joint is given by `-impulse`.
|
||||
@@ -23,10 +23,10 @@ pub struct FixedJoint {
|
||||
|
||||
impl FixedJoint {
|
||||
/// Creates a new fixed joint from the frames of reference of both bodies.
|
||||
pub fn new(local_anchor1: Isometry<Real>, local_anchor2: Isometry<Real>) -> Self {
|
||||
pub fn new(local_frame1: Isometry<Real>, local_frame2: Isometry<Real>) -> Self {
|
||||
Self {
|
||||
local_anchor1,
|
||||
local_anchor2,
|
||||
local_frame1,
|
||||
local_frame2,
|
||||
impulse: SpacialVector::zeros(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ use crate::dynamics::{
|
||||
RigidBodyMassPropsFlags, RigidBodyPosition, RigidBodyType, RigidBodyVelocity,
|
||||
};
|
||||
use crate::geometry::{
|
||||
Collider, ColliderHandle, ColliderMassProperties, ColliderParent, ColliderPosition,
|
||||
ColliderShape,
|
||||
Collider, ColliderHandle, ColliderMassProps, ColliderParent, ColliderPosition, ColliderShape,
|
||||
};
|
||||
use crate::math::{AngVector, Isometry, Point, Real, Rotation, Vector};
|
||||
use crate::utils::{self, WCross};
|
||||
@@ -48,7 +47,7 @@ impl RigidBody {
|
||||
rb_ccd: RigidBodyCcd::default(),
|
||||
rb_ids: RigidBodyIds::default(),
|
||||
rb_colliders: RigidBodyColliders::default(),
|
||||
rb_activation: RigidBodyActivation::new_active(),
|
||||
rb_activation: RigidBodyActivation::active(),
|
||||
changes: RigidBodyChanges::all(),
|
||||
rb_type: RigidBodyType::Dynamic,
|
||||
rb_dominance: RigidBodyDominance::default(),
|
||||
@@ -112,7 +111,7 @@ impl RigidBody {
|
||||
/// The mass properties of this rigid-body.
|
||||
#[inline]
|
||||
pub fn mass_properties(&self) -> &MassProperties {
|
||||
&self.rb_mprops.mass_properties
|
||||
&self.rb_mprops.local_mprops
|
||||
}
|
||||
|
||||
/// The dominance group of this rigid-body.
|
||||
@@ -124,6 +123,72 @@ impl RigidBody {
|
||||
self.rb_dominance.effective_group(&self.rb_type)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Locks or unlocks all the rotations of this rigid-body.
|
||||
pub fn lock_rotations(&mut self, locked: bool, wake_up: bool) {
|
||||
if self.is_dynamic() {
|
||||
if wake_up {
|
||||
self.wake_up(true);
|
||||
}
|
||||
|
||||
self.rb_mprops
|
||||
.flags
|
||||
.set(RigidBodyMassPropsFlags::ROTATION_LOCKED_X, locked);
|
||||
self.rb_mprops
|
||||
.flags
|
||||
.set(RigidBodyMassPropsFlags::ROTATION_LOCKED_Y, locked);
|
||||
self.rb_mprops
|
||||
.flags
|
||||
.set(RigidBodyMassPropsFlags::ROTATION_LOCKED_Z, locked);
|
||||
self.update_world_mass_properties();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Locks or unlocks rotations of this rigid-body along each cartesian axes.
|
||||
pub fn restrict_rotations(
|
||||
&mut self,
|
||||
allow_rotations_x: bool,
|
||||
allow_rotations_y: bool,
|
||||
allow_rotations_z: bool,
|
||||
wake_up: bool,
|
||||
) {
|
||||
if self.is_dynamic() {
|
||||
if wake_up {
|
||||
self.wake_up(true);
|
||||
}
|
||||
|
||||
self.rb_mprops.flags.set(
|
||||
RigidBodyMassPropsFlags::ROTATION_LOCKED_X,
|
||||
allow_rotations_x,
|
||||
);
|
||||
self.rb_mprops.flags.set(
|
||||
RigidBodyMassPropsFlags::ROTATION_LOCKED_Y,
|
||||
allow_rotations_y,
|
||||
);
|
||||
self.rb_mprops.flags.set(
|
||||
RigidBodyMassPropsFlags::ROTATION_LOCKED_Z,
|
||||
allow_rotations_z,
|
||||
);
|
||||
self.update_world_mass_properties();
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Locks or unlocks all the rotations of this rigid-body.
|
||||
pub fn lock_translations(&mut self, locked: bool, wake_up: bool) {
|
||||
if self.is_dynamic() {
|
||||
if wake_up {
|
||||
self.wake_up(true);
|
||||
}
|
||||
|
||||
self.rb_mprops
|
||||
.flags
|
||||
.set(RigidBodyMassPropsFlags::TRANSLATION_LOCKED, locked);
|
||||
self.update_world_mass_properties();
|
||||
}
|
||||
}
|
||||
|
||||
/// Are the translations of this rigid-body locked?
|
||||
pub fn is_translation_locked(&self) -> bool {
|
||||
self.rb_mprops
|
||||
@@ -190,7 +255,7 @@ impl RigidBody {
|
||||
self.wake_up(true);
|
||||
}
|
||||
|
||||
self.rb_mprops.mass_properties = props;
|
||||
self.rb_mprops.local_mprops = props;
|
||||
self.update_world_mass_properties();
|
||||
}
|
||||
|
||||
@@ -210,7 +275,7 @@ impl RigidBody {
|
||||
///
|
||||
/// A kinematic body can move freely but is not affected by forces.
|
||||
pub fn is_kinematic(&self) -> bool {
|
||||
self.rb_type == RigidBodyType::Kinematic
|
||||
self.rb_type.is_kinematic()
|
||||
}
|
||||
|
||||
/// Is this rigid body static?
|
||||
@@ -224,7 +289,7 @@ impl RigidBody {
|
||||
///
|
||||
/// Returns zero if this rigid body has an infinite mass.
|
||||
pub fn mass(&self) -> Real {
|
||||
utils::inv(self.rb_mprops.mass_properties.inv_mass)
|
||||
utils::inv(self.rb_mprops.local_mprops.inv_mass)
|
||||
}
|
||||
|
||||
/// The predicted position of this rigid-body.
|
||||
@@ -251,6 +316,16 @@ impl RigidBody {
|
||||
self.rb_forces.gravity_scale = scale;
|
||||
}
|
||||
|
||||
/// The dominance group of this rigid-body.
|
||||
pub fn dominance_group(&self) -> i8 {
|
||||
self.rb_dominance.0
|
||||
}
|
||||
|
||||
/// The dominance group of this rigid-body.
|
||||
pub fn set_dominance_group(&mut self, dominance: i8) {
|
||||
self.rb_dominance.0 = dominance
|
||||
}
|
||||
|
||||
/// Adds a collider to this rigid-body.
|
||||
// TODO ECS: we keep this public for now just to simply our experiments on bevy_rapier.
|
||||
pub fn add_collider(
|
||||
@@ -259,7 +334,7 @@ impl RigidBody {
|
||||
co_parent: &ColliderParent,
|
||||
co_pos: &mut ColliderPosition,
|
||||
co_shape: &ColliderShape,
|
||||
co_mprops: &ColliderMassProperties,
|
||||
co_mprops: &ColliderMassProps,
|
||||
) {
|
||||
self.rb_colliders.attach_collider(
|
||||
&mut self.changes,
|
||||
@@ -279,10 +354,11 @@ impl RigidBody {
|
||||
if let Some(i) = self.rb_colliders.0.iter().position(|e| *e == handle) {
|
||||
self.changes.set(RigidBodyChanges::COLLIDERS, true);
|
||||
self.rb_colliders.0.swap_remove(i);
|
||||
|
||||
let mass_properties = coll
|
||||
.mass_properties()
|
||||
.transform_by(coll.position_wrt_parent());
|
||||
self.rb_mprops.mass_properties -= mass_properties;
|
||||
.transform_by(coll.position_wrt_parent().unwrap());
|
||||
self.rb_mprops.local_mprops -= mass_properties;
|
||||
self.update_world_mass_properties();
|
||||
}
|
||||
}
|
||||
@@ -384,6 +460,45 @@ impl RigidBody {
|
||||
&self.rb_pos.position
|
||||
}
|
||||
|
||||
/// The translational part of this rigid-body's position.
|
||||
#[inline]
|
||||
pub fn translation(&self) -> &Vector<Real> {
|
||||
&self.rb_pos.position.translation.vector
|
||||
}
|
||||
|
||||
/// Sets the translational part of this rigid-body's position.
|
||||
#[inline]
|
||||
pub fn set_translation(&mut self, translation: Vector<Real>, wake_up: bool) {
|
||||
self.changes.insert(RigidBodyChanges::POSITION);
|
||||
self.rb_pos.position.translation.vector = translation;
|
||||
self.rb_pos.next_position.translation.vector = translation;
|
||||
|
||||
// TODO: Do we really need to check that the body isn't dynamic?
|
||||
if wake_up && self.is_dynamic() {
|
||||
self.wake_up(true)
|
||||
}
|
||||
}
|
||||
|
||||
/// The translational part of this rigid-body's position.
|
||||
#[inline]
|
||||
pub fn rotation(&self) -> &Rotation<Real> {
|
||||
&self.rb_pos.position.rotation
|
||||
}
|
||||
|
||||
/// Sets the rotational part of this rigid-body's position.
|
||||
#[inline]
|
||||
pub fn set_rotation(&mut self, rotation: AngVector<Real>, wake_up: bool) {
|
||||
self.changes.insert(RigidBodyChanges::POSITION);
|
||||
let rotation = Rotation::new(rotation);
|
||||
self.rb_pos.position.rotation = rotation;
|
||||
self.rb_pos.next_position.rotation = rotation;
|
||||
|
||||
// TODO: Do we really need to check that the body isn't dynamic?
|
||||
if wake_up && self.is_dynamic() {
|
||||
self.wake_up(true)
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the position and `next_kinematic_position` of this rigid body.
|
||||
///
|
||||
/// This will teleport the rigid-body to the specified position/orientation,
|
||||
@@ -404,6 +519,20 @@ impl RigidBody {
|
||||
}
|
||||
}
|
||||
|
||||
/// If this rigid body is kinematic, sets its future translation after the next timestep integration.
|
||||
pub fn set_next_kinematic_rotation(&mut self, rotation: AngVector<Real>) {
|
||||
if self.is_kinematic() {
|
||||
self.rb_pos.next_position.rotation = Rotation::new(rotation);
|
||||
}
|
||||
}
|
||||
|
||||
/// If this rigid body is kinematic, sets its future orientation after the next timestep integration.
|
||||
pub fn set_next_kinematic_translation(&mut self, translation: Vector<Real>) {
|
||||
if self.is_kinematic() {
|
||||
self.rb_pos.next_position.translation = translation.into();
|
||||
}
|
||||
}
|
||||
|
||||
/// If this rigid body is kinematic, sets its future position after the next timestep integration.
|
||||
pub fn set_next_kinematic_position(&mut self, pos: Isometry<Real>) {
|
||||
if self.is_kinematic() {
|
||||
@@ -411,6 +540,17 @@ impl RigidBody {
|
||||
}
|
||||
}
|
||||
|
||||
/// Predicts the next position of this rigid-body, by integrating its velocity and forces
|
||||
/// by a time of `dt`.
|
||||
pub fn predict_position_using_velocity_and_forces(&self, dt: Real) -> Isometry<Real> {
|
||||
self.rb_pos.integrate_forces_and_velocities(
|
||||
dt,
|
||||
&self.rb_forces,
|
||||
&self.rb_vels,
|
||||
&self.rb_mprops,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn update_world_mass_properties(&mut self) {
|
||||
self.rb_mprops
|
||||
.update_world_mass_properties(&self.rb_pos.position);
|
||||
@@ -551,7 +691,7 @@ impl RigidBody {
|
||||
pub fn gravitational_potential_energy(&self, dt: Real, gravity: Vector<Real>) -> Real {
|
||||
let world_com = self
|
||||
.rb_mprops
|
||||
.mass_properties
|
||||
.local_mprops
|
||||
.world_com(&self.rb_pos.position)
|
||||
.coords;
|
||||
|
||||
@@ -608,8 +748,13 @@ impl RigidBodyBuilder {
|
||||
}
|
||||
|
||||
/// Initializes the builder of a new kinematic rigid body.
|
||||
pub fn new_kinematic() -> Self {
|
||||
Self::new(RigidBodyType::Kinematic)
|
||||
pub fn new_kinematic_velocity_based() -> Self {
|
||||
Self::new(RigidBodyType::KinematicVelocityBased)
|
||||
}
|
||||
|
||||
/// Initializes the builder of a new kinematic rigid body.
|
||||
pub fn new_kinematic_position_based() -> Self {
|
||||
Self::new(RigidBodyType::KinematicPositionBased)
|
||||
}
|
||||
|
||||
/// Initializes the builder of a new dynamic rigid body.
|
||||
@@ -618,8 +763,8 @@ impl RigidBodyBuilder {
|
||||
}
|
||||
|
||||
/// Sets the scale applied to the gravity force affecting the rigid-body to be created.
|
||||
pub fn gravity_scale(mut self, x: Real) -> Self {
|
||||
self.gravity_scale = x;
|
||||
pub fn gravity_scale(mut self, scale_factor: Real) -> Self {
|
||||
self.gravity_scale = scale_factor;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -630,19 +775,8 @@ impl RigidBodyBuilder {
|
||||
}
|
||||
|
||||
/// Sets the initial translation of the rigid-body to be created.
|
||||
#[cfg(feature = "dim2")]
|
||||
pub fn translation(mut self, x: Real, y: Real) -> Self {
|
||||
self.position.translation.x = x;
|
||||
self.position.translation.y = y;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the initial translation of the rigid-body to be created.
|
||||
#[cfg(feature = "dim3")]
|
||||
pub fn translation(mut self, x: Real, y: Real, z: Real) -> Self {
|
||||
self.position.translation.x = x;
|
||||
self.position.translation.y = y;
|
||||
self.position.translation.z = z;
|
||||
pub fn translation(mut self, translation: Vector<Real>) -> Self {
|
||||
self.position.translation.vector = translation;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -811,16 +945,8 @@ impl RigidBodyBuilder {
|
||||
}
|
||||
|
||||
/// Sets the initial linear velocity of the rigid-body to be created.
|
||||
#[cfg(feature = "dim2")]
|
||||
pub fn linvel(mut self, x: Real, y: Real) -> Self {
|
||||
self.linvel = Vector::new(x, y);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the initial linear velocity of the rigid-body to be created.
|
||||
#[cfg(feature = "dim3")]
|
||||
pub fn linvel(mut self, x: Real, y: Real, z: Real) -> Self {
|
||||
self.linvel = Vector::new(x, y, z);
|
||||
pub fn linvel(mut self, linvel: Vector<Real>) -> Self {
|
||||
self.linvel = linvel;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -857,7 +983,7 @@ impl RigidBodyBuilder {
|
||||
rb.rb_vels.angvel = self.angvel;
|
||||
rb.rb_type = self.rb_type;
|
||||
rb.user_data = self.user_data;
|
||||
rb.rb_mprops.mass_properties = self.mass_properties;
|
||||
rb.rb_mprops.local_mprops = self.mass_properties;
|
||||
rb.rb_mprops.flags = self.mprops_flags;
|
||||
rb.rb_damping.linear_damping = self.linear_damping;
|
||||
rb.rb_damping.angular_damping = self.angular_damping;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::data::{ComponentSetMut, ComponentSetOption};
|
||||
use crate::dynamics::MassProperties;
|
||||
use crate::geometry::{
|
||||
ColliderChanges, ColliderHandle, ColliderMassProperties, ColliderParent, ColliderPosition,
|
||||
ColliderChanges, ColliderHandle, ColliderMassProps, ColliderParent, ColliderPosition,
|
||||
ColliderShape, InteractionGraph, RigidBodyGraphIndex,
|
||||
};
|
||||
use crate::math::{AngVector, AngularInertia, Isometry, Point, Real, Translation, Vector};
|
||||
@@ -54,16 +54,23 @@ pub type BodyStatus = RigidBodyType;
|
||||
/// The status of a body, governing the way it is affected by external forces.
|
||||
pub enum RigidBodyType {
|
||||
/// A `RigidBodyType::Dynamic` body can be affected by all external forces.
|
||||
Dynamic,
|
||||
Dynamic = 0,
|
||||
/// A `RigidBodyType::Static` body cannot be affected by external forces.
|
||||
Static,
|
||||
/// A `RigidBodyType::Kinematic` body cannot be affected by any external forces but can be controlled
|
||||
Static = 1,
|
||||
/// A `RigidBodyType::KinematicPositionBased` body cannot be affected by any external forces but can be controlled
|
||||
/// by the user at the position level while keeping realistic one-way interaction with dynamic bodies.
|
||||
///
|
||||
/// One-way interaction means that a kinematic body can push a dynamic body, but a kinematic body
|
||||
/// cannot be pushed by anything. In other words, the trajectory of a kinematic body can only be
|
||||
/// modified by the user and is independent from any contact or joint it is involved in.
|
||||
Kinematic,
|
||||
KinematicPositionBased = 2,
|
||||
/// A `RigidBodyType::KinematicVelocityBased` body cannot be affected by any external forces but can be controlled
|
||||
/// by the user at the velocity level while keeping realistic one-way interaction with dynamic bodies.
|
||||
///
|
||||
/// One-way interaction means that a kinematic body can push a dynamic body, but a kinematic body
|
||||
/// cannot be pushed by anything. In other words, the trajectory of a kinematic body can only be
|
||||
/// modified by the user and is independent from any contact or joint it is involved in.
|
||||
KinematicVelocityBased = 3,
|
||||
// Semikinematic, // A kinematic that performs automatic CCD with the static environment to avoid traversing it?
|
||||
// Disabled,
|
||||
}
|
||||
@@ -81,7 +88,8 @@ impl RigidBodyType {
|
||||
|
||||
/// Is this rigid-body kinematic (i.e. can move but is unaffected by forces)?
|
||||
pub fn is_kinematic(self) -> bool {
|
||||
self == RigidBodyType::Kinematic
|
||||
self == RigidBodyType::KinematicPositionBased
|
||||
|| self == RigidBodyType::KinematicVelocityBased
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +174,7 @@ impl RigidBodyPosition {
|
||||
mprops: &RigidBodyMassProps,
|
||||
) -> Isometry<Real> {
|
||||
let new_vels = forces.integrate(dt, vels, mprops);
|
||||
new_vels.integrate(dt, &self.position, &mprops.mass_properties.local_com)
|
||||
new_vels.integrate(dt, &self.position, &mprops.local_mprops.local_com)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,7 +216,7 @@ pub struct RigidBodyMassProps {
|
||||
/// Flags for locking rotation and translation.
|
||||
pub flags: RigidBodyMassPropsFlags,
|
||||
/// The local mass properties of the rigid-body.
|
||||
pub mass_properties: MassProperties,
|
||||
pub local_mprops: MassProperties,
|
||||
/// The world-space center of mass of the rigid-body.
|
||||
pub world_com: Point<Real>,
|
||||
/// The inverse mass taking into account translation locking.
|
||||
@@ -222,7 +230,7 @@ impl Default for RigidBodyMassProps {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
flags: RigidBodyMassPropsFlags::empty(),
|
||||
mass_properties: MassProperties::zero(),
|
||||
local_mprops: MassProperties::zero(),
|
||||
world_com: Point::origin(),
|
||||
effective_inv_mass: 0.0,
|
||||
effective_world_inv_inertia_sqrt: AngularInertia::zero(),
|
||||
@@ -239,11 +247,20 @@ impl From<RigidBodyMassPropsFlags> for RigidBodyMassProps {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MassProperties> for RigidBodyMassProps {
|
||||
fn from(local_mprops: MassProperties) -> Self {
|
||||
Self {
|
||||
local_mprops,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RigidBodyMassProps {
|
||||
/// The mass of the rigid-body.
|
||||
#[must_use]
|
||||
pub fn mass(&self) -> Real {
|
||||
crate::utils::inv(self.mass_properties.inv_mass)
|
||||
crate::utils::inv(self.local_mprops.inv_mass)
|
||||
}
|
||||
|
||||
/// The effective mass (that takes the potential translation locking into account) of
|
||||
@@ -255,11 +272,10 @@ impl RigidBodyMassProps {
|
||||
|
||||
/// Update the world-space mass properties of `self`, taking into account the new position.
|
||||
pub fn update_world_mass_properties(&mut self, position: &Isometry<Real>) {
|
||||
self.world_com = self.mass_properties.world_com(&position);
|
||||
self.effective_inv_mass = self.mass_properties.inv_mass;
|
||||
self.effective_world_inv_inertia_sqrt = self
|
||||
.mass_properties
|
||||
.world_inv_inertia_sqrt(&position.rotation);
|
||||
self.world_com = self.local_mprops.world_com(&position);
|
||||
self.effective_inv_mass = self.local_mprops.inv_mass;
|
||||
self.effective_world_inv_inertia_sqrt =
|
||||
self.local_mprops.world_inv_inertia_sqrt(&position.rotation);
|
||||
|
||||
// Take into account translation/rotation locking.
|
||||
if self
|
||||
@@ -665,7 +681,7 @@ impl RigidBodyColliders {
|
||||
co_pos: &mut ColliderPosition,
|
||||
co_parent: &ColliderParent,
|
||||
co_shape: &ColliderShape,
|
||||
co_mprops: &ColliderMassProperties,
|
||||
co_mprops: &ColliderMassProps,
|
||||
) {
|
||||
rb_changes.set(
|
||||
RigidBodyChanges::MODIFIED | RigidBodyChanges::COLLIDERS,
|
||||
@@ -684,7 +700,7 @@ impl RigidBodyColliders {
|
||||
.mass_properties(&**co_shape)
|
||||
.transform_by(&co_parent.pos_wrt_parent);
|
||||
self.0.push(co_handle);
|
||||
rb_mprops.mass_properties += mass_properties;
|
||||
rb_mprops.local_mprops += mass_properties;
|
||||
rb_mprops.update_world_mass_properties(&rb_pos.position);
|
||||
}
|
||||
|
||||
@@ -759,7 +775,7 @@ pub struct RigidBodyActivation {
|
||||
|
||||
impl Default for RigidBodyActivation {
|
||||
fn default() -> Self {
|
||||
Self::new_active()
|
||||
Self::active()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -770,7 +786,7 @@ impl RigidBodyActivation {
|
||||
}
|
||||
|
||||
/// Create a new rb_activation status initialised with the default rb_activation threshold and is active.
|
||||
pub fn new_active() -> Self {
|
||||
pub fn active() -> Self {
|
||||
RigidBodyActivation {
|
||||
threshold: Self::default_threshold(),
|
||||
energy: Self::default_threshold() * 4.0,
|
||||
@@ -779,7 +795,7 @@ impl RigidBodyActivation {
|
||||
}
|
||||
|
||||
/// Create a new rb_activation status initialised with the default rb_activation threshold and is inactive.
|
||||
pub fn new_inactive() -> Self {
|
||||
pub fn inactive() -> Self {
|
||||
RigidBodyActivation {
|
||||
threshold: Self::default_threshold(),
|
||||
energy: 0.0,
|
||||
@@ -787,6 +803,14 @@ impl RigidBodyActivation {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new activation status that prevents the rigid-body from sleeping.
|
||||
pub fn cannot_sleep() -> Self {
|
||||
RigidBodyActivation {
|
||||
threshold: -Real::MAX,
|
||||
..Self::active()
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the body is not asleep.
|
||||
#[inline]
|
||||
pub fn is_active(&self) -> bool {
|
||||
|
||||
@@ -113,7 +113,7 @@ impl IslandSolver {
|
||||
let mut new_poss = *poss;
|
||||
let new_vels = vels.apply_damping(params.dt, damping);
|
||||
new_poss.next_position =
|
||||
vels.integrate(params.dt, &poss.position, &mprops.mass_properties.local_com);
|
||||
vels.integrate(params.dt, &poss.position, &mprops.local_mprops.local_com);
|
||||
|
||||
bodies.set_internal(handle.0, new_vels);
|
||||
bodies.set_internal(handle.0, new_poss);
|
||||
@@ -140,7 +140,7 @@ impl IslandSolver {
|
||||
.integrate(params.dt, vels, mprops)
|
||||
.apply_damping(params.dt, &damping);
|
||||
new_poss.next_position =
|
||||
vels.integrate(params.dt, &poss.position, &mprops.mass_properties.local_com);
|
||||
vels.integrate(params.dt, &poss.position, &mprops.local_mprops.local_com);
|
||||
|
||||
bodies.set_internal(handle.0, new_vels);
|
||||
bodies.set_internal(handle.0, new_poss);
|
||||
|
||||
@@ -34,8 +34,8 @@ impl BallPositionConstraint {
|
||||
let (mprops2, ids2) = rb2;
|
||||
|
||||
Self {
|
||||
local_com1: mprops1.mass_properties.local_com,
|
||||
local_com2: mprops2.mass_properties.local_com,
|
||||
local_com1: mprops1.local_mprops.local_com,
|
||||
local_com2: mprops2.local_mprops.local_com,
|
||||
im1: mprops1.effective_inv_mass,
|
||||
im2: mprops2.effective_inv_mass,
|
||||
ii1: mprops1.effective_world_inv_inertia_sqrt.squared(),
|
||||
@@ -131,7 +131,7 @@ impl BallPositionGroundConstraint {
|
||||
ii2: mprops2.effective_world_inv_inertia_sqrt.squared(),
|
||||
local_anchor2: cparams.local_anchor1,
|
||||
position2: ids2.active_set_offset,
|
||||
local_com2: mprops2.mass_properties.local_com,
|
||||
local_com2: mprops2.local_mprops.local_com,
|
||||
}
|
||||
} else {
|
||||
Self {
|
||||
@@ -140,7 +140,7 @@ impl BallPositionGroundConstraint {
|
||||
ii2: mprops2.effective_world_inv_inertia_sqrt.squared(),
|
||||
local_anchor2: cparams.local_anchor2,
|
||||
position2: ids2.active_set_offset,
|
||||
local_com2: mprops2.mass_properties.local_com,
|
||||
local_com2: mprops2.local_mprops.local_com,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ impl WBallPositionConstraint {
|
||||
let (mprops1, ids1) = rbs1;
|
||||
let (mprops2, ids2) = rbs2;
|
||||
|
||||
let local_com1 = Point::from(gather![|ii| mprops1[ii].mass_properties.local_com]);
|
||||
let local_com2 = Point::from(gather![|ii| mprops2[ii].mass_properties.local_com]);
|
||||
let local_com1 = Point::from(gather![|ii| mprops1[ii].local_mprops.local_com]);
|
||||
let local_com2 = Point::from(gather![|ii| mprops2[ii].local_mprops.local_com]);
|
||||
let im1 = SimdReal::from(gather![|ii| mprops1[ii].effective_inv_mass]);
|
||||
let im2 = SimdReal::from(gather![|ii| mprops2[ii].effective_inv_mass]);
|
||||
let ii1 = AngularInertia::<SimdReal>::from(gather![
|
||||
@@ -169,7 +169,7 @@ impl WBallPositionGroundConstraint {
|
||||
cparams[ii].local_anchor2
|
||||
}]);
|
||||
let position2 = gather![|ii| ids2[ii].active_set_offset];
|
||||
let local_com2 = Point::from(gather![|ii| mprops2[ii].mass_properties.local_com]);
|
||||
let local_com2 = Point::from(gather![|ii| mprops2[ii].local_mprops.local_com]);
|
||||
|
||||
Self {
|
||||
anchor1,
|
||||
|
||||
@@ -8,8 +8,8 @@ use crate::utils::WAngularInertia;
|
||||
pub(crate) struct FixedPositionConstraint {
|
||||
position1: usize,
|
||||
position2: usize,
|
||||
local_anchor1: Isometry<Real>,
|
||||
local_anchor2: Isometry<Real>,
|
||||
local_frame1: Isometry<Real>,
|
||||
local_frame2: Isometry<Real>,
|
||||
local_com1: Point<Real>,
|
||||
local_com2: Point<Real>,
|
||||
im1: Real,
|
||||
@@ -38,16 +38,16 @@ impl FixedPositionConstraint {
|
||||
let ang_inv_lhs = (ii1 + ii2).inverse();
|
||||
|
||||
Self {
|
||||
local_anchor1: cparams.local_anchor1,
|
||||
local_anchor2: cparams.local_anchor2,
|
||||
local_frame1: cparams.local_frame1,
|
||||
local_frame2: cparams.local_frame2,
|
||||
position1: ids1.active_set_offset,
|
||||
position2: ids2.active_set_offset,
|
||||
im1,
|
||||
im2,
|
||||
ii1,
|
||||
ii2,
|
||||
local_com1: mprops1.mass_properties.local_com,
|
||||
local_com2: mprops2.mass_properties.local_com,
|
||||
local_com1: mprops1.local_mprops.local_com,
|
||||
local_com2: mprops2.local_mprops.local_com,
|
||||
lin_inv_lhs,
|
||||
ang_inv_lhs,
|
||||
}
|
||||
@@ -58,8 +58,8 @@ impl FixedPositionConstraint {
|
||||
let mut position2 = positions[self.position2 as usize];
|
||||
|
||||
// Angular correction.
|
||||
let anchor1 = position1 * self.local_anchor1;
|
||||
let anchor2 = position2 * self.local_anchor2;
|
||||
let anchor1 = position1 * self.local_frame1;
|
||||
let anchor2 = position2 * self.local_frame2;
|
||||
let ang_err = anchor2.rotation * anchor1.rotation.inverse();
|
||||
#[cfg(feature = "dim3")]
|
||||
let ang_impulse = self
|
||||
@@ -75,8 +75,8 @@ impl FixedPositionConstraint {
|
||||
Rotation::new(self.ii2.transform_vector(-ang_impulse)) * position2.rotation;
|
||||
|
||||
// Linear correction.
|
||||
let anchor1 = position1 * Point::from(self.local_anchor1.translation.vector);
|
||||
let anchor2 = position2 * Point::from(self.local_anchor2.translation.vector);
|
||||
let anchor1 = position1 * Point::from(self.local_frame1.translation.vector);
|
||||
let anchor2 = position2 * Point::from(self.local_frame2.translation.vector);
|
||||
let err = anchor2 - anchor1;
|
||||
let impulse = err * (self.lin_inv_lhs * params.joint_erp);
|
||||
position1.translation.vector += self.im1 * impulse;
|
||||
@@ -91,7 +91,7 @@ impl FixedPositionConstraint {
|
||||
pub(crate) struct FixedPositionGroundConstraint {
|
||||
position2: usize,
|
||||
anchor1: Isometry<Real>,
|
||||
local_anchor2: Isometry<Real>,
|
||||
local_frame2: Isometry<Real>,
|
||||
local_com2: Point<Real>,
|
||||
im2: Real,
|
||||
ii2: AngularInertia<Real>,
|
||||
@@ -109,23 +109,23 @@ impl FixedPositionGroundConstraint {
|
||||
let (mprops2, ids2) = rb2;
|
||||
|
||||
let anchor1;
|
||||
let local_anchor2;
|
||||
let local_frame2;
|
||||
|
||||
if flipped {
|
||||
anchor1 = poss1.next_position * cparams.local_anchor2;
|
||||
local_anchor2 = cparams.local_anchor1;
|
||||
anchor1 = poss1.next_position * cparams.local_frame2;
|
||||
local_frame2 = cparams.local_frame1;
|
||||
} else {
|
||||
anchor1 = poss1.next_position * cparams.local_anchor1;
|
||||
local_anchor2 = cparams.local_anchor2;
|
||||
anchor1 = poss1.next_position * cparams.local_frame1;
|
||||
local_frame2 = cparams.local_frame2;
|
||||
};
|
||||
|
||||
Self {
|
||||
anchor1,
|
||||
local_anchor2,
|
||||
local_frame2,
|
||||
position2: ids2.active_set_offset,
|
||||
im2: mprops2.effective_inv_mass,
|
||||
ii2: mprops2.effective_world_inv_inertia_sqrt.squared(),
|
||||
local_com2: mprops2.mass_properties.local_com,
|
||||
local_com2: mprops2.local_mprops.local_com,
|
||||
impulse: 0.0,
|
||||
}
|
||||
}
|
||||
@@ -134,13 +134,13 @@ impl FixedPositionGroundConstraint {
|
||||
let mut position2 = positions[self.position2 as usize];
|
||||
|
||||
// Angular correction.
|
||||
let anchor2 = position2 * self.local_anchor2;
|
||||
let anchor2 = position2 * self.local_frame2;
|
||||
let ang_err = anchor2.rotation * self.anchor1.rotation.inverse();
|
||||
position2.rotation = ang_err.powf(-params.joint_erp) * position2.rotation;
|
||||
|
||||
// Linear correction.
|
||||
let anchor1 = Point::from(self.anchor1.translation.vector);
|
||||
let anchor2 = position2 * Point::from(self.local_anchor2.translation.vector);
|
||||
let anchor2 = position2 * Point::from(self.local_frame2.translation.vector);
|
||||
let err = anchor2 - anchor1;
|
||||
// NOTE: no need to divide by im2 just to multiply right after.
|
||||
let impulse = err * params.joint_erp;
|
||||
|
||||
@@ -63,8 +63,8 @@ impl FixedVelocityConstraint {
|
||||
let (poss1, vels1, mprops1, ids1) = rb1;
|
||||
let (poss2, vels2, mprops2, ids2) = rb2;
|
||||
|
||||
let anchor1 = poss1.position * cparams.local_anchor1;
|
||||
let anchor2 = poss2.position * cparams.local_anchor2;
|
||||
let anchor1 = poss1.position * cparams.local_frame1;
|
||||
let anchor2 = poss2.position * cparams.local_frame2;
|
||||
let im1 = mprops1.effective_inv_mass;
|
||||
let im2 = mprops2.effective_inv_mass;
|
||||
let ii1 = mprops1.effective_world_inv_inertia_sqrt.squared();
|
||||
@@ -280,13 +280,13 @@ impl FixedVelocityGroundConstraint {
|
||||
|
||||
let (anchor1, anchor2) = if flipped {
|
||||
(
|
||||
poss1.position * cparams.local_anchor2,
|
||||
poss2.position * cparams.local_anchor1,
|
||||
poss1.position * cparams.local_frame2,
|
||||
poss2.position * cparams.local_frame1,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
poss1.position * cparams.local_anchor1,
|
||||
poss2.position * cparams.local_anchor2,
|
||||
poss1.position * cparams.local_frame1,
|
||||
poss2.position * cparams.local_frame2,
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
@@ -91,12 +91,12 @@ impl WFixedVelocityConstraint {
|
||||
]);
|
||||
let mj_lambda2 = gather![|ii| ids2[ii].active_set_offset];
|
||||
|
||||
let local_anchor1 = Isometry::from(gather![|ii| cparams[ii].local_anchor1]);
|
||||
let local_anchor2 = Isometry::from(gather![|ii| cparams[ii].local_anchor2]);
|
||||
let local_frame1 = Isometry::from(gather![|ii| cparams[ii].local_frame1]);
|
||||
let local_frame2 = Isometry::from(gather![|ii| cparams[ii].local_frame2]);
|
||||
let impulse = SpacialVector::from(gather![|ii| cparams[ii].impulse]);
|
||||
|
||||
let anchor1 = position1 * local_anchor1;
|
||||
let anchor2 = position2 * local_anchor2;
|
||||
let anchor1 = position1 * local_frame1;
|
||||
let anchor2 = position2 * local_frame2;
|
||||
let ii1 = ii1_sqrt.squared();
|
||||
let ii2 = ii2_sqrt.squared();
|
||||
let r1 = anchor1.translation.vector - world_com1.coords;
|
||||
@@ -363,20 +363,20 @@ impl WFixedVelocityGroundConstraint {
|
||||
]);
|
||||
let mj_lambda2 = gather![|ii| ids2[ii].active_set_offset];
|
||||
|
||||
let local_anchor1 = Isometry::from(gather![|ii| if flipped[ii] {
|
||||
cparams[ii].local_anchor2
|
||||
let local_frame1 = Isometry::from(gather![|ii| if flipped[ii] {
|
||||
cparams[ii].local_frame2
|
||||
} else {
|
||||
cparams[ii].local_anchor1
|
||||
cparams[ii].local_frame1
|
||||
}]);
|
||||
let local_anchor2 = Isometry::from(gather![|ii| if flipped[ii] {
|
||||
cparams[ii].local_anchor1
|
||||
let local_frame2 = Isometry::from(gather![|ii| if flipped[ii] {
|
||||
cparams[ii].local_frame1
|
||||
} else {
|
||||
cparams[ii].local_anchor2
|
||||
cparams[ii].local_frame2
|
||||
}]);
|
||||
let impulse = SpacialVector::from(gather![|ii| cparams[ii].impulse]);
|
||||
|
||||
let anchor1 = position1 * local_anchor1;
|
||||
let anchor2 = position2 * local_anchor2;
|
||||
let anchor1 = position1 * local_frame1;
|
||||
let anchor2 = position2 * local_frame2;
|
||||
let ii2 = ii2_sqrt.squared();
|
||||
let r1 = anchor1.translation.vector - world_com1.coords;
|
||||
let r2 = anchor2.translation.vector - world_com2.coords;
|
||||
|
||||
@@ -41,8 +41,8 @@ impl GenericPositionConstraint {
|
||||
im2,
|
||||
ii1,
|
||||
ii2,
|
||||
local_com1: rb1.mass_properties.local_com,
|
||||
local_com2: rb2.mass_properties.local_com,
|
||||
local_com1: rb1.local_mprops.local_com,
|
||||
local_com2: rb2.local_mprops.local_com,
|
||||
joint: *joint,
|
||||
}
|
||||
}
|
||||
@@ -215,7 +215,7 @@ impl GenericPositionGroundConstraint {
|
||||
position2: rb2.active_set_offset,
|
||||
im2: rb2.effective_inv_mass,
|
||||
ii2: rb2.effective_world_inv_inertia_sqrt.squared(),
|
||||
local_com2: rb2.mass_properties.local_com,
|
||||
local_com2: rb2.local_mprops.local_com,
|
||||
joint: *joint,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ impl RevolutePositionConstraint {
|
||||
ii1,
|
||||
ii2,
|
||||
ang_inv_lhs,
|
||||
local_com1: mprops1.mass_properties.local_com,
|
||||
local_com2: mprops2.mass_properties.local_com,
|
||||
local_com1: mprops1.local_mprops.local_com,
|
||||
local_com2: mprops2.local_mprops.local_com,
|
||||
local_anchor1: cparams.local_anchor1,
|
||||
local_anchor2: cparams.local_anchor2,
|
||||
local_axis1: cparams.local_axis1,
|
||||
@@ -183,7 +183,7 @@ impl RevolutePositionGroundConstraint {
|
||||
local_anchor2,
|
||||
im2: mprops2.effective_inv_mass,
|
||||
ii2: mprops2.effective_world_inv_inertia_sqrt.squared(),
|
||||
local_com2: mprops2.mass_properties.local_com,
|
||||
local_com2: mprops2.local_mprops.local_com,
|
||||
axis1,
|
||||
local_axis2,
|
||||
position2: ids2.active_set_offset,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user