Add prelude + use vectors for setting linvel/translation in builders
This commit is contained in:
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,8 +1,31 @@
|
|||||||
## v0.9.0
|
## 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::*`
|
||||||
|
|
||||||
### Modified
|
### Modified
|
||||||
- Renamed `BodyStatus` to `RigidBodyType`.
|
- Renamed `BodyStatus` to `RigidBodyType`.
|
||||||
|
|
||||||
|
FIXME:
|
||||||
|
- `RigidBodyBuilder::translation` now takes a vector instead of individual components.
|
||||||
|
- `RigidBodyBuilder::linvel` now takes a vector instead of individual components.
|
||||||
|
- `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.
|
||||||
|
- 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`.
|
||||||
|
- The field `ContactPair::pair` (which contained two collider handles) has been replaced by two
|
||||||
|
fields: `ContactPair::collider1` and `ContactPair::collider2`.
|
||||||
|
- The fields `FixedJoint::local_anchor1` and `FixedJoint::local_anchor2` have been renamed to
|
||||||
|
`FixedJoint::local_frame1` and `FixedJoint::local_frame2`.
|
||||||
|
|
||||||
## v0.8.0
|
## v0.8.0
|
||||||
### Modified
|
### Modified
|
||||||
- Switch to nalgebra 0.26.
|
- Switch to nalgebra 0.26.
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
use na::Point2;
|
use rapier2d::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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)
|
let co = ColliderDesc::new(ground_shape)
|
||||||
.translation(-Vector2::y())
|
.translation(-Vector2::y())
|
||||||
.build(BodyPartHandle(ground_handle, 0));
|
.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.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.rotation(std::f32::consts::FRAC_PI_2)
|
.rotation(std::f32::consts::FRAC_PI_2)
|
||||||
.translation(ground_size, ground_size * 2.0)
|
.translation(vector![ground_size, ground_size * 2.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.rotation(std::f32::consts::FRAC_PI_2)
|
.rotation(std::f32::consts::FRAC_PI_2)
|
||||||
.translation(-ground_size, ground_size * 2.0)
|
.translation(vector![-ground_size, ground_size * 2.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
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
|
* Create the cubes
|
||||||
@@ -53,10 +51,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let y = j as f32 * shift + centery + 2.0;
|
let y = j as f32 * shift + centery + 2.0;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.rotation(std::f32::consts::FRAC_PI_2)
|
.rotation(std::f32::consts::FRAC_PI_2)
|
||||||
.translation(ground_size, ground_size * 4.0)
|
.translation(vector![ground_size, ground_size * 4.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size * 4.0, 1.2).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.rotation(std::f32::consts::FRAC_PI_2)
|
.rotation(std::f32::consts::FRAC_PI_2)
|
||||||
.translation(-ground_size, ground_size * 4.0)
|
.translation(vector![-ground_size, ground_size * 4.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size * 4.0, 1.2).build();
|
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
|
* Create the cubes
|
||||||
@@ -55,10 +53,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let y = j as f32 * shifty + centery + 3.0;
|
let y = j as f32 * shifty + centery + 3.0;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::capsule_y(rad * 1.5, rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::distributions::{Distribution, Standard};
|
||||||
use rand::{rngs::StdRng, SeedableRng};
|
use rand::{rngs::StdRng, SeedableRng};
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier2d::prelude::*;
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.rotation(std::f32::consts::FRAC_PI_2)
|
.rotation(std::f32::consts::FRAC_PI_2)
|
||||||
.translation(ground_size, ground_size * 2.0)
|
.translation(vector![ground_size, ground_size * 2.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.rotation(std::f32::consts::FRAC_PI_2)
|
.rotation(std::f32::consts::FRAC_PI_2)
|
||||||
.translation(-ground_size, ground_size * 2.0)
|
.translation(vector![-ground_size, ground_size * 2.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
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
|
* Create the convex polygons
|
||||||
@@ -58,18 +56,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let x = i as f32 * shift - centerx;
|
let x = i as f32 * shift - centerx;
|
||||||
let y = j as f32 * shift * 2.0 + centery + 2.0;
|
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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
let mut points = Vec::new();
|
let mut points = Vec::new();
|
||||||
|
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
let pt: Point2<f32> = distribution.sample(&mut rng);
|
let pt: Point<f32> = distribution.sample(&mut rng);
|
||||||
points.push(pt * scale);
|
points.push(pt * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
let collider = ColliderBuilder::convex_hull(&points).unwrap().build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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 na::DVector;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier2d::prelude::*;
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
/*
|
/*
|
||||||
* Ground
|
* Ground
|
||||||
*/
|
*/
|
||||||
let ground_size = Vector2::new(50.0, 1.0);
|
let ground_size = Vector::new(50.0, 1.0);
|
||||||
let nsubdivs = 2000;
|
let nsubdivs = 2000;
|
||||||
|
|
||||||
let heights = DVector::from_fn(nsubdivs + 1, |i, _| {
|
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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::heightfield(heights, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -46,15 +45,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let y = j as f32 * shift + centery + 3.0;
|
let y = j as f32 * shift + centery + 3.0;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
if j % 2 == 0 {
|
if j % 2 == 0 {
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
} else {
|
} else {
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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)
|
let rigid_body = RigidBodyBuilder::new(status)
|
||||||
.translation(fk * shift, -fi * shift)
|
.translation(vector![fk * shift, -fi * shift])
|
||||||
.build();
|
.build();
|
||||||
let child_handle = bodies.insert(rigid_body);
|
let child_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
let collider = ColliderBuilder::ball(rad).build();
|
||||||
colliders.insert(collider, child_handle, &mut bodies);
|
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||||
|
|
||||||
// Vertical joint.
|
// Vertical joint.
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
let parent_handle = *body_handles.last().unwrap();
|
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);
|
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +49,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
if k > 0 {
|
if k > 0 {
|
||||||
let parent_index = body_handles.len() - numi;
|
let parent_index = body_handles.len() - numi;
|
||||||
let parent_handle = body_handles[parent_index];
|
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);
|
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,5 +61,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{FixedJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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)
|
let rigid_body = RigidBodyBuilder::new(status)
|
||||||
.translation(x + fk * shift, y - fi * shift)
|
.translation(vector![x + fk * shift, y - fi * shift])
|
||||||
.build();
|
.build();
|
||||||
let child_handle = bodies.insert(rigid_body);
|
let child_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
let collider = ColliderBuilder::ball(rad).build();
|
||||||
colliders.insert(collider, child_handle, &mut bodies);
|
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||||
|
|
||||||
// Vertical joint.
|
// Vertical joint.
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
let parent_handle = *body_handles.last().unwrap();
|
let parent_handle = *body_handles.last().unwrap();
|
||||||
let joint = FixedJoint::new(
|
let joint = FixedJoint::new(
|
||||||
Isometry2::identity(),
|
Isometry::identity(),
|
||||||
Isometry2::translation(0.0, shift),
|
Isometry::translation(0.0, shift),
|
||||||
);
|
);
|
||||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
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_index = body_handles.len() - num;
|
||||||
let parent_handle = body_handles[parent_index];
|
let parent_handle = body_handles[parent_index];
|
||||||
let joint = FixedJoint::new(
|
let joint = FixedJoint::new(
|
||||||
Isometry2::identity(),
|
Isometry::identity(),
|
||||||
Isometry2::translation(-shift, 0.0),
|
Isometry::translation(-shift, 0.0),
|
||||||
);
|
);
|
||||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
@@ -76,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, PrismaticJoint, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -25,27 +23,31 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
for j in 0..50 {
|
for j in 0..50 {
|
||||||
let x = j as f32 * shift * 4.0;
|
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 mut curr_parent = bodies.insert(ground);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
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 {
|
for i in 0..num {
|
||||||
let y = y - (i + 1) as f32 * shift;
|
let y = y - (i + 1) as f32 * shift;
|
||||||
let density = 1.0;
|
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 curr_child = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).density(density).build();
|
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 {
|
let axis = if i % 2 == 0 {
|
||||||
Unit::new_normalize(Vector2::new(1.0, 1.0))
|
UnitVector::new_normalize(vector![1.0, 1.0])
|
||||||
} else {
|
} else {
|
||||||
Unit::new_normalize(Vector2::new(-1.0, 1.0))
|
UnitVector::new_normalize(vector![-1.0, 1.0])
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut prism =
|
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_enabled = true;
|
||||||
prism.limits[0] = -1.5;
|
prism.limits[0] = -1.5;
|
||||||
prism.limits[1] = 1.5;
|
prism.limits[1] = 1.5;
|
||||||
@@ -60,5 +62,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build();
|
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
|
* Create the cubes
|
||||||
@@ -40,10 +38,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let y = fi * shift + centery;
|
let y = fi * shift + centery;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::Point3;
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -37,10 +35,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let density = 0.477;
|
let density = 0.477;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).density(density).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -45,10 +43,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shift - centerz + offset;
|
let z = k as f32 * shift - centerz + offset;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -46,10 +44,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shift - centerz + offset;
|
let z = k as f32 * shift - centerz + offset;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::capsule_y(rad, rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -49,8 +47,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Build the rigid body.
|
// Build the rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(x, y, z)
|
.translation(vector![x, y, z])
|
||||||
.linvel(0.0, -1000.0, 0.0)
|
.linvel(vector![0.0, -1000.0, 0.0])
|
||||||
.ccd_enabled(true)
|
.ccd_enabled(true)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
@@ -65,7 +63,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
_ => ColliderBuilder::capsule_y(rad, rad),
|
_ => 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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -45,18 +43,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shift * 2.0 - centerz + offset;
|
let z = k as f32 * shift * 2.0 - centerz + offset;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad).build();
|
let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad).build();
|
||||||
let collider2 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
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();
|
.build();
|
||||||
let collider3 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
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();
|
.build();
|
||||||
colliders.insert(collider1, handle, &mut bodies);
|
colliders.insert_with_parent(collider1, handle, &mut bodies);
|
||||||
colliders.insert(collider2, handle, &mut bodies);
|
colliders.insert_with_parent(collider2, handle, &mut bodies);
|
||||||
colliders.insert(collider3, 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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::distributions::{Distribution, Standard};
|
||||||
use rand::{rngs::StdRng, SeedableRng};
|
use rand::{rngs::StdRng, SeedableRng};
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -53,17 +51,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
let mut points = Vec::new();
|
let mut points = Vec::new();
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
let pt: Point3<f32> = distribution.sample(&mut rng);
|
let pt: Point<f32> = distribution.sample(&mut rng);
|
||||||
points.push(pt * scale);
|
points.push(pt * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::round_convex_hull(&points, border_rad)
|
let collider = ColliderBuilder::round_convex_hull(&points, border_rad)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build();
|
.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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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 na::ComplexField;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
/*
|
/*
|
||||||
* Ground
|
* 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 nsubdivs = 20;
|
||||||
|
|
||||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::heightfield(heights, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -55,15 +54,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shift - centerz;
|
let z = k as f32 * shift - centerz;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
if j % 2 == 0 {
|
if j % 2 == 0 {
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
} else {
|
} else {
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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)
|
let rigid_body = RigidBodyBuilder::new(status)
|
||||||
.translation(fk * shift, 0.0, fi * shift)
|
.translation(vector![fk * shift, 0.0, fi * shift])
|
||||||
.build();
|
.build();
|
||||||
let child_handle = bodies.insert(rigid_body);
|
let child_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
let collider = ColliderBuilder::ball(rad).build();
|
||||||
colliders.insert(collider, child_handle, &mut bodies);
|
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||||
|
|
||||||
// Vertical joint.
|
// Vertical joint.
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
let parent_handle = *body_handles.last().unwrap();
|
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);
|
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +44,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
if k > 0 {
|
if k > 0 {
|
||||||
let parent_index = body_handles.len() - num;
|
let parent_index = body_handles.len() - num;
|
||||||
let parent_handle = body_handles[parent_index];
|
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);
|
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,8 +56,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
testbed.set_world(bodies, colliders, joints);
|
||||||
testbed.look_at(
|
testbed.look_at(point![-110.0, -46.0, 170.0], point![54.0, -38.0, 29.0]);
|
||||||
Point3::new(-110.0, -46.0, 170.0),
|
|
||||||
Point3::new(54.0, -38.0, 29.0),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
use na::{Isometry3, Point3};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::dynamics::{FixedJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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)
|
let rigid_body = RigidBodyBuilder::new(status)
|
||||||
.translation(x + fk * shift, y, z + fi * shift)
|
.translation(vector![x + fk * shift, y, z + fi * shift])
|
||||||
.build();
|
.build();
|
||||||
let child_handle = bodies.insert(rigid_body);
|
let child_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
let collider = ColliderBuilder::ball(rad).build();
|
||||||
colliders.insert(collider, child_handle, &mut bodies);
|
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||||
|
|
||||||
// Vertical joint.
|
// Vertical joint.
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
let parent_handle = *body_handles.last().unwrap();
|
let parent_handle = *body_handles.last().unwrap();
|
||||||
let joint = FixedJoint::new(
|
let joint = FixedJoint::new(
|
||||||
Isometry3::identity(),
|
Isometry::identity(),
|
||||||
Isometry3::translation(0.0, 0.0, -shift),
|
Isometry::translation(0.0, 0.0, -shift),
|
||||||
);
|
);
|
||||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
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_index = body_handles.len() - num;
|
||||||
let parent_handle = body_handles[parent_index];
|
let parent_handle = body_handles[parent_index];
|
||||||
let joint = FixedJoint::new(
|
let joint = FixedJoint::new(
|
||||||
Isometry3::identity(),
|
Isometry::identity(),
|
||||||
Isometry3::translation(-shift, 0.0, 0.0),
|
Isometry::translation(-shift, 0.0, 0.0),
|
||||||
);
|
);
|
||||||
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
@@ -80,8 +78,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
testbed.set_world(bodies, colliders, joints);
|
||||||
testbed.look_at(
|
testbed.look_at(point![-38.0, 14.0, 108.0], point![46.0, 12.0, 23.0]);
|
||||||
Point3::new(-38.0, 14.0, 108.0),
|
|
||||||
Point3::new(46.0, 12.0, 23.0),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
use na::{Point3, Unit, Vector3};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, PrismaticJoint, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -24,33 +22,37 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
for j in 0..50 {
|
for j in 0..50 {
|
||||||
let x = j as f32 * shift * 4.0;
|
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 mut curr_parent = bodies.insert(ground);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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 {
|
for i in 0..num {
|
||||||
let z = z + (i + 1) as f32 * shift;
|
let z = z + (i + 1) as f32 * shift;
|
||||||
let density = 1.0;
|
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 curr_child = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad)
|
let collider = ColliderBuilder::cuboid(rad, rad, rad)
|
||||||
.density(density)
|
.density(density)
|
||||||
.build();
|
.build();
|
||||||
colliders.insert(collider, curr_child, &mut bodies);
|
colliders.insert_with_parent(collider, curr_child, &mut bodies);
|
||||||
|
|
||||||
let axis = if i % 2 == 0 {
|
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 {
|
} 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(
|
let mut prism = PrismaticJoint::new(
|
||||||
Point3::origin(),
|
Point::origin(),
|
||||||
axis,
|
axis,
|
||||||
z,
|
z,
|
||||||
Point3::new(0.0, 0.0, -shift),
|
point![0.0, 0.0, -shift],
|
||||||
axis,
|
axis,
|
||||||
z,
|
z,
|
||||||
);
|
);
|
||||||
@@ -69,8 +71,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
testbed.set_world(bodies, colliders, joints);
|
||||||
testbed.look_at(
|
testbed.look_at(point![262.0, 63.0, 124.0], point![101.0, 4.0, -3.0]);
|
||||||
Point3::new(262.0, 63.0, 124.0),
|
|
||||||
Point3::new(101.0, 4.0, -3.0),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
use na::{Isometry3, Point3, Vector3};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RevoluteJoint, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 x = j as f32 * shift * 4.0;
|
||||||
|
|
||||||
let ground = RigidBodyBuilder::new_static()
|
let ground = RigidBodyBuilder::new_static()
|
||||||
.translation(x, y, 0.0)
|
.translation(vector![x, y, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let mut curr_parent = bodies.insert(ground);
|
let mut curr_parent = bodies.insert(ground);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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 {
|
for i in 0..num {
|
||||||
// Create four bodies.
|
// Create four bodies.
|
||||||
let z = i as f32 * shift * 2.0 + shift;
|
let z = i as f32 * shift * 2.0 + shift;
|
||||||
let positions = [
|
let positions = [
|
||||||
Isometry3::translation(x, y, z),
|
Isometry::translation(x, y, z),
|
||||||
Isometry3::translation(x + shift, y, z),
|
Isometry::translation(x + shift, y, z),
|
||||||
Isometry3::translation(x + shift, y, z + shift),
|
Isometry::translation(x + shift, y, z + shift),
|
||||||
Isometry3::translation(x, y, z + shift),
|
Isometry::translation(x, y, z + shift),
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut handles = [curr_parent; 4];
|
let mut handles = [curr_parent; 4];
|
||||||
@@ -48,19 +46,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad)
|
let collider = ColliderBuilder::cuboid(rad, rad, rad)
|
||||||
.density(density)
|
.density(density)
|
||||||
.build();
|
.build();
|
||||||
colliders.insert(collider, handles[k], &mut bodies);
|
colliders.insert_with_parent(collider, handles[k], &mut bodies);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup four joints.
|
// Setup four joints.
|
||||||
let o = Point3::origin();
|
let o = Point::origin();
|
||||||
let x = Vector3::x_axis();
|
let x = Vector::x_axis();
|
||||||
let z = Vector3::z_axis();
|
let z = Vector::z_axis();
|
||||||
|
|
||||||
let revs = [
|
let revs = [
|
||||||
RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z),
|
RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z),
|
||||||
RevoluteJoint::new(o, x, Point3::new(-shift, 0.0, 0.0), x),
|
RevoluteJoint::new(o, x, point![-shift, 0.0, 0.0], x),
|
||||||
RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z),
|
RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z),
|
||||||
RevoluteJoint::new(o, x, Point3::new(shift, 0.0, 0.0), x),
|
RevoluteJoint::new(o, x, point![shift, 0.0, 0.0], x),
|
||||||
];
|
];
|
||||||
|
|
||||||
joints.insert(&mut bodies, curr_parent, handles[0], revs[0]);
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
testbed.set_world(bodies, colliders, joints);
|
||||||
testbed.look_at(
|
testbed.look_at(point![478.0, 83.0, 228.0], point![134.0, 83.0, -116.0]);
|
||||||
Point3::new(478.0, 83.0, 228.0),
|
|
||||||
Point3::new(134.0, 83.0, -116.0),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
use na::{Point3, Vector3};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn build_block(
|
pub fn build_block(
|
||||||
testbed: &mut Testbed,
|
testbed: &mut Testbed,
|
||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
half_extents: Vector3<f32>,
|
half_extents: Vector<f32>,
|
||||||
shift: Vector3<f32>,
|
shift: Vector<f32>,
|
||||||
mut numx: usize,
|
mut numx: usize,
|
||||||
numy: usize,
|
numy: usize,
|
||||||
mut numz: 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_width = 2.0 * half_extents.z * numx as f32;
|
||||||
let block_height = 2.0 * half_extents.y * numy 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 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 color0 = [0.7, 0.5, 0.9];
|
||||||
let mut color1 = Point3::new(0.6, 1.0, 0.6);
|
let mut color1 = [0.6, 1.0, 0.6];
|
||||||
|
|
||||||
for i in 0..numy {
|
for i in 0..numy {
|
||||||
std::mem::swap(&mut numx, &mut numz);
|
std::mem::swap(&mut numx, &mut numz);
|
||||||
@@ -41,15 +39,15 @@ pub fn build_block(
|
|||||||
|
|
||||||
// Build the rigid body.
|
// Build the rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(
|
.translation(vector![
|
||||||
x + dim.x + shift.x,
|
x + dim.x + shift.x,
|
||||||
y + dim.y + shift.y,
|
y + dim.y + shift.y,
|
||||||
z + dim.z + shift.z,
|
z + dim.z + shift.z
|
||||||
)
|
])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
|
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);
|
testbed.set_initial_body_color(handle, color0);
|
||||||
std::mem::swap(&mut color0, &mut color1);
|
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 {
|
for j in 0..(block_width / (dim.z as f32 * 2.0)) as usize {
|
||||||
// Build the rigid body.
|
// Build the rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(
|
.translation(vector![
|
||||||
i as f32 * dim.x * 2.0 + dim.x + shift.x,
|
i as f32 * dim.x * 2.0 + dim.x + shift.x,
|
||||||
dim.y + shift.y + block_height,
|
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();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
|
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);
|
testbed.set_initial_body_color(handle, color0);
|
||||||
std::mem::swap(&mut color0, &mut color1);
|
std::mem::swap(&mut color0, &mut color1);
|
||||||
}
|
}
|
||||||
@@ -94,16 +92,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let ground_height = 0.1;
|
let ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* 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;
|
let mut block_height = 0.0;
|
||||||
// These should only be set to odd values otherwise
|
// These should only be set to odd values otherwise
|
||||||
// the blocks won't align in the nicest way.
|
// the blocks won't align in the nicest way.
|
||||||
@@ -120,7 +118,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
half_extents,
|
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,
|
numx,
|
||||||
numy,
|
numy,
|
||||||
numz,
|
numz,
|
||||||
@@ -135,5 +133,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
fn create_pyramid(
|
fn create_pyramid(
|
||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
offset: Vector3<f32>,
|
offset: Vector<f32>,
|
||||||
stack_height: usize,
|
stack_height: usize,
|
||||||
half_extents: Vector3<f32>,
|
half_extents: Vector<f32>,
|
||||||
) {
|
) {
|
||||||
let shift = half_extents * 2.5;
|
let shift = half_extents * 2.5;
|
||||||
for i in 0usize..stack_height {
|
for i in 0usize..stack_height {
|
||||||
@@ -24,12 +22,14 @@ fn create_pyramid(
|
|||||||
- stack_height as f32 * half_extents.z;
|
- stack_height as f32 * half_extents.z;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 rigid_body_handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
let collider =
|
let collider =
|
||||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
|
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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
*/
|
*/
|
||||||
let cube_size = 1.0;
|
let cube_size = 1.0;
|
||||||
let hext = Vector3::repeat(cube_size);
|
let hext = Vector::repeat(cube_size);
|
||||||
let bottomy = cube_size;
|
let bottomy = cube_size;
|
||||||
create_pyramid(
|
create_pyramid(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(0.0, bottomy, 0.0),
|
vector![0.0, bottomy, 0.0],
|
||||||
24,
|
24,
|
||||||
hext,
|
hext,
|
||||||
);
|
);
|
||||||
@@ -74,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
fn create_tower_circle(
|
fn create_tower_circle(
|
||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
offset: Vector3<f32>,
|
offset: Vector<f32>,
|
||||||
stack_height: usize,
|
stack_height: usize,
|
||||||
nsubdivs: usize,
|
nsubdivs: usize,
|
||||||
half_extents: Vector3<f32>,
|
half_extents: Vector<f32>,
|
||||||
) {
|
) {
|
||||||
let ang_step = std::f32::consts::PI * 2.0 / nsubdivs as 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;
|
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 fj = j as f32;
|
||||||
let fi = i as f32;
|
let fi = i as f32;
|
||||||
let y = fi * shift.y;
|
let y = fi * shift.y;
|
||||||
let pos = Translation3::from(offset)
|
let pos = Translation::from(offset)
|
||||||
* UnitQuaternion::new(Vector3::y() * (fi / 2.0 + fj) * ang_step)
|
* Rotation::new(Vector::y() * (fi / 2.0 + fj) * ang_step)
|
||||||
* Translation3::new(0.0, y, radius);
|
* Translation::new(0.0, y, radius);
|
||||||
|
|
||||||
// Build the rigid body.
|
// Build the rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic().position(pos).build();
|
let rigid_body = RigidBodyBuilder::new_dynamic().position(pos).build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider =
|
let collider =
|
||||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
|
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(
|
fn create_wall(
|
||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
offset: Vector3<f32>,
|
offset: Vector<f32>,
|
||||||
stack_height: usize,
|
stack_height: usize,
|
||||||
half_extents: Vector3<f32>,
|
half_extents: Vector<f32>,
|
||||||
) {
|
) {
|
||||||
let shift = half_extents * 2.0;
|
let shift = half_extents * 2.0;
|
||||||
for i in 0usize..stack_height {
|
for i in 0usize..stack_height {
|
||||||
@@ -52,11 +50,13 @@ fn create_wall(
|
|||||||
- stack_height as f32 * half_extents.z;
|
- stack_height as f32 * half_extents.z;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider =
|
let collider =
|
||||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
|
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(
|
fn create_pyramid(
|
||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
offset: Vector3<f32>,
|
offset: Vector<f32>,
|
||||||
stack_height: usize,
|
stack_height: usize,
|
||||||
half_extents: Vector3<f32>,
|
half_extents: Vector<f32>,
|
||||||
) {
|
) {
|
||||||
let shift = half_extents * 2.0;
|
let shift = half_extents * 2.0;
|
||||||
|
|
||||||
@@ -83,11 +83,13 @@ fn create_pyramid(
|
|||||||
- stack_height as f32 * half_extents.z;
|
- stack_height as f32 * half_extents.z;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider =
|
let collider =
|
||||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
|
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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
*/
|
*/
|
||||||
let cube_size = 1.0;
|
let cube_size = 1.0;
|
||||||
let hext = Vector3::repeat(cube_size);
|
let hext = Vector::repeat(cube_size);
|
||||||
let bottomy = cube_size * 50.0;
|
let bottomy = cube_size * 50.0;
|
||||||
create_pyramid(
|
create_pyramid(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(-110.0, bottomy, 0.0),
|
vector![-110.0, bottomy, 0.0],
|
||||||
12,
|
12,
|
||||||
hext,
|
hext,
|
||||||
);
|
);
|
||||||
create_pyramid(
|
create_pyramid(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(-80.0, bottomy, 0.0),
|
vector![-80.0, bottomy, 0.0],
|
||||||
12,
|
12,
|
||||||
hext,
|
hext,
|
||||||
);
|
);
|
||||||
create_pyramid(
|
create_pyramid(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(-50.0, bottomy, 0.0),
|
vector![-50.0, bottomy, 0.0],
|
||||||
12,
|
12,
|
||||||
hext,
|
hext,
|
||||||
);
|
);
|
||||||
create_pyramid(
|
create_pyramid(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(-20.0, bottomy, 0.0),
|
vector![-20.0, bottomy, 0.0],
|
||||||
12,
|
12,
|
||||||
hext,
|
hext,
|
||||||
);
|
);
|
||||||
create_wall(
|
create_wall(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(-2.0, bottomy, 0.0),
|
vector![-2.0, bottomy, 0.0],
|
||||||
12,
|
12,
|
||||||
hext,
|
hext,
|
||||||
);
|
);
|
||||||
create_wall(
|
create_wall(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(4.0, bottomy, 0.0),
|
vector![4.0, bottomy, 0.0],
|
||||||
12,
|
12,
|
||||||
hext,
|
hext,
|
||||||
);
|
);
|
||||||
create_wall(
|
create_wall(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(10.0, bottomy, 0.0),
|
vector![10.0, bottomy, 0.0],
|
||||||
12,
|
12,
|
||||||
hext,
|
hext,
|
||||||
);
|
);
|
||||||
create_tower_circle(
|
create_tower_circle(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(25.0, bottomy, 0.0),
|
vector![25.0, bottomy, 0.0],
|
||||||
8,
|
8,
|
||||||
24,
|
24,
|
||||||
hext,
|
hext,
|
||||||
@@ -182,5 +184,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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 na::ComplexField;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, HeightField};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
/*
|
/*
|
||||||
* Ground
|
* 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 nsubdivs = 20;
|
||||||
|
|
||||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::trimesh(vertices, indices).build();
|
let collider = ColliderBuilder::trimesh(vertices, indices).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the cubes
|
* Create the cubes
|
||||||
@@ -60,15 +59,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shift - centerz;
|
let z = k as f32 * shift - centerz;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
if j % 2 == 0 {
|
if j % 2 == 0 {
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
} else {
|
} else {
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::Point2;
|
use rapier2d::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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.
|
// Callback that will be executed on the main loop to handle proximities.
|
||||||
testbed.add_callback(move |mut graphics, physics, _, _| {
|
testbed.add_callback(move |mut graphics, physics, _, _| {
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 10.0)
|
.translation(vector![0.0, 10.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = physics.bodies.insert(rigid_body);
|
let handle = physics.bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||||
physics
|
physics
|
||||||
.colliders
|
.colliders
|
||||||
.insert(collider, handle, &mut physics.bodies);
|
.insert_with_parent(collider, handle, &mut physics.bodies);
|
||||||
|
|
||||||
if let Some(graphics) = &mut graphics {
|
if let Some(graphics) = &mut graphics {
|
||||||
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
||||||
@@ -48,5 +46,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -21,23 +19,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build();
|
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)
|
let collider = ColliderBuilder::cuboid(ground_thickness, ground_size)
|
||||||
.translation(-3.0, 0.0)
|
.translation(vector![-3.0, 0.0])
|
||||||
.build();
|
.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)
|
let collider = ColliderBuilder::cuboid(ground_thickness, ground_size)
|
||||||
.translation(6.0, 0.0)
|
.translation(vector![6.0, 0.0])
|
||||||
.build();
|
.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)
|
let collider = ColliderBuilder::cuboid(ground_thickness, ground_size)
|
||||||
.translation(2.5, 0.0)
|
.translation(vector![2.5, 0.0])
|
||||||
.sensor(true)
|
.sensor(true)
|
||||||
.build();
|
.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
|
* Create the shapes
|
||||||
@@ -45,9 +43,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let radx = 0.4;
|
let radx = 0.4;
|
||||||
let rady = 0.05;
|
let rady = 0.05;
|
||||||
|
|
||||||
let delta1 = Isometry2::translation(0.0, radx - rady);
|
let delta1 = Isometry::translation(0.0, radx - rady);
|
||||||
let delta2 = Isometry2::translation(-radx + rady, 0.0);
|
let delta2 = Isometry::translation(-radx + rady, 0.0);
|
||||||
let delta3 = Isometry2::translation(radx - rady, 0.0);
|
let delta3 = Isometry::translation(radx - rady, 0.0);
|
||||||
|
|
||||||
let mut compound_parts = Vec::new();
|
let mut compound_parts = Vec::new();
|
||||||
let vertical = SharedShape::cuboid(rady, radx);
|
let vertical = SharedShape::cuboid(rady, radx);
|
||||||
@@ -70,8 +68,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Build the rigid body.
|
// Build the rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(x, y)
|
.translation(vector![x, y])
|
||||||
.linvel(100.0, -10.0)
|
.linvel(vector![100.0, -10.0])
|
||||||
.ccd_enabled(true)
|
.ccd_enabled(true)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
@@ -80,12 +78,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
// let collider = ColliderBuilder::new(part.1.clone())
|
// let collider = ColliderBuilder::new(part.1.clone())
|
||||||
// .position_wrt_parent(part.0)
|
// .position_wrt_parent(part.0)
|
||||||
// .build();
|
// .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::new(compound_shape.clone()).build();
|
||||||
// let collider = ColliderBuilder::cuboid(radx, rady).build();
|
// let collider = ColliderBuilder::cuboid(radx, rady).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,13 +91,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
testbed.add_callback(move |mut graphics, physics, events, _| {
|
testbed.add_callback(move |mut graphics, physics, events, _| {
|
||||||
while let Ok(prox) = events.intersection_events.try_recv() {
|
while let Ok(prox) = events.intersection_events.try_recv() {
|
||||||
let color = if prox.intersecting {
|
let color = if prox.intersecting {
|
||||||
Point3::new(1.0, 1.0, 0.0)
|
[1.0, 1.0, 0.0]
|
||||||
} else {
|
} 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_handle1 = physics
|
||||||
let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
|
.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 let Some(graphics) = &mut graphics {
|
||||||
if parent_handle1 != ground_handle && prox.collider1 != sensor_handle {
|
if parent_handle1 != ground_handle && prox.collider1 != sensor_handle {
|
||||||
graphics.set_body_color(parent_handle1, color);
|
graphics.set_body_color(parent_handle1, color);
|
||||||
@@ -115,5 +123,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet, InteractionGroups};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height)
|
.translation(vector![0.0, -ground_height])
|
||||||
.build();
|
.build();
|
||||||
let floor_handle = bodies.insert(rigid_body);
|
let floor_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height).build();
|
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
|
* Setup groups
|
||||||
@@ -34,23 +32,24 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* A green floor that will collide with the GREEN group only.
|
* A green floor that will collide with the GREEN group only.
|
||||||
*/
|
*/
|
||||||
let green_floor = ColliderBuilder::cuboid(1.0, 0.1)
|
let green_floor = ColliderBuilder::cuboid(1.0, 0.1)
|
||||||
.translation(0.0, 1.0)
|
.translation(vector![0.0, 1.0])
|
||||||
.collision_groups(GREEN_GROUP)
|
.collision_groups(GREEN_GROUP)
|
||||||
.build();
|
.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.
|
* A blue floor that will collide with the BLUE group only.
|
||||||
*/
|
*/
|
||||||
let blue_floor = ColliderBuilder::cuboid(1.0, 0.1)
|
let blue_floor = ColliderBuilder::cuboid(1.0, 0.1)
|
||||||
.translation(0.0, 2.0)
|
.translation(vector![0.0, 2.0])
|
||||||
.collision_groups(BLUE_GROUP)
|
.collision_groups(BLUE_GROUP)
|
||||||
.build();
|
.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
|
* Create the cubes
|
||||||
@@ -69,17 +68,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Alternate between the green and blue groups.
|
// Alternate between the green and blue groups.
|
||||||
let (group, color) = if i % 2 == 0 {
|
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 {
|
} 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad)
|
let collider = ColliderBuilder::cuboid(rad, rad)
|
||||||
.collision_groups(group)
|
.collision_groups(group)
|
||||||
.build();
|
.build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
|
|
||||||
testbed.set_initial_body_color(handle, color);
|
testbed.set_initial_body_color(handle, color);
|
||||||
}
|
}
|
||||||
@@ -89,5 +90,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::distributions::{Distribution, Standard};
|
||||||
use rand::{rngs::StdRng, SeedableRng};
|
use rand::{rngs::StdRng, SeedableRng};
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier2d::prelude::*;
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.rotation(std::f32::consts::FRAC_PI_2)
|
.rotation(std::f32::consts::FRAC_PI_2)
|
||||||
.translation(ground_size, ground_size * 2.0)
|
.translation(vector![ground_size, ground_size * 2.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.rotation(std::f32::consts::FRAC_PI_2)
|
.rotation(std::f32::consts::FRAC_PI_2)
|
||||||
.translation(-ground_size, ground_size * 2.0)
|
.translation(vector![-ground_size, ground_size * 2.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2).build();
|
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
|
* Create the convex polygons
|
||||||
@@ -58,18 +56,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let x = i as f32 * shift - centerx;
|
let x = i as f32 * shift - centerx;
|
||||||
let y = j as f32 * shift * 2.0 + centery + 2.0;
|
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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
let mut points = Vec::new();
|
let mut points = Vec::new();
|
||||||
|
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
let pt: Point2<f32> = distribution.sample(&mut rng);
|
let pt: Point<f32> = distribution.sample(&mut rng);
|
||||||
points.push(pt * scale);
|
points.push(pt * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
let collider = ColliderBuilder::convex_hull(&points).unwrap().build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -24,8 +22,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Build the rigid body.
|
// Build the rigid body.
|
||||||
let rb = RigidBodyBuilder::new_dynamic()
|
let rb = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(x, y)
|
.translation(vector![x, y])
|
||||||
.linvel(x * 10.0, y * 10.0)
|
.linvel(vector![x * 10.0, y * 10.0])
|
||||||
.angvel(100.0)
|
.angvel(100.0)
|
||||||
.linear_damping((i + 1) as f32 * subdiv * 10.0)
|
.linear_damping((i + 1) as f32 * subdiv * 10.0)
|
||||||
.angular_damping((num - i) 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.
|
// Build the collider.
|
||||||
let co = ColliderBuilder::cuboid(rad, rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world_with_params(bodies, colliders, joints, Vector2::zeros(), ());
|
testbed.set_world_with_params(bodies, colliders, joints, Vector::zeros(), ());
|
||||||
testbed.look_at(Point2::new(3.0, 2.0), 50.0);
|
testbed.look_at(point![3.0, 2.0], 50.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
use na::Point2;
|
use rapier2d::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -16,25 +14,25 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
*/
|
*/
|
||||||
let rad = 1.0;
|
let rad = 1.0;
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -rad)
|
.translation(vector![0.0, -rad])
|
||||||
.rotation(std::f32::consts::PI / 4.0)
|
.rotation(std::f32::consts::PI / 4.0)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
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.
|
// Build the dynamic box rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 3.0 * rad)
|
.translation(vector![0.0, 3.0 * rad])
|
||||||
.can_sleep(false)
|
.can_sleep(false)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
let collider = ColliderBuilder::ball(rad).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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 na::DVector;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier2d::prelude::*;
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
/*
|
/*
|
||||||
* Ground
|
* Ground
|
||||||
*/
|
*/
|
||||||
let ground_size = Vector2::new(50.0, 1.0);
|
let ground_size = Vector::new(50.0, 1.0);
|
||||||
let nsubdivs = 2000;
|
let nsubdivs = 2000;
|
||||||
|
|
||||||
let heights = DVector::from_fn(nsubdivs + 1, |i, _| {
|
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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::heightfield(heights, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -46,15 +45,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let y = j as f32 * shift + centery + 3.0;
|
let y = j as f32 * shift + centery + 3.0;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
if j % 2 == 0 {
|
if j % 2 == 0 {
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
} else {
|
} else {
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{BallJoint, JointSet, RigidBodyBuilder, RigidBodySet, RigidBodyType};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -15,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Create the balls
|
* Create the balls
|
||||||
*/
|
*/
|
||||||
// Build the rigid body.
|
// 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,
|
// in order to be able to compare rapier with Box2D,
|
||||||
// we set it to 0.4.
|
// we set it to 0.4.
|
||||||
let rad = 0.4;
|
let rad = 0.4;
|
||||||
@@ -37,16 +35,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new(status)
|
let rigid_body = RigidBodyBuilder::new(status)
|
||||||
.translation(fk * shift, -fi * shift)
|
.translation(vector![fk * shift, -fi * shift])
|
||||||
.build();
|
.build();
|
||||||
let child_handle = bodies.insert(rigid_body);
|
let child_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
let collider = ColliderBuilder::ball(rad).build();
|
||||||
colliders.insert(collider, child_handle, &mut bodies);
|
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||||
|
|
||||||
// Vertical joint.
|
// Vertical joint.
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
let parent_handle = *body_handles.last().unwrap();
|
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);
|
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +52,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
if k > 0 {
|
if k > 0 {
|
||||||
let parent_index = body_handles.len() - numi;
|
let parent_index = body_handles.len() - numi;
|
||||||
let parent_handle = body_handles[parent_index];
|
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);
|
joints.insert(&mut bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
// This shows a bug when a cylinder is in contact with a very large
|
// 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height)
|
.translation(vector![0.0, -ground_height])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height).build();
|
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.
|
* A rectangle that only rotate.
|
||||||
*/
|
*/
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 3.0)
|
.translation(vector![0.0, 3.0])
|
||||||
.lock_translations()
|
.lock_translations()
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(2.0, 0.6).build();
|
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.
|
* A tilted capsule that cannot rotate.
|
||||||
*/
|
*/
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 5.0)
|
.translation(vector![0.0, 5.0])
|
||||||
.rotation(1.0)
|
.rotation(1.0)
|
||||||
.lock_rotations()
|
.lock_rotations()
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::capsule_y(0.6, 0.4).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderHandle, ColliderSet};
|
|
||||||
use rapier2d::pipeline::{ContactModificationContext, PhysicsHooks, PhysicsHooksFlags};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
struct OneWayPlatformHook {
|
struct OneWayPlatformHook {
|
||||||
@@ -10,10 +7,6 @@ struct OneWayPlatformHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
|
impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
|
||||||
fn active_hooks(&self) -> PhysicsHooksFlags {
|
|
||||||
PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS
|
|
||||||
}
|
|
||||||
|
|
||||||
fn modify_solver_contacts(
|
fn modify_solver_contacts(
|
||||||
&self,
|
&self,
|
||||||
context: &mut ContactModificationContext<RigidBodySet, ColliderSet>,
|
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_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_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.
|
// - 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 {
|
if context.collider1 == self.platform1 {
|
||||||
allowed_local_n1 = Vector2::y();
|
allowed_local_n1 = Vector::y();
|
||||||
} else if context.collider2 == self.platform1 {
|
} else if context.collider2 == self.platform1 {
|
||||||
// Flip the allowed direction.
|
// Flip the allowed direction.
|
||||||
allowed_local_n1 = -Vector2::y();
|
allowed_local_n1 = -Vector::y();
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.collider1 == self.platform2 {
|
if context.collider1 == self.platform2 {
|
||||||
allowed_local_n1 = -Vector2::y();
|
allowed_local_n1 = -Vector::y();
|
||||||
} else if context.collider2 == self.platform2 {
|
} else if context.collider2 == self.platform2 {
|
||||||
// Flip the allowed direction.
|
// Flip the allowed direction.
|
||||||
allowed_local_n1 = Vector2::y();
|
allowed_local_n1 = Vector::y();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the helper function that simulates one-way platforms.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
let collider = ColliderBuilder::cuboid(25.0, 0.5)
|
let collider = ColliderBuilder::cuboid(25.0, 0.5)
|
||||||
.translation(30.0, 2.0)
|
.translation(vector![30.0, 2.0])
|
||||||
.modify_solver_contacts(true)
|
.active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS)
|
||||||
.build();
|
.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)
|
let collider = ColliderBuilder::cuboid(25.0, 0.5)
|
||||||
.translation(-30.0, -2.0)
|
.translation(vector![-30.0, -2.0])
|
||||||
.modify_solver_contacts(true)
|
.active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS)
|
||||||
.build();
|
.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.
|
* Setup the one-way platform hook.
|
||||||
@@ -105,12 +98,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
// Spawn a new cube.
|
// Spawn a new cube.
|
||||||
let collider = ColliderBuilder::cuboid(1.5, 2.0).build();
|
let collider = ColliderBuilder::cuboid(1.5, 2.0).build();
|
||||||
let body = RigidBodyBuilder::new_dynamic()
|
let body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(20.0, 10.0)
|
.translation(vector![20.0, 10.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = physics.bodies.insert(body);
|
let handle = physics.bodies.insert(body);
|
||||||
physics
|
physics
|
||||||
.colliders
|
.colliders
|
||||||
.insert(collider, handle, &mut physics.bodies);
|
.insert_with_parent(collider, handle, &mut physics.bodies);
|
||||||
|
|
||||||
if let Some(graphics) = graphics {
|
if let Some(graphics) = graphics {
|
||||||
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
||||||
@@ -134,8 +127,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
bodies,
|
bodies,
|
||||||
colliders,
|
colliders,
|
||||||
joints,
|
joints,
|
||||||
Vector2::new(0.0, -9.81),
|
vector![0.0, -9.81],
|
||||||
physics_hooks,
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height)
|
.translation(vector![0.0, -ground_height])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height).build();
|
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
|
* Create the boxes
|
||||||
@@ -40,10 +38,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let y = j as f32 * shift + centery;
|
let y = j as f32 * shift + centery;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,11 +51,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Setup a kinematic rigid body.
|
* Setup a kinematic rigid body.
|
||||||
*/
|
*/
|
||||||
let platform_body = RigidBodyBuilder::new_kinematic()
|
let platform_body = RigidBodyBuilder::new_kinematic()
|
||||||
.translation(-10.0 * rad, 1.5 + 0.8)
|
.translation(vector![-10.0 * rad, 1.5 + 0.8])
|
||||||
.build();
|
.build();
|
||||||
let platform_handle = bodies.insert(platform_body);
|
let platform_handle = bodies.insert(platform_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad * 10.0, rad).build();
|
let collider = ColliderBuilder::cuboid(rad * 10.0, rad).build();
|
||||||
colliders.insert(collider, platform_handle, &mut bodies);
|
colliders.insert_with_parent(collider, platform_handle, &mut bodies);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup a callback to control the platform.
|
* Setup a callback to control the platform.
|
||||||
@@ -82,5 +82,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Run the simulation.
|
* Run the simulation.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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 na::ComplexField;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier2d::prelude::*;
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 step_size = ground_size / (nsubdivs as f32);
|
||||||
let mut points = Vec::new();
|
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 {
|
for i in 1..nsubdivs - 1 {
|
||||||
let x = -ground_size / 2.0 + i as f32 * step_size;
|
let x = -ground_size / 2.0 + i as f32 * step_size;
|
||||||
let y = ComplexField::cos(i as f32 * step_size) * 2.0;
|
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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::polyline(points, None).build();
|
let collider = ColliderBuilder::polyline(points, None).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the cubes
|
* Create the cubes
|
||||||
@@ -48,15 +47,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let y = j as f32 * shift + centery + 3.0;
|
let y = j as f32 * shift + centery + 3.0;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
if j % 2 == 0 {
|
if j % 2 == 0 {
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
} else {
|
} else {
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_thickness).build();
|
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
|
* Create the cubes
|
||||||
@@ -40,10 +38,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let y = fi * shift + centery;
|
let y = fi * shift + centery;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 1.0;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height)
|
.translation(vector![0.0, -ground_height])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height)
|
let collider = ColliderBuilder::cuboid(ground_size, ground_height)
|
||||||
.restitution(1.0)
|
.restitution(1.0)
|
||||||
.build();
|
.build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
|
|
||||||
let num = 10;
|
let num = 10;
|
||||||
let rad = 0.5;
|
let rad = 0.5;
|
||||||
@@ -33,13 +31,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
for i in 0..=num {
|
for i in 0..=num {
|
||||||
let x = (i as f32) - num as f32 / 2.0;
|
let x = (i as f32) - num as f32 / 2.0;
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
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();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad)
|
let collider = ColliderBuilder::ball(rad)
|
||||||
.restitution((i as f32) / (num as f32))
|
.restitution((i as f32) / (num as f32))
|
||||||
.build();
|
.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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height)
|
.translation(vector![0.0, -ground_height])
|
||||||
.build();
|
.build();
|
||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height).build();
|
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.
|
* Create some boxes.
|
||||||
@@ -38,12 +36,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let y = 3.0;
|
let y = 3.0;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
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,37 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Rigid body so that the sensor can move.
|
// Rigid body so that the sensor can move.
|
||||||
let sensor = RigidBodyBuilder::new_dynamic()
|
let sensor = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 10.0)
|
.translation(vector![0.0, 10.0])
|
||||||
.build();
|
.build();
|
||||||
let sensor_handle = bodies.insert(sensor);
|
let sensor_handle = bodies.insert(sensor);
|
||||||
|
|
||||||
// Solid cube attached to the sensor which
|
// Solid cube attached to the sensor which
|
||||||
// other colliders can touch.
|
// other colliders can touch.
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad).build();
|
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
|
// We create a collider desc without density because we don't
|
||||||
// want it to contribute to the rigid body mass.
|
// want it to contribute to the rigid body mass.
|
||||||
let sensor_collider = ColliderBuilder::ball(rad * 5.0).sensor(true).build();
|
let sensor_collider = ColliderBuilder::ball(rad * 5.0)
|
||||||
colliders.insert(sensor_collider, sensor_handle, &mut bodies);
|
.density(0.0)
|
||||||
|
.sensor(true)
|
||||||
|
.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.
|
// Callback that will be executed on the main loop to handle proximities.
|
||||||
testbed.add_callback(move |mut graphics, physics, events, _| {
|
testbed.add_callback(move |mut graphics, physics, events, _| {
|
||||||
while let Ok(prox) = events.intersection_events.try_recv() {
|
while let Ok(prox) = events.intersection_events.try_recv() {
|
||||||
let color = if prox.intersecting {
|
let color = if prox.intersecting {
|
||||||
Point3::new(1.0, 1.0, 0.0)
|
[1.0, 1.0, 0.0]
|
||||||
} else {
|
} 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_handle1 = physics.colliders[prox.collider1].parent().unwrap();
|
||||||
let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
|
let parent_handle2 = physics.colliders[prox.collider2].parent().unwrap();
|
||||||
|
|
||||||
if let Some(graphics) = &mut graphics {
|
if let Some(graphics) = &mut graphics {
|
||||||
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
||||||
graphics.set_body_color(parent_handle1, color);
|
graphics.set_body_color(parent_handle1, color);
|
||||||
@@ -94,5 +98,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier2d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier2d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed2d::Testbed;
|
use rapier_testbed2d::Testbed;
|
||||||
|
|
||||||
use lyon::math::Point;
|
use lyon::math::Point;
|
||||||
@@ -25,23 +23,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.rotation(std::f32::consts::FRAC_PI_2)
|
.rotation(std::f32::consts::FRAC_PI_2)
|
||||||
.translation(ground_size, ground_size)
|
.translation(vector![ground_size, ground_size])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.rotation(std::f32::consts::FRAC_PI_2)
|
.rotation(std::f32::consts::FRAC_PI_2)
|
||||||
.translation(-ground_size, ground_size)
|
.translation(vector![-ground_size, ground_size])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, 1.2).build();
|
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.
|
* Create the trimeshes from a tesselated SVG.
|
||||||
@@ -83,18 +81,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let vertices: Vec<_> = mesh
|
let vertices: Vec<_> = mesh
|
||||||
.vertices
|
.vertices
|
||||||
.iter()
|
.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();
|
.collect();
|
||||||
|
|
||||||
for k in 0..5 {
|
for k in 0..5 {
|
||||||
let collider =
|
let collider =
|
||||||
ColliderBuilder::trimesh(vertices.clone(), indices.clone()).build();
|
ColliderBuilder::trimesh(vertices.clone(), indices.clone()).build();
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
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)
|
.rotation(angle)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
}
|
}
|
||||||
|
|
||||||
ith += 1;
|
ith += 1;
|
||||||
@@ -106,7 +104,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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#"
|
const RAPIER_SVG_STR: &'static str = r#"
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
use na::{Point3, Vector3};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
fn create_wall(
|
fn create_wall(
|
||||||
testbed: &mut Testbed,
|
testbed: &mut Testbed,
|
||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
offset: Vector3<f32>,
|
offset: Vector<f32>,
|
||||||
stack_height: usize,
|
stack_height: usize,
|
||||||
half_extents: Vector3<f32>,
|
half_extents: Vector<f32>,
|
||||||
) {
|
) {
|
||||||
let shift = half_extents * 2.0;
|
let shift = half_extents * 2.0;
|
||||||
let mut k = 0;
|
let mut k = 0;
|
||||||
@@ -23,22 +21,18 @@ fn create_wall(
|
|||||||
- stack_height as f32 * half_extents.z;
|
- stack_height as f32 * half_extents.z;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider =
|
let collider =
|
||||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z).build();
|
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;
|
k += 1;
|
||||||
if k % 2 == 0 {
|
if k % 2 == 0 {
|
||||||
testbed.set_initial_body_color(
|
testbed.set_initial_body_color(handle, [255. / 255., 131. / 255., 244.0 / 255.]);
|
||||||
handle,
|
|
||||||
Point3::new(255. / 255., 131. / 255., 244.0 / 255.),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
testbed.set_initial_body_color(
|
testbed.set_initial_body_color(handle, [131. / 255., 255. / 255., 244.0 / 255.]);
|
||||||
handle,
|
|
||||||
Point3::new(131. / 255., 255. / 255., 244.0 / 255.),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,11 +53,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let ground_height = 0.1;
|
let ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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.
|
* Create the pyramids.
|
||||||
@@ -79,18 +73,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
testbed,
|
testbed,
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(x, shift_y, 0.0),
|
vector![x, shift_y, 0.0],
|
||||||
num_z,
|
num_z,
|
||||||
Vector3::new(0.5, 0.5, 1.0),
|
vector![0.5, 0.5, 1.0],
|
||||||
);
|
);
|
||||||
|
|
||||||
create_wall(
|
create_wall(
|
||||||
testbed,
|
testbed,
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
Vector3::new(x, shift_y, shift_z),
|
vector![x, shift_y, shift_z],
|
||||||
num_z,
|
num_z,
|
||||||
Vector3::new(0.5, 0.5, 1.0),
|
vector![0.5, 0.5, 1.0],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,35 +98,45 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
.sensor(true)
|
.sensor(true)
|
||||||
.build();
|
.build();
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.linvel(1000.0, 0.0, 0.0)
|
.linvel(vector![1000.0, 0.0, 0.0])
|
||||||
.translation(-20.0, shift_y + 2.0, 0.0)
|
.translation(vector![-20.0, shift_y + 2.0, 0.0])
|
||||||
.ccd_enabled(true)
|
.ccd_enabled(true)
|
||||||
.build();
|
.build();
|
||||||
let sensor_handle = bodies.insert(rigid_body);
|
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.
|
// Second rigid-body with CCD enabled.
|
||||||
let collider = ColliderBuilder::ball(1.0).density(10.0).build();
|
let collider = ColliderBuilder::ball(1.0).density(10.0).build();
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.linvel(1000.0, 0.0, 0.0)
|
.linvel(vector![1000.0, 0.0, 0.0])
|
||||||
.translation(-20.0, shift_y + 2.0, shift_z)
|
.translation(vector![-20.0, shift_y + 2.0, shift_z])
|
||||||
.ccd_enabled(true)
|
.ccd_enabled(true)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
colliders.insert(collider.clone(), handle, &mut bodies);
|
colliders.insert_with_parent(collider.clone(), handle, &mut bodies);
|
||||||
testbed.set_initial_body_color(handle, Point3::new(0.2, 0.2, 1.0));
|
testbed.set_initial_body_color(handle, [0.2, 0.2, 1.0]);
|
||||||
|
|
||||||
// Callback that will be executed on the main loop to handle proximities.
|
// Callback that will be executed on the main loop to handle proximities.
|
||||||
testbed.add_callback(move |mut graphics, physics, events, _| {
|
testbed.add_callback(move |mut graphics, physics, events, _| {
|
||||||
while let Ok(prox) = events.intersection_events.try_recv() {
|
while let Ok(prox) = events.intersection_events.try_recv() {
|
||||||
let color = if prox.intersecting {
|
let color = if prox.intersecting {
|
||||||
Point3::new(1.0, 1.0, 0.0)
|
[1.0, 1.0, 0.0]
|
||||||
} else {
|
} 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_handle1 = physics
|
||||||
let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
|
.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 let Some(graphics) = &mut graphics {
|
||||||
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
||||||
@@ -149,5 +153,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, InteractionGroups};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let floor_handle = bodies.insert(rigid_body);
|
let floor_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Setup groups
|
||||||
@@ -34,23 +32,24 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* A green floor that will collide with the GREEN group only.
|
* A green floor that will collide with the GREEN group only.
|
||||||
*/
|
*/
|
||||||
let green_floor = ColliderBuilder::cuboid(1.0, 0.1, 1.0)
|
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)
|
.collision_groups(GREEN_GROUP)
|
||||||
.build();
|
.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.
|
* A blue floor that will collide with the BLUE group only.
|
||||||
*/
|
*/
|
||||||
let blue_floor = ColliderBuilder::cuboid(1.0, 0.1, 1.0)
|
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)
|
.collision_groups(BLUE_GROUP)
|
||||||
.build();
|
.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
|
* Create the cubes
|
||||||
@@ -72,17 +71,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Alternate between the green and blue groups.
|
// Alternate between the green and blue groups.
|
||||||
let (group, color) = if k % 2 == 0 {
|
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 {
|
} 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad)
|
let collider = ColliderBuilder::cuboid(rad, rad, rad)
|
||||||
.collision_groups(group)
|
.collision_groups(group)
|
||||||
.build();
|
.build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
|
|
||||||
testbed.set_initial_body_color(handle, color);
|
testbed.set_initial_body_color(handle, color);
|
||||||
}
|
}
|
||||||
@@ -93,5 +94,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -46,40 +44,42 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shift * 2.0 - centerz + offset;
|
let z = k as f32 * shift * 2.0 - centerz + offset;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
// First option: attach several colliders to a single rigid-body.
|
// First option: attach several colliders to a single rigid-body.
|
||||||
if j < numy / 2 {
|
if j < numy / 2 {
|
||||||
let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad).build();
|
let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad).build();
|
||||||
let collider2 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
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();
|
.build();
|
||||||
let collider3 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
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();
|
.build();
|
||||||
colliders.insert(collider1, handle, &mut bodies);
|
colliders.insert_with_parent(collider1, handle, &mut bodies);
|
||||||
colliders.insert(collider2, handle, &mut bodies);
|
colliders.insert_with_parent(collider2, handle, &mut bodies);
|
||||||
colliders.insert(collider3, handle, &mut bodies);
|
colliders.insert_with_parent(collider3, handle, &mut bodies);
|
||||||
} else {
|
} else {
|
||||||
// Second option: create a compound shape and attach it to a single collider.
|
// Second option: create a compound shape and attach it to a single collider.
|
||||||
let shapes = vec![
|
let shapes = vec![
|
||||||
(
|
(
|
||||||
Isometry3::identity(),
|
Isometry::identity(),
|
||||||
SharedShape::cuboid(rad * 10.0, rad, rad),
|
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),
|
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),
|
SharedShape::cuboid(rad, rad * 10.0, rad),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
let collider = ColliderBuilder::compound(shapes).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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 obj::raw::object::Polygon;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
|
|
||||||
use rapier3d::parry::bounding_volume;
|
use rapier3d::parry::bounding_volume;
|
||||||
|
use rapier3d::prelude::*;
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
@@ -26,11 +24,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let ground_height = 0.1;
|
let ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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.
|
* Create the convex decompositions.
|
||||||
@@ -52,7 +50,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let mut vertices: Vec<_> = model
|
let mut vertices: Vec<_> = model
|
||||||
.positions
|
.positions
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| Point3::new(v.0, v.1, v.2))
|
.map(|v| point![v.0, v.1, v.2])
|
||||||
.collect();
|
.collect();
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
let indices: Vec<_> = model
|
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 y = (igeom / width) as f32 * shift + 4.0;
|
||||||
let z = k as f32 * shift;
|
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);
|
let handle = bodies.insert(body);
|
||||||
|
|
||||||
for shape in &shapes {
|
for shape in &shapes {
|
||||||
let collider = ColliderBuilder::new(shape.clone()).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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> {
|
fn models() -> Vec<String> {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use na::Point3;
|
|
||||||
use rand::distributions::{Distribution, Standard};
|
use rand::distributions::{Distribution, Standard};
|
||||||
use rand::{rngs::StdRng, SeedableRng};
|
use rand::{rngs::StdRng, SeedableRng};
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the polyhedra
|
||||||
@@ -50,17 +48,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
let mut points = Vec::new();
|
let mut points = Vec::new();
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
let pt: Point3<f32> = distribution.sample(&mut rng);
|
let pt: Point<f32> = distribution.sample(&mut rng);
|
||||||
points.push(pt * scale);
|
points.push(pt * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::round_convex_hull(&points, border_rad)
|
let collider = ColliderBuilder::round_convex_hull(&points, border_rad)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build();
|
.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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -24,9 +22,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Build the rigid body.
|
// Build the rigid body.
|
||||||
let rb = RigidBodyBuilder::new_dynamic()
|
let rb = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(x, y, 0.0)
|
.translation(vector![x, y, 0.0])
|
||||||
.linvel(x * 10.0, y * 10.0, 0.0)
|
.linvel(vector![x * 10.0, y * 10.0, 0.0])
|
||||||
.angvel(Vector3::z() * 100.0)
|
.angvel(Vector::z() * 100.0)
|
||||||
.linear_damping((i + 1) as f32 * subdiv * 10.0)
|
.linear_damping((i + 1) as f32 * subdiv * 10.0)
|
||||||
.angular_damping((num - i) as f32 * subdiv * 10.0)
|
.angular_damping((num - i) as f32 * subdiv * 10.0)
|
||||||
.build();
|
.build();
|
||||||
@@ -34,12 +32,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Build the collider.
|
// Build the collider.
|
||||||
let co = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world_with_params(bodies, colliders, joints, Vector3::zeros(), ());
|
testbed.set_world_with_params(bodies, colliders, joints, Vector::zeros(), ());
|
||||||
testbed.look_at(Point3::new(2.0, 2.5, 20.0), Point3::new(2.0, 2.5, 0.0));
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4).build();
|
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
|
* Rolling ball
|
||||||
*/
|
*/
|
||||||
let ball_rad = 0.1;
|
let ball_rad = 0.1;
|
||||||
let rb = RigidBodyBuilder::new_dynamic()
|
let rb = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 0.2, 0.0)
|
.translation(vector![0.0, 0.2, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ball_handle = bodies.insert(rb);
|
let ball_handle = bodies.insert(rb);
|
||||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
|
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, _, _| {
|
testbed.add_callback(move |_, physics, _, _| {
|
||||||
// Remove then re-add the ground collider.
|
// Remove then re-add the ground collider.
|
||||||
@@ -46,14 +45,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
ground_collider_handle = physics
|
ground_collider_handle =
|
||||||
|
physics
|
||||||
.colliders
|
.colliders
|
||||||
.insert(coll, ground_handle, &mut physics.bodies);
|
.insert_with_parent(coll, ground_handle, &mut physics.bodies);
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, HalfSpace, SharedShape};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
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();
|
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_y = 0.0;
|
||||||
let mut curr_width = 10_000.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;
|
curr_y += curr_height * 4.0;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, curr_y, 0.0)
|
.translation(vector![0.0, curr_y, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(curr_width, curr_height, curr_width).build();
|
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;
|
curr_width /= 5.0;
|
||||||
}
|
}
|
||||||
@@ -41,5 +39,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -19,28 +17,28 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
for _ in 0..6 {
|
for _ in 0..6 {
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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.
|
// Build the dynamic box rigid body.
|
||||||
for _ in 0..6 {
|
for _ in 0..6 {
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(1.1, 0.0, 0.0)
|
.translation(vector![1.1, 0.0, 0.0])
|
||||||
.rotation(Vector3::new(0.8, 0.2, 0.1))
|
.rotation(vector![0.8, 0.2, 0.1])
|
||||||
.can_sleep(false)
|
.can_sleep(false)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(2.0, 0.1, 1.0).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
// This shows a bug when a cylinder is in contact with a very large
|
// 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -47,14 +45,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = -centerz + offset;
|
let z = -centerz + offset;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cylinder(rad, rad).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4)
|
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4)
|
||||||
.friction(0.15)
|
.friction(0.15)
|
||||||
// .restitution(0.5)
|
// .restitution(0.5)
|
||||||
.build();
|
.build();
|
||||||
colliders.insert(collider, ground_handle, &mut bodies);
|
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rolling ball
|
* Rolling ball
|
||||||
*/
|
*/
|
||||||
let ball_rad = 0.1;
|
let ball_rad = 0.1;
|
||||||
let rb = RigidBodyBuilder::new_dynamic()
|
let rb = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 0.2, 0.0)
|
.translation(vector![0.0, 0.2, 0.0])
|
||||||
.linvel(10.0, 0.0, 0.0)
|
.linvel(vector![10.0, 0.0, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ball_handle = bodies.insert(rb);
|
let ball_handle = bodies.insert(rb);
|
||||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
|
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 linvel = Vector::zeros();
|
||||||
let mut angvel = Vector3::zeros();
|
let mut angvel = Vector::zeros();
|
||||||
let mut pos = Isometry3::identity();
|
let mut pos = Isometry::identity();
|
||||||
let mut step = 0;
|
let mut step = 0;
|
||||||
let mut extra_colliders = Vec::new();
|
let mut extra_colliders = Vec::new();
|
||||||
let snapped_frame = 51;
|
let snapped_frame = 51;
|
||||||
@@ -55,7 +53,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let new_ball_collider_handle =
|
let new_ball_collider_handle =
|
||||||
physics
|
physics
|
||||||
.colliders
|
.colliders
|
||||||
.insert(collider, ball_handle, &mut physics.bodies);
|
.insert_with_parent(collider, ball_handle, &mut physics.bodies);
|
||||||
|
|
||||||
if let Some(graphics) = &mut graphics {
|
if let Some(graphics) = &mut graphics {
|
||||||
graphics.add_collider(new_ball_collider_handle, &physics.colliders);
|
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.
|
// Remove then re-add the ground collider.
|
||||||
// let ground = physics.bodies.get_mut(ground_handle).unwrap();
|
// 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
|
// let coll = physics
|
||||||
// .colliders
|
// .colliders
|
||||||
// .remove(ground_collider_handle, &mut physics.bodies, true)
|
// .remove(ground_collider_handle, &mut physics.bodies, true)
|
||||||
@@ -104,7 +102,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let new_ground_collider_handle =
|
let new_ground_collider_handle =
|
||||||
physics
|
physics
|
||||||
.colliders
|
.colliders
|
||||||
.insert(coll, ground_handle, &mut physics.bodies);
|
.insert_with_parent(coll, ground_handle, &mut physics.bodies);
|
||||||
|
|
||||||
if let Some(graphics) = &mut graphics {
|
if let Some(graphics) = &mut graphics {
|
||||||
graphics.add_collider(new_ground_collider_handle, &physics.colliders);
|
graphics.add_collider(new_ground_collider_handle, &physics.colliders);
|
||||||
@@ -117,5 +115,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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)
|
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size)
|
||||||
.friction(1.5)
|
.friction(1.5)
|
||||||
.build();
|
.build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
|
|
||||||
// Build a dynamic box rigid body.
|
// Build a dynamic box rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 1.1, 0.0)
|
.translation(vector![0.0, 1.1, 0.0])
|
||||||
.rotation(Vector3::y() * 0.3)
|
.rotation(Vector::y() * 0.3)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(2.0, 1.0, 3.0).friction(1.5).build();
|
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 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);
|
rigid_body.set_linvel(force, true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 2.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, 4.0, 0.0)
|
.translation(vector![0.0, 4.0, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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;
|
let rad = 1.0;
|
||||||
// Build the dynamic box rigid body.
|
// Build the dynamic box rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
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)
|
.can_sleep(false)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
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()
|
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)
|
.can_sleep(false)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
let collider = ColliderBuilder::ball(rad).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the testbed.
|
* 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);
|
testbed.set_world(bodies, colliders, joints);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
use na::{Point3, Vector3};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
fn prismatic_repro(
|
fn prismatic_repro(
|
||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
joints: &mut JointSet,
|
joints: &mut JointSet,
|
||||||
box_center: Point3<f32>,
|
box_center: Point<f32>,
|
||||||
) {
|
) {
|
||||||
let box_rb = bodies.insert(
|
let box_rb = bodies.insert(
|
||||||
RigidBodyBuilder::new_dynamic()
|
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(),
|
.build(),
|
||||||
);
|
);
|
||||||
colliders.insert(
|
colliders.insert_with_parent(
|
||||||
ColliderBuilder::cuboid(1.0, 0.25, 1.0).build(),
|
ColliderBuilder::cuboid(1.0, 0.25, 1.0).build(),
|
||||||
box_rb,
|
box_rb,
|
||||||
bodies,
|
bodies,
|
||||||
@@ -22,32 +20,32 @@ fn prismatic_repro(
|
|||||||
|
|
||||||
let wheel_y = -1.0;
|
let wheel_y = -1.0;
|
||||||
let wheel_positions = vec![
|
let wheel_positions = vec![
|
||||||
Vector3::new(1.0, wheel_y, -1.0),
|
vector![1.0, wheel_y, -1.0],
|
||||||
Vector3::new(-1.0, wheel_y, -1.0),
|
vector![-1.0, wheel_y, -1.0],
|
||||||
Vector3::new(1.0, wheel_y, 1.0),
|
vector![1.0, wheel_y, 1.0],
|
||||||
Vector3::new(-1.0, wheel_y, 1.0),
|
vector![-1.0, wheel_y, 1.0],
|
||||||
];
|
];
|
||||||
|
|
||||||
for pos in wheel_positions {
|
for pos in wheel_positions {
|
||||||
let wheel_pos_in_world = box_center + pos;
|
let wheel_pos_in_world = box_center + pos;
|
||||||
let wheel_rb = bodies.insert(
|
let wheel_rb = bodies.insert(
|
||||||
RigidBodyBuilder::new_dynamic()
|
RigidBodyBuilder::new_dynamic()
|
||||||
.translation(
|
.translation(vector![
|
||||||
wheel_pos_in_world.x,
|
wheel_pos_in_world.x,
|
||||||
wheel_pos_in_world.y,
|
wheel_pos_in_world.y,
|
||||||
wheel_pos_in_world.z,
|
wheel_pos_in_world.z
|
||||||
)
|
])
|
||||||
.build(),
|
.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(
|
let mut prismatic = rapier3d::dynamics::PrismaticJoint::new(
|
||||||
Point3::new(pos.x, pos.y, pos.z),
|
point![pos.x, pos.y, pos.z],
|
||||||
Vector3::y_axis(),
|
Vector::y_axis(),
|
||||||
Vector3::default(),
|
Vector::zeros(),
|
||||||
Point3::new(0.0, 0.0, 0.0),
|
Point::origin(),
|
||||||
Vector3::y_axis(),
|
Vector::y_axis(),
|
||||||
Vector3::default(),
|
Vector::default(),
|
||||||
);
|
);
|
||||||
prismatic.configure_motor_model(rapier3d::dynamics::SpringModel::VelocityBased);
|
prismatic.configure_motor_model(rapier3d::dynamics::SpringModel::VelocityBased);
|
||||||
let (stiffness, damping) = (0.05, 0.2);
|
let (stiffness, damping) = (0.05, 0.2);
|
||||||
@@ -59,10 +57,10 @@ fn prismatic_repro(
|
|||||||
// put a small box under one of the wheels
|
// put a small box under one of the wheels
|
||||||
let gravel = bodies.insert(
|
let gravel = bodies.insert(
|
||||||
RigidBodyBuilder::new_dynamic()
|
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(),
|
.build(),
|
||||||
);
|
);
|
||||||
colliders.insert(
|
colliders.insert_with_parent(
|
||||||
ColliderBuilder::cuboid(0.5, 0.1, 0.5).build(),
|
ColliderBuilder::cuboid(0.5, 0.1, 0.5).build(),
|
||||||
gravel,
|
gravel,
|
||||||
bodies,
|
bodies,
|
||||||
@@ -84,22 +82,22 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let ground_height = 0.1;
|
let ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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(
|
prismatic_repro(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
&mut joints,
|
&mut joints,
|
||||||
Point3::new(0.0, 5.0, 0.0),
|
point![0.0, 5.0, 0.0],
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4)
|
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4)
|
||||||
.friction(0.15)
|
.friction(0.15)
|
||||||
// .restitution(0.5)
|
// .restitution(0.5)
|
||||||
.build();
|
.build();
|
||||||
colliders.insert(collider, ground_handle, &mut bodies);
|
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rolling ball
|
* Rolling ball
|
||||||
*/
|
*/
|
||||||
let ball_rad = 0.1;
|
let ball_rad = 0.1;
|
||||||
let rb = RigidBodyBuilder::new_dynamic()
|
let rb = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 0.2, 0.0)
|
.translation(vector![0.0, 0.2, 0.0])
|
||||||
.linvel(10.0, 0.0, 0.0)
|
.linvel(vector![10.0, 0.0, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ball_handle = bodies.insert(rb);
|
let ball_handle = bodies.insert(rb);
|
||||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
|
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 linvel = Vector::zeros();
|
||||||
let mut angvel = Vector3::zeros();
|
let mut angvel = Vector::zeros();
|
||||||
let mut pos = Isometry3::identity();
|
let mut pos = Isometry::identity();
|
||||||
let mut step = 0;
|
let mut step = 0;
|
||||||
let snapped_frame = 51;
|
let snapped_frame = 51;
|
||||||
|
|
||||||
@@ -68,5 +66,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size)
|
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size)
|
||||||
.friction(0.15)
|
.friction(0.15)
|
||||||
// .restitution(0.5)
|
// .restitution(0.5)
|
||||||
.build();
|
.build();
|
||||||
colliders.insert(collider, ground_handle, &mut bodies);
|
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rolling ball
|
* Rolling ball
|
||||||
*/
|
*/
|
||||||
let ball_rad = 0.1;
|
let ball_rad = 0.1;
|
||||||
let rb = RigidBodyBuilder::new_dynamic()
|
let rb = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 0.2, 0.0)
|
.translation(vector![0.0, 0.2, 0.0])
|
||||||
.linvel(10.0, 0.0, 0.0)
|
.linvel(vector![10.0, 0.0, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ball_handle = bodies.insert(rb);
|
let ball_handle = bodies.insert(rb);
|
||||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0).build();
|
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 linvel = Vector::zeros();
|
||||||
let mut angvel = Vector3::zeros();
|
let mut angvel = Vector::zeros();
|
||||||
let mut pos = Isometry3::identity();
|
let mut pos = Isometry::identity();
|
||||||
let mut step = 0;
|
let mut step = 0;
|
||||||
let snapped_frame = 51;
|
let snapped_frame = 51;
|
||||||
|
|
||||||
@@ -90,7 +88,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shiftz - centerz + offset;
|
let z = k as f32 * shiftz - centerz + offset;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
let collider = match j % 5 {
|
let collider = match j % 5 {
|
||||||
@@ -103,7 +103,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
_ => ColliderBuilder::capsule_y(rad, rad).build(),
|
_ => 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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -13,31 +11,31 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Triangle ground.
|
// Triangle ground.
|
||||||
let vtx = [
|
let vtx = [
|
||||||
Point3::new(-10.0, 0.0, -10.0),
|
point![-10.0, 0.0, -10.0],
|
||||||
Point3::new(10.0, 0.0, -10.0),
|
point![10.0, 0.0, -10.0],
|
||||||
Point3::new(0.0, 0.0, 10.0),
|
point![0.0, 0.0, 10.0],
|
||||||
];
|
];
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, 0.0, 0.0)
|
.translation(vector![0.0, 0.0, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::triangle(vtx[0], vtx[1], vtx[2]).build();
|
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.
|
// Dynamic box rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
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))
|
// .rotation(Vector3::new(0.8, 0.2, 0.1))
|
||||||
.can_sleep(false)
|
.can_sleep(false)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(20.0, 0.1, 1.0).build();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -14,14 +12,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
// Triangle ground.
|
// Triangle ground.
|
||||||
let width = 0.5;
|
let width = 0.5;
|
||||||
let vtx = vec![
|
let vtx = vec![
|
||||||
Point3::new(-width, 0.0, -width),
|
point![-width, 0.0, -width],
|
||||||
Point3::new(width, 0.0, -width),
|
point![width, 0.0, -width],
|
||||||
Point3::new(width, 0.0, width),
|
point![width, 0.0, width],
|
||||||
Point3::new(-width, 0.0, width),
|
point![-width, 0.0, width],
|
||||||
Point3::new(-width, -width, -width),
|
point![-width, -width, -width],
|
||||||
Point3::new(width, -width, -width),
|
point![width, -width, -width],
|
||||||
Point3::new(width, -width, width),
|
point![width, -width, width],
|
||||||
Point3::new(-width, -width, width),
|
point![-width, -width, width],
|
||||||
];
|
];
|
||||||
let idx = vec![
|
let idx = vec![
|
||||||
[0, 2, 1],
|
[0, 2, 1],
|
||||||
@@ -40,25 +38,25 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Dynamic box rigid body.
|
// Dynamic box rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
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))
|
// .rotation(Vector3::new(0.8, 0.2, 0.1))
|
||||||
.can_sleep(false)
|
.can_sleep(false)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.0).build();
|
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()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, 0.0, 0.0)
|
.translation(vector![0.0, 0.0, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::trimesh(vtx, idx).build();
|
let collider = ColliderBuilder::trimesh(vtx, idx).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
testbed.set_initial_body_color(handle, Point3::new(0.3, 0.3, 0.3));
|
testbed.set_initial_body_color(handle, [0.3, 0.3, 0.3]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -31,7 +29,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let width = 1.0;
|
let width = 1.0;
|
||||||
let thickness = 0.1;
|
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_angle = 0.0;
|
||||||
let mut curr_rad = 10.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 };
|
let tilt = if nudged || i == num - 1 { 0.2 } else { 0.0 };
|
||||||
|
|
||||||
if skip == 0 {
|
if skip == 0 {
|
||||||
let rot = UnitQuaternion::new(Vector3::y() * curr_angle);
|
let rot = Rotation::new(Vector::y() * curr_angle);
|
||||||
let tilt = UnitQuaternion::new(rot * Vector3::z() * tilt);
|
let tilt = Rotation::new(rot * Vector::z() * tilt);
|
||||||
let position =
|
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
|
* tilt
|
||||||
* rot;
|
* rot;
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic().position(position).build();
|
let rigid_body = RigidBodyBuilder::new_dynamic().position(position).build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(thickness, width * 2.0, width).build();
|
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]);
|
testbed.set_initial_body_color(handle, colors[i % 2]);
|
||||||
} else {
|
} else {
|
||||||
skip -= 1;
|
skip -= 1;
|
||||||
@@ -76,5 +74,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
const MAX_NUMBER_OF_BODIES: usize = 400;
|
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 ground_height = 2.1; // 16.0;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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.
|
// Callback that will be executed on the main loop to handle proximities.
|
||||||
testbed.add_callback(move |mut graphics, physics, _, run_state| {
|
testbed.add_callback(move |mut graphics, physics, _, run_state| {
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 10.0, 0.0)
|
.translation(vector![0.0, 10.0, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = physics.bodies.insert(rigid_body);
|
let handle = physics.bodies.insert(rigid_body);
|
||||||
let collider = match run_state.timestep_id % 3 {
|
let collider = match run_state.timestep_id % 3 {
|
||||||
@@ -38,7 +36,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
physics
|
physics
|
||||||
.colliders
|
.colliders
|
||||||
.insert(collider, handle, &mut physics.bodies);
|
.insert_with_parent(collider, handle, &mut physics.bodies);
|
||||||
|
|
||||||
if let Some(graphics) = &mut graphics {
|
if let Some(graphics) = &mut graphics {
|
||||||
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
||||||
@@ -83,5 +81,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
// .physics_state_mut()
|
// .physics_state_mut()
|
||||||
// .integration_parameters
|
// .integration_parameters
|
||||||
// .velocity_based_erp = 0.2;
|
// .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::prelude::*;
|
||||||
|
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::harness::Harness;
|
use rapier_testbed3d::harness::Harness;
|
||||||
|
|
||||||
pub fn init_world(harness: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -47,10 +44,12 @@ pub fn init_world(harness: &mut Harness) {
|
|||||||
let z = k as f32 * shift - centerz + offset;
|
let z = k as f32 * shift - centerz + offset;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::capsule_y(rad, rad).build();
|
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 na::ComplexField;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, SharedShape};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
/*
|
/*
|
||||||
* Ground
|
* 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 nsubdivs = 20;
|
||||||
|
|
||||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::heightfield(heights, ground_size).build();
|
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
|
* Create the cubes
|
||||||
@@ -55,7 +54,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shift - centerz;
|
let z = k as f32 * shift - centerz;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
let collider = match j % 6 {
|
let collider = match j % 6 {
|
||||||
@@ -69,15 +70,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
_ => {
|
_ => {
|
||||||
let shapes = vec![
|
let shapes = vec![
|
||||||
(
|
(
|
||||||
Isometry3::identity(),
|
Isometry::identity(),
|
||||||
SharedShape::cuboid(rad, rad / 2.0, rad / 2.0),
|
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),
|
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),
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{
|
|
||||||
BallJoint, FixedJoint, JointSet, PrismaticJoint, RevoluteJoint, RigidBodyBuilder,
|
|
||||||
RigidBodyHandle, RigidBodySet, RigidBodyType,
|
|
||||||
};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
fn create_prismatic_joints(
|
fn create_prismatic_joints(
|
||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
joints: &mut JointSet,
|
joints: &mut JointSet,
|
||||||
origin: Point3<f32>,
|
origin: Point<f32>,
|
||||||
num: usize,
|
num: usize,
|
||||||
) {
|
) {
|
||||||
let rad = 0.4;
|
let rad = 0.4;
|
||||||
let shift = 2.0;
|
let shift = 2.0;
|
||||||
|
|
||||||
let ground = RigidBodyBuilder::new_static()
|
let ground = RigidBodyBuilder::new_static()
|
||||||
.translation(origin.x, origin.y, origin.z)
|
.translation(vector![origin.x, origin.y, origin.z])
|
||||||
.build();
|
.build();
|
||||||
let mut curr_parent = bodies.insert(ground);
|
let mut curr_parent = bodies.insert(ground);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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 {
|
for i in 0..num {
|
||||||
let z = origin.z + (i + 1) as f32 * shift;
|
let z = origin.z + (i + 1) as f32 * shift;
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(origin.x, origin.y, z)
|
.translation(vector![origin.x, origin.y, z])
|
||||||
.build();
|
.build();
|
||||||
let curr_child = bodies.insert(rigid_body);
|
let curr_child = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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 {
|
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 {
|
} 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(
|
let mut prism = PrismaticJoint::new(
|
||||||
Point3::new(0.0, 0.0, 0.0),
|
point![0.0, 0.0, 0.0],
|
||||||
axis,
|
axis,
|
||||||
z,
|
z,
|
||||||
Point3::new(0.0, 0.0, -shift),
|
point![0.0, 0.0, -shift],
|
||||||
axis,
|
axis,
|
||||||
z,
|
z,
|
||||||
);
|
);
|
||||||
@@ -61,40 +56,40 @@ fn create_actuated_prismatic_joints(
|
|||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
joints: &mut JointSet,
|
joints: &mut JointSet,
|
||||||
origin: Point3<f32>,
|
origin: Point<f32>,
|
||||||
num: usize,
|
num: usize,
|
||||||
) {
|
) {
|
||||||
let rad = 0.4;
|
let rad = 0.4;
|
||||||
let shift = 2.0;
|
let shift = 2.0;
|
||||||
|
|
||||||
let ground = RigidBodyBuilder::new_static()
|
let ground = RigidBodyBuilder::new_static()
|
||||||
.translation(origin.x, origin.y, origin.z)
|
.translation(vector![origin.x, origin.y, origin.z])
|
||||||
.build();
|
.build();
|
||||||
let mut curr_parent = bodies.insert(ground);
|
let mut curr_parent = bodies.insert(ground);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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 {
|
for i in 0..num {
|
||||||
let z = origin.z + (i + 1) as f32 * shift;
|
let z = origin.z + (i + 1) as f32 * shift;
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(origin.x, origin.y, z)
|
.translation(vector![origin.x, origin.y, z])
|
||||||
.build();
|
.build();
|
||||||
let curr_child = bodies.insert(rigid_body);
|
let curr_child = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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 {
|
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 {
|
} 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(
|
let mut prism = PrismaticJoint::new(
|
||||||
Point3::new(0.0, 0.0, 0.0),
|
point![0.0, 0.0, 0.0],
|
||||||
axis,
|
axis,
|
||||||
z,
|
z,
|
||||||
Point3::new(0.0, 0.0, -shift),
|
point![0.0, 0.0, -shift],
|
||||||
axis,
|
axis,
|
||||||
z,
|
z,
|
||||||
);
|
);
|
||||||
@@ -128,27 +123,27 @@ fn create_revolute_joints(
|
|||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
joints: &mut JointSet,
|
joints: &mut JointSet,
|
||||||
origin: Point3<f32>,
|
origin: Point<f32>,
|
||||||
num: usize,
|
num: usize,
|
||||||
) {
|
) {
|
||||||
let rad = 0.4;
|
let rad = 0.4;
|
||||||
let shift = 2.0;
|
let shift = 2.0;
|
||||||
|
|
||||||
let ground = RigidBodyBuilder::new_static()
|
let ground = RigidBodyBuilder::new_static()
|
||||||
.translation(origin.x, origin.y, 0.0)
|
.translation(vector![origin.x, origin.y, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let mut curr_parent = bodies.insert(ground);
|
let mut curr_parent = bodies.insert(ground);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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 {
|
for i in 0..num {
|
||||||
// Create four bodies.
|
// Create four bodies.
|
||||||
let z = origin.z + i as f32 * shift * 2.0 + shift;
|
let z = origin.z + i as f32 * shift * 2.0 + shift;
|
||||||
let positions = [
|
let positions = [
|
||||||
Isometry3::translation(origin.x, origin.y, z),
|
Isometry::translation(origin.x, origin.y, z),
|
||||||
Isometry3::translation(origin.x + shift, origin.y, z),
|
Isometry::translation(origin.x + shift, origin.y, z),
|
||||||
Isometry3::translation(origin.x + shift, origin.y, z + shift),
|
Isometry::translation(origin.x + shift, origin.y, z + shift),
|
||||||
Isometry3::translation(origin.x, origin.y, z + shift),
|
Isometry::translation(origin.x, origin.y, z + shift),
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut handles = [curr_parent; 4];
|
let mut handles = [curr_parent; 4];
|
||||||
@@ -158,19 +153,19 @@ fn create_revolute_joints(
|
|||||||
.build();
|
.build();
|
||||||
handles[k] = bodies.insert(rigid_body);
|
handles[k] = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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.
|
// Setup four joints.
|
||||||
let o = Point3::origin();
|
let o = Point::origin();
|
||||||
let x = Vector3::x_axis();
|
let x = Vector::x_axis();
|
||||||
let z = Vector3::z_axis();
|
let z = Vector::z_axis();
|
||||||
|
|
||||||
let revs = [
|
let revs = [
|
||||||
RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z),
|
RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z),
|
||||||
RevoluteJoint::new(o, x, Point3::new(-shift, 0.0, 0.0), x),
|
RevoluteJoint::new(o, x, point![-shift, 0.0, 0.0], x),
|
||||||
RevoluteJoint::new(o, z, Point3::new(0.0, 0.0, -shift), z),
|
RevoluteJoint::new(o, z, point![0.0, 0.0, -shift], z),
|
||||||
RevoluteJoint::new(o, x, Point3::new(shift, 0.0, 0.0), x),
|
RevoluteJoint::new(o, x, point![shift, 0.0, 0.0], x),
|
||||||
];
|
];
|
||||||
|
|
||||||
joints.insert(bodies, curr_parent, handles[0], revs[0]);
|
joints.insert(bodies, curr_parent, handles[0], revs[0]);
|
||||||
@@ -186,7 +181,7 @@ fn create_fixed_joints(
|
|||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
joints: &mut JointSet,
|
joints: &mut JointSet,
|
||||||
origin: Point3<f32>,
|
origin: Point<f32>,
|
||||||
num: usize,
|
num: usize,
|
||||||
) {
|
) {
|
||||||
let rad = 0.4;
|
let rad = 0.4;
|
||||||
@@ -209,18 +204,22 @@ fn create_fixed_joints(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new(status)
|
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();
|
.build();
|
||||||
let child_handle = bodies.insert(rigid_body);
|
let child_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad).build();
|
let collider = ColliderBuilder::ball(rad).build();
|
||||||
colliders.insert(collider, child_handle, bodies);
|
colliders.insert_with_parent(collider, child_handle, bodies);
|
||||||
|
|
||||||
// Vertical joint.
|
// Vertical joint.
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
let parent_handle = *body_handles.last().unwrap();
|
let parent_handle = *body_handles.last().unwrap();
|
||||||
let joint = FixedJoint::new(
|
let joint = FixedJoint::new(
|
||||||
Isometry3::identity(),
|
Isometry::identity(),
|
||||||
Isometry3::translation(0.0, 0.0, -shift),
|
Isometry::translation(0.0, 0.0, -shift),
|
||||||
);
|
);
|
||||||
joints.insert(bodies, parent_handle, child_handle, joint);
|
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_index = body_handles.len() - num;
|
||||||
let parent_handle = body_handles[parent_index];
|
let parent_handle = body_handles[parent_index];
|
||||||
let joint = FixedJoint::new(
|
let joint = FixedJoint::new(
|
||||||
Isometry3::identity(),
|
Isometry::identity(),
|
||||||
Isometry3::translation(-shift, 0.0, 0.0),
|
Isometry::translation(-shift, 0.0, 0.0),
|
||||||
);
|
);
|
||||||
joints.insert(bodies, parent_handle, child_handle, joint);
|
joints.insert(bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
@@ -264,16 +263,16 @@ fn create_ball_joints(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new(status)
|
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();
|
.build();
|
||||||
let child_handle = bodies.insert(rigid_body);
|
let child_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::capsule_z(rad * 1.25, rad).build();
|
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.
|
// Vertical joint.
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
let parent_handle = *body_handles.last().unwrap();
|
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);
|
joints.insert(bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +280,7 @@ fn create_ball_joints(
|
|||||||
if k > 0 {
|
if k > 0 {
|
||||||
let parent_index = body_handles.len() - num;
|
let parent_index = body_handles.len() - num;
|
||||||
let parent_handle = body_handles[parent_index];
|
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);
|
joints.insert(bodies, parent_handle, child_handle, joint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,7 +293,7 @@ fn create_actuated_revolute_joints(
|
|||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
joints: &mut JointSet,
|
joints: &mut JointSet,
|
||||||
origin: Point3<f32>,
|
origin: Point<f32>,
|
||||||
num: usize,
|
num: usize,
|
||||||
) {
|
) {
|
||||||
let rad = 0.4;
|
let rad = 0.4;
|
||||||
@@ -302,10 +301,10 @@ fn create_actuated_revolute_joints(
|
|||||||
|
|
||||||
// We will reuse this base configuration for all the joints here.
|
// We will reuse this base configuration for all the joints here.
|
||||||
let joint_template = RevoluteJoint::new(
|
let joint_template = RevoluteJoint::new(
|
||||||
Point3::origin(),
|
Point::origin(),
|
||||||
Vector3::z_axis(),
|
Vector::z_axis(),
|
||||||
Point3::new(0.0, 0.0, -shift),
|
point![0.0, 0.0, -shift],
|
||||||
Vector3::z_axis(),
|
Vector::z_axis(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut parent_handle = RigidBodyHandle::invalid();
|
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 shifty = (i >= 1) as u32 as f32 * -2.0;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new(status)
|
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))
|
// .rotation(Vector3::new(0.0, fi * 1.1, 0.0))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let child_handle = bodies.insert(rigid_body);
|
let child_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad * 2.0, rad * 6.0 / (fi + 1.0), rad).build();
|
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 {
|
if i > 0 {
|
||||||
let mut joint = joint_template.clone();
|
let mut joint = joint_template.clone();
|
||||||
@@ -360,14 +359,14 @@ fn create_actuated_ball_joints(
|
|||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
joints: &mut JointSet,
|
joints: &mut JointSet,
|
||||||
origin: Point3<f32>,
|
origin: Point<f32>,
|
||||||
num: usize,
|
num: usize,
|
||||||
) {
|
) {
|
||||||
let rad = 0.4;
|
let rad = 0.4;
|
||||||
let shift = 2.0;
|
let shift = 2.0;
|
||||||
|
|
||||||
// We will reuse this base configuration for all the joints here.
|
// 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();
|
let mut parent_handle = RigidBodyHandle::invalid();
|
||||||
|
|
||||||
@@ -384,24 +383,24 @@ fn create_actuated_ball_joints(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new(status)
|
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))
|
// .rotation(Vector3::new(0.0, fi * 1.1, 0.0))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let child_handle = bodies.insert(rigid_body);
|
let child_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::capsule_y(rad * 2.0 / (fi + 1.0), rad).build();
|
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 {
|
if i > 0 {
|
||||||
let mut joint = joint_template.clone();
|
let mut joint = joint_template.clone();
|
||||||
|
|
||||||
if i == 1 {
|
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 {
|
} else if i == num - 1 {
|
||||||
let stiffness = 0.2;
|
let stiffness = 0.2;
|
||||||
let damping = 1.0;
|
let damping = 1.0;
|
||||||
joint.configure_motor_position(
|
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,
|
stiffness,
|
||||||
damping,
|
damping,
|
||||||
);
|
);
|
||||||
@@ -426,42 +425,42 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
&mut joints,
|
&mut joints,
|
||||||
Point3::new(20.0, 5.0, 0.0),
|
point![20.0, 5.0, 0.0],
|
||||||
4,
|
4,
|
||||||
);
|
);
|
||||||
create_actuated_prismatic_joints(
|
create_actuated_prismatic_joints(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
&mut joints,
|
&mut joints,
|
||||||
Point3::new(25.0, 5.0, 0.0),
|
point![25.0, 5.0, 0.0],
|
||||||
4,
|
4,
|
||||||
);
|
);
|
||||||
create_revolute_joints(
|
create_revolute_joints(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
&mut joints,
|
&mut joints,
|
||||||
Point3::new(20.0, 0.0, 0.0),
|
point![20.0, 0.0, 0.0],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
create_fixed_joints(
|
create_fixed_joints(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
&mut joints,
|
&mut joints,
|
||||||
Point3::new(0.0, 10.0, 0.0),
|
point![0.0, 10.0, 0.0],
|
||||||
10,
|
10,
|
||||||
);
|
);
|
||||||
create_actuated_revolute_joints(
|
create_actuated_revolute_joints(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
&mut joints,
|
&mut joints,
|
||||||
Point3::new(20.0, 10.0, 0.0),
|
point![20.0, 10.0, 0.0],
|
||||||
6,
|
6,
|
||||||
);
|
);
|
||||||
create_actuated_ball_joints(
|
create_actuated_ball_joints(
|
||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
&mut joints,
|
&mut joints,
|
||||||
Point3::new(13.0, 10.0, 0.0),
|
point![13.0, 10.0, 0.0],
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
create_ball_joints(&mut bodies, &mut colliders, &mut joints, 15);
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn build_block(
|
pub fn build_block(
|
||||||
testbed: &mut Testbed,
|
testbed: &mut Testbed,
|
||||||
bodies: &mut RigidBodySet,
|
bodies: &mut RigidBodySet,
|
||||||
colliders: &mut ColliderSet,
|
colliders: &mut ColliderSet,
|
||||||
half_extents: Vector3<f32>,
|
half_extents: Vector<f32>,
|
||||||
shift: Vector3<f32>,
|
shift: Vector<f32>,
|
||||||
mut numx: usize,
|
mut numx: usize,
|
||||||
numy: usize,
|
numy: usize,
|
||||||
mut numz: 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_width = 2.0 * half_extents.z * numx as f32;
|
||||||
let block_height = 2.0 * half_extents.y * numy 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 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 color0 = [0.7, 0.5, 0.9];
|
||||||
let mut color1 = Point3::new(0.6, 1.0, 0.6);
|
let mut color1 = [0.6, 1.0, 0.6];
|
||||||
|
|
||||||
for i in 0..numy {
|
for i in 0..numy {
|
||||||
std::mem::swap(&mut numx, &mut numz);
|
std::mem::swap(&mut numx, &mut numz);
|
||||||
@@ -41,15 +39,15 @@ pub fn build_block(
|
|||||||
|
|
||||||
// Build the rigid body.
|
// Build the rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(
|
.translation(vector![
|
||||||
x + dim.x + shift.x,
|
x + dim.x + shift.x,
|
||||||
y + dim.y + shift.y,
|
y + dim.y + shift.y,
|
||||||
z + dim.z + shift.z,
|
z + dim.z + shift.z
|
||||||
)
|
])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
|
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);
|
testbed.set_initial_body_color(handle, color0);
|
||||||
std::mem::swap(&mut color0, &mut color1);
|
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 {
|
for j in 0..(block_width / (dim.z as f32 * 2.0)) as usize {
|
||||||
// Build the rigid body.
|
// Build the rigid body.
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(
|
.translation(vector![
|
||||||
i as f32 * dim.x * 2.0 + dim.x + shift.x,
|
i as f32 * dim.x * 2.0 + dim.x + shift.x,
|
||||||
dim.y + shift.y + block_height,
|
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();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z).build();
|
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);
|
testbed.set_initial_body_color(handle, color0);
|
||||||
std::mem::swap(&mut color0, &mut color1);
|
std::mem::swap(&mut color0, &mut color1);
|
||||||
}
|
}
|
||||||
@@ -94,16 +92,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let ground_height = 0.1;
|
let ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* 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;
|
let mut block_height = 0.0;
|
||||||
// These should only be set to odd values otherwise
|
// These should only be set to odd values otherwise
|
||||||
// the blocks won't align in the nicest way.
|
// the blocks won't align in the nicest way.
|
||||||
@@ -120,7 +118,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
&mut bodies,
|
&mut bodies,
|
||||||
&mut colliders,
|
&mut colliders,
|
||||||
half_extents,
|
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,
|
numx,
|
||||||
numy,
|
numy,
|
||||||
numz,
|
numz,
|
||||||
@@ -135,5 +133,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
// This shows a bug when a cylinder is in contact with a very large
|
// 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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.
|
* A rectangle that only rotates along the `x` axis.
|
||||||
*/
|
*/
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 3.0, 0.0)
|
.translation(vector![0.0, 3.0, 0.0])
|
||||||
.lock_translations()
|
.lock_translations()
|
||||||
.restrict_rotations(true, false, false)
|
.restrict_rotations(true, false, false)
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(0.2, 0.6, 2.0).build();
|
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.
|
* A tilted capsule that cannot rotate.
|
||||||
*/
|
*/
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
let rigid_body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 5.0, 0.0)
|
.translation(vector![0.0, 5.0, 0.0])
|
||||||
.rotation(Vector3::x() * 1.0)
|
.rotation(Vector::x() * 1.0)
|
||||||
.lock_rotations()
|
.lock_rotations()
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::capsule_y(0.6, 0.4).build();
|
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();
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderHandle, ColliderSet};
|
|
||||||
use rapier3d::pipeline::{ContactModificationContext, PhysicsHooks, PhysicsHooksFlags};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
struct OneWayPlatformHook {
|
struct OneWayPlatformHook {
|
||||||
@@ -10,10 +7,6 @@ struct OneWayPlatformHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
|
impl PhysicsHooks<RigidBodySet, ColliderSet> for OneWayPlatformHook {
|
||||||
fn active_hooks(&self) -> PhysicsHooksFlags {
|
|
||||||
PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS
|
|
||||||
}
|
|
||||||
|
|
||||||
fn modify_solver_contacts(
|
fn modify_solver_contacts(
|
||||||
&self,
|
&self,
|
||||||
context: &mut ContactModificationContext<RigidBodySet, ColliderSet>,
|
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.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.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.
|
// - 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 {
|
if context.collider1 == self.platform1 {
|
||||||
allowed_local_n1 = Vector3::y();
|
allowed_local_n1 = Vector::y();
|
||||||
} else if context.collider2 == self.platform1 {
|
} else if context.collider2 == self.platform1 {
|
||||||
// Flip the allowed direction.
|
// Flip the allowed direction.
|
||||||
allowed_local_n1 = -Vector3::y();
|
allowed_local_n1 = -Vector::y();
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.collider1 == self.platform2 {
|
if context.collider1 == self.platform2 {
|
||||||
allowed_local_n1 = -Vector3::y();
|
allowed_local_n1 = -Vector::y();
|
||||||
} else if context.collider2 == self.platform2 {
|
} else if context.collider2 == self.platform2 {
|
||||||
// Flip the allowed direction.
|
// Flip the allowed direction.
|
||||||
allowed_local_n1 = Vector3::y();
|
allowed_local_n1 = Vector::y();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the helper function that simulates one-way platforms.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0)
|
let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0)
|
||||||
.translation(0.0, 2.0, 30.0)
|
.translation(vector![0.0, 2.0, 30.0])
|
||||||
.modify_solver_contacts(true)
|
.active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS)
|
||||||
.build();
|
.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)
|
let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0)
|
||||||
.translation(0.0, -2.0, -30.0)
|
.translation(vector![0.0, -2.0, -30.0])
|
||||||
.modify_solver_contacts(true)
|
.active_hooks(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS)
|
||||||
.build();
|
.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.
|
* Setup the one-way platform hook.
|
||||||
@@ -105,12 +98,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
// Spawn a new cube.
|
// Spawn a new cube.
|
||||||
let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.5).build();
|
let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.5).build();
|
||||||
let body = RigidBodyBuilder::new_dynamic()
|
let body = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 6.0, 20.0)
|
.translation(vector![0.0, 6.0, 20.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = physics.bodies.insert(body);
|
let handle = physics.bodies.insert(body);
|
||||||
physics
|
physics
|
||||||
.colliders
|
.colliders
|
||||||
.insert(collider, handle, &mut physics.bodies);
|
.insert_with_parent(collider, handle, &mut physics.bodies);
|
||||||
|
|
||||||
if let Some(graphics) = graphics {
|
if let Some(graphics) = graphics {
|
||||||
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
graphics.add_body(handle, &physics.bodies, &physics.colliders);
|
||||||
@@ -134,8 +127,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
bodies,
|
bodies,
|
||||||
colliders,
|
colliders,
|
||||||
joints,
|
joints,
|
||||||
Vector3::new(0.0, -9.81, 0.0),
|
vector![0.0, -9.81, 0.0],
|
||||||
physics_hooks,
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the boxes
|
||||||
@@ -43,10 +41,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shift - centerz;
|
let z = k as f32 * shift - centerz;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,11 +55,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Setup a kinematic rigid body.
|
* Setup a kinematic rigid body.
|
||||||
*/
|
*/
|
||||||
let platform_body = RigidBodyBuilder::new_kinematic()
|
let platform_body = RigidBodyBuilder::new_kinematic()
|
||||||
.translation(0.0, 1.5 + 0.8, -10.0 * rad)
|
.translation(vector![0.0, 1.5 + 0.8, -10.0 * rad])
|
||||||
.build();
|
.build();
|
||||||
let platform_handle = bodies.insert(platform_body);
|
let platform_handle = bodies.insert(platform_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad * 10.0, rad, rad * 10.0).build();
|
let collider = ColliderBuilder::cuboid(rad * 10.0, rad, rad * 10.0).build();
|
||||||
colliders.insert(collider, platform_handle, &mut bodies);
|
colliders.insert_with_parent(collider, platform_handle, &mut bodies);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup a callback to control the platform.
|
* Setup a callback to control the platform.
|
||||||
@@ -93,5 +93,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Run the simulation.
|
* Run the simulation.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 2.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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
|
* Create the primitives
|
||||||
@@ -47,7 +45,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shiftz - centerz + offset;
|
let z = k as f32 * shiftz - centerz + offset;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
let collider = match j % 5 {
|
let collider = match j % 5 {
|
||||||
@@ -60,7 +60,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
_ => ColliderBuilder::capsule_y(rad, rad).build(),
|
_ => 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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 1.0;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 2.0)
|
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 2.0)
|
||||||
.restitution(1.0)
|
.restitution(1.0)
|
||||||
.build();
|
.build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
|
|
||||||
let num = 10;
|
let num = 10;
|
||||||
let rad = 0.5;
|
let rad = 0.5;
|
||||||
@@ -33,13 +31,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
for i in 0..=num {
|
for i in 0..=num {
|
||||||
let x = (i as f32) - num as f32 / 2.0;
|
let x = (i as f32) - num as f32 / 2.0;
|
||||||
let rigid_body = RigidBodyBuilder::new_dynamic()
|
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();
|
.build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::ball(rad)
|
let collider = ColliderBuilder::ball(rad)
|
||||||
.restitution((i as f32) / (num as f32))
|
.restitution((i as f32) / (num as f32))
|
||||||
.build();
|
.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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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::prelude::*;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut 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 ground_height = 0.1;
|
||||||
|
|
||||||
let rigid_body = RigidBodyBuilder::new_static()
|
let rigid_body = RigidBodyBuilder::new_static()
|
||||||
.translation(0.0, -ground_height, 0.0)
|
.translation(vector![0.0, -ground_height, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let ground_handle = bodies.insert(rigid_body);
|
let ground_handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
|
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.
|
* Create some boxes.
|
||||||
@@ -41,12 +39,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shift - centerz;
|
let z = k as f32 * shift - centerz;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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,36 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
|
|
||||||
// Rigid body so that the sensor can move.
|
// Rigid body so that the sensor can move.
|
||||||
let sensor = RigidBodyBuilder::new_dynamic()
|
let sensor = RigidBodyBuilder::new_dynamic()
|
||||||
.translation(0.0, 5.0, 0.0)
|
.translation(vector![0.0, 5.0, 0.0])
|
||||||
.build();
|
.build();
|
||||||
let sensor_handle = bodies.insert(sensor);
|
let sensor_handle = bodies.insert(sensor);
|
||||||
|
|
||||||
// Solid cube attached to the sensor which
|
// Solid cube attached to the sensor which
|
||||||
// other colliders can touch.
|
// other colliders can touch.
|
||||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).build();
|
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
|
// We create a collider desc without density because we don't
|
||||||
// want it to contribute to the rigid body mass.
|
// want it to contribute to the rigid body mass.
|
||||||
let sensor_collider = ColliderBuilder::ball(rad * 5.0).sensor(true).build();
|
let sensor_collider = ColliderBuilder::ball(rad * 5.0)
|
||||||
colliders.insert(sensor_collider, sensor_handle, &mut bodies);
|
.density(0.0)
|
||||||
|
.sensor(true)
|
||||||
|
.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.
|
// Callback that will be executed on the main loop to handle proximities.
|
||||||
testbed.add_callback(move |mut graphics, physics, events, _| {
|
testbed.add_callback(move |mut graphics, physics, events, _| {
|
||||||
while let Ok(prox) = events.intersection_events.try_recv() {
|
while let Ok(prox) = events.intersection_events.try_recv() {
|
||||||
let color = if prox.intersecting {
|
let color = if prox.intersecting {
|
||||||
Point3::new(1.0, 1.0, 0.0)
|
[1.0, 1.0, 0.0]
|
||||||
} else {
|
} 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_handle1 = physics.colliders[prox.collider1].parent().unwrap();
|
||||||
let parent_handle2 = physics.colliders.get(prox.collider2).unwrap().parent();
|
let parent_handle2 = physics.colliders[prox.collider2].parent().unwrap();
|
||||||
|
|
||||||
if let Some(graphics) = &mut graphics {
|
if let Some(graphics) = &mut graphics {
|
||||||
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
||||||
@@ -99,5 +102,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
* Set up the testbed.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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 na::ComplexField;
|
||||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
use rapier3d::prelude::*;
|
||||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, HeightField, SharedShape};
|
|
||||||
use rapier_testbed3d::Testbed;
|
use rapier_testbed3d::Testbed;
|
||||||
|
|
||||||
pub fn init_world(testbed: &mut Testbed) {
|
pub fn init_world(testbed: &mut Testbed) {
|
||||||
@@ -14,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
/*
|
/*
|
||||||
* Ground
|
* 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 nsubdivs = 20;
|
||||||
|
|
||||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
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 rigid_body = RigidBodyBuilder::new_static().build();
|
||||||
let handle = bodies.insert(rigid_body);
|
let handle = bodies.insert(rigid_body);
|
||||||
let collider = ColliderBuilder::trimesh(vertices, indices).build();
|
let collider = ColliderBuilder::trimesh(vertices, indices).build();
|
||||||
colliders.insert(collider, handle, &mut bodies);
|
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the cubes
|
* Create the cubes
|
||||||
@@ -60,7 +59,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
let z = k as f32 * shift - centerz;
|
let z = k as f32 * shift - centerz;
|
||||||
|
|
||||||
// Build the rigid body.
|
// 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 handle = bodies.insert(rigid_body);
|
||||||
|
|
||||||
let collider = match j % 6 {
|
let collider = match j % 6 {
|
||||||
@@ -74,15 +75,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
_ => {
|
_ => {
|
||||||
let shapes = vec![
|
let shapes = vec![
|
||||||
(
|
(
|
||||||
Isometry3::identity(),
|
Isometry::identity(),
|
||||||
SharedShape::cuboid(rad, rad / 2.0, rad / 2.0),
|
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),
|
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),
|
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.
|
* Set up the testbed.
|
||||||
*/
|
*/
|
||||||
testbed.set_world(bodies, colliders, joints);
|
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());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,14 @@ impl<T> Coarena<T> {
|
|||||||
Self { data: Vec::new() }
|
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.
|
/// Gets a specific element from the coarena, if it exists.
|
||||||
pub fn get(&self, index: Index) -> Option<&T> {
|
pub fn get(&self, index: Index) -> Option<&T> {
|
||||||
let (i, g) = index.into_raw_parts();
|
let (i, g) = index.into_raw_parts();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ pub struct IntegrationParameters {
|
|||||||
///
|
///
|
||||||
/// When CCD with multiple substeps is enabled, the timestep is subdivided
|
/// When CCD with multiple substeps is enabled, the timestep is subdivided
|
||||||
/// into smaller pieces. This timestep subdivision won't generate timestep
|
/// 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
|
/// Setting this to a large value will reduce the opportunity to performing
|
||||||
/// CCD substepping, resulting in potentially more time dropped by the
|
/// CCD substepping, resulting in potentially more time dropped by the
|
||||||
@@ -18,17 +18,6 @@ pub struct IntegrationParameters {
|
|||||||
/// to numerical instabilities.
|
/// to numerical instabilities.
|
||||||
pub min_ccd_dt: Real,
|
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 Error Reduction Parameter in `[0, 1]` is the proportion of
|
||||||
/// the positional error to be corrected at each time step (default: `0.2`).
|
/// the positional error to be corrected at each time step (default: `0.2`).
|
||||||
pub erp: Real,
|
pub erp: Real,
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ use crate::math::{Isometry, Real, SpacialVector};
|
|||||||
pub struct FixedJoint {
|
pub struct FixedJoint {
|
||||||
/// The frame of reference for the first body affected by this joint, expressed in the local frame
|
/// The frame of reference for the first body affected by this joint, expressed in the local frame
|
||||||
/// of the first body.
|
/// 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
|
/// The frame of reference for the second body affected by this joint, expressed in the local frame
|
||||||
/// of the first body.
|
/// 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 first body affected by this joint.
|
||||||
///
|
///
|
||||||
/// The impulse applied to the second body affected by this joint is given by `-impulse`.
|
/// The impulse applied to the second body affected by this joint is given by `-impulse`.
|
||||||
@@ -23,10 +23,10 @@ pub struct FixedJoint {
|
|||||||
|
|
||||||
impl FixedJoint {
|
impl FixedJoint {
|
||||||
/// Creates a new fixed joint from the frames of reference of both bodies.
|
/// 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 {
|
Self {
|
||||||
local_anchor1,
|
local_frame1,
|
||||||
local_anchor2,
|
local_frame2,
|
||||||
impulse: SpacialVector::zeros(),
|
impulse: SpacialVector::zeros(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,6 +124,72 @@ impl RigidBody {
|
|||||||
self.rb_dominance.effective_group(&self.rb_type)
|
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?
|
/// Are the translations of this rigid-body locked?
|
||||||
pub fn is_translation_locked(&self) -> bool {
|
pub fn is_translation_locked(&self) -> bool {
|
||||||
self.rb_mprops
|
self.rb_mprops
|
||||||
@@ -251,6 +317,16 @@ impl RigidBody {
|
|||||||
self.rb_forces.gravity_scale = scale;
|
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.
|
/// Adds a collider to this rigid-body.
|
||||||
// TODO ECS: we keep this public for now just to simply our experiments on bevy_rapier.
|
// TODO ECS: we keep this public for now just to simply our experiments on bevy_rapier.
|
||||||
pub fn add_collider(
|
pub fn add_collider(
|
||||||
@@ -279,9 +355,10 @@ impl RigidBody {
|
|||||||
if let Some(i) = self.rb_colliders.0.iter().position(|e| *e == handle) {
|
if let Some(i) = self.rb_colliders.0.iter().position(|e| *e == handle) {
|
||||||
self.changes.set(RigidBodyChanges::COLLIDERS, true);
|
self.changes.set(RigidBodyChanges::COLLIDERS, true);
|
||||||
self.rb_colliders.0.swap_remove(i);
|
self.rb_colliders.0.swap_remove(i);
|
||||||
|
|
||||||
let mass_properties = coll
|
let mass_properties = coll
|
||||||
.mass_properties()
|
.mass_properties()
|
||||||
.transform_by(coll.position_wrt_parent());
|
.transform_by(coll.position_wrt_parent().unwrap());
|
||||||
self.rb_mprops.mass_properties -= mass_properties;
|
self.rb_mprops.mass_properties -= mass_properties;
|
||||||
self.update_world_mass_properties();
|
self.update_world_mass_properties();
|
||||||
}
|
}
|
||||||
@@ -384,6 +461,45 @@ impl RigidBody {
|
|||||||
&self.rb_pos.position
|
&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.
|
/// Sets the position and `next_kinematic_position` of this rigid body.
|
||||||
///
|
///
|
||||||
/// This will teleport the rigid-body to the specified position/orientation,
|
/// This will teleport the rigid-body to the specified position/orientation,
|
||||||
@@ -404,6 +520,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, rotation: Rotation<Real>) {
|
||||||
|
if self.is_kinematic() {
|
||||||
|
self.rb_pos.next_position.rotation = rotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// If this rigid body is kinematic, sets its future position after the next timestep integration.
|
/// 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>) {
|
pub fn set_next_kinematic_position(&mut self, pos: Isometry<Real>) {
|
||||||
if self.is_kinematic() {
|
if self.is_kinematic() {
|
||||||
@@ -411,6 +541,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) {
|
pub(crate) fn update_world_mass_properties(&mut self) {
|
||||||
self.rb_mprops
|
self.rb_mprops
|
||||||
.update_world_mass_properties(&self.rb_pos.position);
|
.update_world_mass_properties(&self.rb_pos.position);
|
||||||
@@ -618,8 +759,8 @@ impl RigidBodyBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the scale applied to the gravity force affecting the rigid-body to be created.
|
/// Sets the scale applied to the gravity force affecting the rigid-body to be created.
|
||||||
pub fn gravity_scale(mut self, x: Real) -> Self {
|
pub fn gravity_scale(mut self, scale_factor: Real) -> Self {
|
||||||
self.gravity_scale = x;
|
self.gravity_scale = scale_factor;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,19 +771,8 @@ impl RigidBodyBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the initial translation of the rigid-body to be created.
|
/// Sets the initial translation of the rigid-body to be created.
|
||||||
#[cfg(feature = "dim2")]
|
pub fn translation(mut self, translation: Vector<Real>) -> Self {
|
||||||
pub fn translation(mut self, x: Real, y: Real) -> Self {
|
self.position.translation.vector = translation;
|
||||||
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;
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,16 +941,8 @@ impl RigidBodyBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the initial linear velocity of the rigid-body to be created.
|
/// Sets the initial linear velocity of the rigid-body to be created.
|
||||||
#[cfg(feature = "dim2")]
|
pub fn linvel(mut self, linvel: Vector<Real>) -> Self {
|
||||||
pub fn linvel(mut self, x: Real, y: Real) -> Self {
|
self.linvel = linvel;
|
||||||
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);
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ use crate::utils::WAngularInertia;
|
|||||||
pub(crate) struct FixedPositionConstraint {
|
pub(crate) struct FixedPositionConstraint {
|
||||||
position1: usize,
|
position1: usize,
|
||||||
position2: usize,
|
position2: usize,
|
||||||
local_anchor1: Isometry<Real>,
|
local_frame1: Isometry<Real>,
|
||||||
local_anchor2: Isometry<Real>,
|
local_frame2: Isometry<Real>,
|
||||||
local_com1: Point<Real>,
|
local_com1: Point<Real>,
|
||||||
local_com2: Point<Real>,
|
local_com2: Point<Real>,
|
||||||
im1: Real,
|
im1: Real,
|
||||||
@@ -38,8 +38,8 @@ impl FixedPositionConstraint {
|
|||||||
let ang_inv_lhs = (ii1 + ii2).inverse();
|
let ang_inv_lhs = (ii1 + ii2).inverse();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
local_anchor1: cparams.local_anchor1,
|
local_frame1: cparams.local_frame1,
|
||||||
local_anchor2: cparams.local_anchor2,
|
local_frame2: cparams.local_frame2,
|
||||||
position1: ids1.active_set_offset,
|
position1: ids1.active_set_offset,
|
||||||
position2: ids2.active_set_offset,
|
position2: ids2.active_set_offset,
|
||||||
im1,
|
im1,
|
||||||
@@ -58,8 +58,8 @@ impl FixedPositionConstraint {
|
|||||||
let mut position2 = positions[self.position2 as usize];
|
let mut position2 = positions[self.position2 as usize];
|
||||||
|
|
||||||
// Angular correction.
|
// Angular correction.
|
||||||
let anchor1 = position1 * self.local_anchor1;
|
let anchor1 = position1 * self.local_frame1;
|
||||||
let anchor2 = position2 * self.local_anchor2;
|
let anchor2 = position2 * self.local_frame2;
|
||||||
let ang_err = anchor2.rotation * anchor1.rotation.inverse();
|
let ang_err = anchor2.rotation * anchor1.rotation.inverse();
|
||||||
#[cfg(feature = "dim3")]
|
#[cfg(feature = "dim3")]
|
||||||
let ang_impulse = self
|
let ang_impulse = self
|
||||||
@@ -75,8 +75,8 @@ impl FixedPositionConstraint {
|
|||||||
Rotation::new(self.ii2.transform_vector(-ang_impulse)) * position2.rotation;
|
Rotation::new(self.ii2.transform_vector(-ang_impulse)) * position2.rotation;
|
||||||
|
|
||||||
// Linear correction.
|
// Linear correction.
|
||||||
let anchor1 = position1 * Point::from(self.local_anchor1.translation.vector);
|
let anchor1 = position1 * Point::from(self.local_frame1.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;
|
let err = anchor2 - anchor1;
|
||||||
let impulse = err * (self.lin_inv_lhs * params.joint_erp);
|
let impulse = err * (self.lin_inv_lhs * params.joint_erp);
|
||||||
position1.translation.vector += self.im1 * impulse;
|
position1.translation.vector += self.im1 * impulse;
|
||||||
@@ -91,7 +91,7 @@ impl FixedPositionConstraint {
|
|||||||
pub(crate) struct FixedPositionGroundConstraint {
|
pub(crate) struct FixedPositionGroundConstraint {
|
||||||
position2: usize,
|
position2: usize,
|
||||||
anchor1: Isometry<Real>,
|
anchor1: Isometry<Real>,
|
||||||
local_anchor2: Isometry<Real>,
|
local_frame2: Isometry<Real>,
|
||||||
local_com2: Point<Real>,
|
local_com2: Point<Real>,
|
||||||
im2: Real,
|
im2: Real,
|
||||||
ii2: AngularInertia<Real>,
|
ii2: AngularInertia<Real>,
|
||||||
@@ -109,19 +109,19 @@ impl FixedPositionGroundConstraint {
|
|||||||
let (mprops2, ids2) = rb2;
|
let (mprops2, ids2) = rb2;
|
||||||
|
|
||||||
let anchor1;
|
let anchor1;
|
||||||
let local_anchor2;
|
let local_frame2;
|
||||||
|
|
||||||
if flipped {
|
if flipped {
|
||||||
anchor1 = poss1.next_position * cparams.local_anchor2;
|
anchor1 = poss1.next_position * cparams.local_frame2;
|
||||||
local_anchor2 = cparams.local_anchor1;
|
local_frame2 = cparams.local_frame1;
|
||||||
} else {
|
} else {
|
||||||
anchor1 = poss1.next_position * cparams.local_anchor1;
|
anchor1 = poss1.next_position * cparams.local_frame1;
|
||||||
local_anchor2 = cparams.local_anchor2;
|
local_frame2 = cparams.local_frame2;
|
||||||
};
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
anchor1,
|
anchor1,
|
||||||
local_anchor2,
|
local_frame2,
|
||||||
position2: ids2.active_set_offset,
|
position2: ids2.active_set_offset,
|
||||||
im2: mprops2.effective_inv_mass,
|
im2: mprops2.effective_inv_mass,
|
||||||
ii2: mprops2.effective_world_inv_inertia_sqrt.squared(),
|
ii2: mprops2.effective_world_inv_inertia_sqrt.squared(),
|
||||||
@@ -134,13 +134,13 @@ impl FixedPositionGroundConstraint {
|
|||||||
let mut position2 = positions[self.position2 as usize];
|
let mut position2 = positions[self.position2 as usize];
|
||||||
|
|
||||||
// Angular correction.
|
// Angular correction.
|
||||||
let anchor2 = position2 * self.local_anchor2;
|
let anchor2 = position2 * self.local_frame2;
|
||||||
let ang_err = anchor2.rotation * self.anchor1.rotation.inverse();
|
let ang_err = anchor2.rotation * self.anchor1.rotation.inverse();
|
||||||
position2.rotation = ang_err.powf(-params.joint_erp) * position2.rotation;
|
position2.rotation = ang_err.powf(-params.joint_erp) * position2.rotation;
|
||||||
|
|
||||||
// Linear correction.
|
// Linear correction.
|
||||||
let anchor1 = Point::from(self.anchor1.translation.vector);
|
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;
|
let err = anchor2 - anchor1;
|
||||||
// NOTE: no need to divide by im2 just to multiply right after.
|
// NOTE: no need to divide by im2 just to multiply right after.
|
||||||
let impulse = err * params.joint_erp;
|
let impulse = err * params.joint_erp;
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ impl FixedVelocityConstraint {
|
|||||||
let (poss1, vels1, mprops1, ids1) = rb1;
|
let (poss1, vels1, mprops1, ids1) = rb1;
|
||||||
let (poss2, vels2, mprops2, ids2) = rb2;
|
let (poss2, vels2, mprops2, ids2) = rb2;
|
||||||
|
|
||||||
let anchor1 = poss1.position * cparams.local_anchor1;
|
let anchor1 = poss1.position * cparams.local_frame1;
|
||||||
let anchor2 = poss2.position * cparams.local_anchor2;
|
let anchor2 = poss2.position * cparams.local_frame2;
|
||||||
let im1 = mprops1.effective_inv_mass;
|
let im1 = mprops1.effective_inv_mass;
|
||||||
let im2 = mprops2.effective_inv_mass;
|
let im2 = mprops2.effective_inv_mass;
|
||||||
let ii1 = mprops1.effective_world_inv_inertia_sqrt.squared();
|
let ii1 = mprops1.effective_world_inv_inertia_sqrt.squared();
|
||||||
@@ -280,13 +280,13 @@ impl FixedVelocityGroundConstraint {
|
|||||||
|
|
||||||
let (anchor1, anchor2) = if flipped {
|
let (anchor1, anchor2) = if flipped {
|
||||||
(
|
(
|
||||||
poss1.position * cparams.local_anchor2,
|
poss1.position * cparams.local_frame2,
|
||||||
poss2.position * cparams.local_anchor1,
|
poss2.position * cparams.local_frame1,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
poss1.position * cparams.local_anchor1,
|
poss1.position * cparams.local_frame1,
|
||||||
poss2.position * cparams.local_anchor2,
|
poss2.position * cparams.local_frame2,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -91,12 +91,12 @@ impl WFixedVelocityConstraint {
|
|||||||
]);
|
]);
|
||||||
let mj_lambda2 = gather![|ii| ids2[ii].active_set_offset];
|
let mj_lambda2 = gather![|ii| ids2[ii].active_set_offset];
|
||||||
|
|
||||||
let local_anchor1 = Isometry::from(gather![|ii| cparams[ii].local_anchor1]);
|
let local_frame1 = Isometry::from(gather![|ii| cparams[ii].local_frame1]);
|
||||||
let local_anchor2 = Isometry::from(gather![|ii| cparams[ii].local_anchor2]);
|
let local_frame2 = Isometry::from(gather![|ii| cparams[ii].local_frame2]);
|
||||||
let impulse = SpacialVector::from(gather![|ii| cparams[ii].impulse]);
|
let impulse = SpacialVector::from(gather![|ii| cparams[ii].impulse]);
|
||||||
|
|
||||||
let anchor1 = position1 * local_anchor1;
|
let anchor1 = position1 * local_frame1;
|
||||||
let anchor2 = position2 * local_anchor2;
|
let anchor2 = position2 * local_frame2;
|
||||||
let ii1 = ii1_sqrt.squared();
|
let ii1 = ii1_sqrt.squared();
|
||||||
let ii2 = ii2_sqrt.squared();
|
let ii2 = ii2_sqrt.squared();
|
||||||
let r1 = anchor1.translation.vector - world_com1.coords;
|
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 mj_lambda2 = gather![|ii| ids2[ii].active_set_offset];
|
||||||
|
|
||||||
let local_anchor1 = Isometry::from(gather![|ii| if flipped[ii] {
|
let local_frame1 = Isometry::from(gather![|ii| if flipped[ii] {
|
||||||
cparams[ii].local_anchor2
|
cparams[ii].local_frame2
|
||||||
} else {
|
} else {
|
||||||
cparams[ii].local_anchor1
|
cparams[ii].local_frame1
|
||||||
}]);
|
}]);
|
||||||
let local_anchor2 = Isometry::from(gather![|ii| if flipped[ii] {
|
let local_frame2 = Isometry::from(gather![|ii| if flipped[ii] {
|
||||||
cparams[ii].local_anchor1
|
cparams[ii].local_frame1
|
||||||
} else {
|
} else {
|
||||||
cparams[ii].local_anchor2
|
cparams[ii].local_frame2
|
||||||
}]);
|
}]);
|
||||||
let impulse = SpacialVector::from(gather![|ii| cparams[ii].impulse]);
|
let impulse = SpacialVector::from(gather![|ii| cparams[ii].impulse]);
|
||||||
|
|
||||||
let anchor1 = position1 * local_anchor1;
|
let anchor1 = position1 * local_frame1;
|
||||||
let anchor2 = position2 * local_anchor2;
|
let anchor2 = position2 * local_frame2;
|
||||||
let ii2 = ii2_sqrt.squared();
|
let ii2 = ii2_sqrt.squared();
|
||||||
let r1 = anchor1.translation.vector - world_com1.coords;
|
let r1 = anchor1.translation.vector - world_com1.coords;
|
||||||
let r2 = anchor2.translation.vector - world_com2.coords;
|
let r2 = anchor2.translation.vector - world_com2.coords;
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ use crate::dynamics::{CoefficientCombineRule, MassProperties, RigidBodyHandle};
|
|||||||
use crate::geometry::{
|
use crate::geometry::{
|
||||||
ColliderBroadPhaseData, ColliderChanges, ColliderGroups, ColliderMassProperties,
|
ColliderBroadPhaseData, ColliderChanges, ColliderGroups, ColliderMassProperties,
|
||||||
ColliderMaterial, ColliderParent, ColliderPosition, ColliderShape, ColliderType,
|
ColliderMaterial, ColliderParent, ColliderPosition, ColliderShape, ColliderType,
|
||||||
InteractionGroups, SharedShape, SolverFlags,
|
InteractionGroups, SharedShape,
|
||||||
};
|
};
|
||||||
use crate::math::{AngVector, Isometry, Point, Real, Rotation, Vector, DIM};
|
use crate::math::{AngVector, Isometry, Point, Real, Rotation, Vector, DIM};
|
||||||
use crate::parry::transformation::vhacd::VHACDParameters;
|
use crate::parry::transformation::vhacd::VHACDParameters;
|
||||||
|
use crate::pipeline::PhysicsHooksFlags;
|
||||||
use na::Unit;
|
use na::Unit;
|
||||||
use parry::bounding_volume::AABB;
|
use parry::bounding_volume::AABB;
|
||||||
use parry::shape::Shape;
|
use parry::shape::Shape;
|
||||||
@@ -20,7 +21,7 @@ pub struct Collider {
|
|||||||
pub(crate) co_shape: ColliderShape,
|
pub(crate) co_shape: ColliderShape,
|
||||||
pub(crate) co_mprops: ColliderMassProperties,
|
pub(crate) co_mprops: ColliderMassProperties,
|
||||||
pub(crate) co_changes: ColliderChanges,
|
pub(crate) co_changes: ColliderChanges,
|
||||||
pub(crate) co_parent: ColliderParent,
|
pub(crate) co_parent: Option<ColliderParent>,
|
||||||
pub(crate) co_pos: ColliderPosition,
|
pub(crate) co_pos: ColliderPosition,
|
||||||
pub(crate) co_material: ColliderMaterial,
|
pub(crate) co_material: ColliderMaterial,
|
||||||
pub(crate) co_groups: ColliderGroups,
|
pub(crate) co_groups: ColliderGroups,
|
||||||
@@ -31,14 +32,14 @@ pub struct Collider {
|
|||||||
|
|
||||||
impl Collider {
|
impl Collider {
|
||||||
pub(crate) fn reset_internal_references(&mut self) {
|
pub(crate) fn reset_internal_references(&mut self) {
|
||||||
self.co_parent.handle = RigidBodyHandle::invalid();
|
self.co_parent = None;
|
||||||
self.co_bf_data.proxy_index = crate::INVALID_U32;
|
self.co_bf_data.proxy_index = crate::INVALID_U32;
|
||||||
self.co_changes = ColliderChanges::all();
|
self.co_changes = ColliderChanges::all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The rigid body this collider is attached to.
|
/// The rigid body this collider is attached to.
|
||||||
pub fn parent(&self) -> RigidBodyHandle {
|
pub fn parent(&self) -> Option<RigidBodyHandle> {
|
||||||
self.co_parent.handle
|
self.co_parent.map(|parent| parent.handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is this collider a sensor?
|
/// Is this collider a sensor?
|
||||||
@@ -46,6 +47,26 @@ impl Collider {
|
|||||||
self.co_type.is_sensor()
|
self.co_type.is_sensor()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The physics hooks enabled for this collider.
|
||||||
|
pub fn active_hooks(&self) -> PhysicsHooksFlags {
|
||||||
|
self.co_material.active_hooks
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the physics hooks enabled for this collider.
|
||||||
|
pub fn set_active_hooks(&mut self, active_hooks: PhysicsHooksFlags) {
|
||||||
|
self.co_material.active_hooks = active_hooks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The friction coefficient of this collider.
|
||||||
|
pub fn friction(&self) -> Real {
|
||||||
|
self.co_material.friction
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the friction coefficient of this collider.
|
||||||
|
pub fn set_friction(&mut self, coefficient: Real) {
|
||||||
|
self.co_material.friction = coefficient
|
||||||
|
}
|
||||||
|
|
||||||
/// The combine rule used by this collider to combine its friction
|
/// The combine rule used by this collider to combine its friction
|
||||||
/// coefficient with the friction coefficient of the other collider it
|
/// coefficient with the friction coefficient of the other collider it
|
||||||
/// is in contact with.
|
/// is in contact with.
|
||||||
@@ -60,6 +81,16 @@ impl Collider {
|
|||||||
self.co_material.friction_combine_rule = rule;
|
self.co_material.friction_combine_rule = rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The restitution coefficient of this collider.
|
||||||
|
pub fn restitution(&self) -> Real {
|
||||||
|
self.co_material.restitution
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the restitution coefficient of this collider.
|
||||||
|
pub fn set_restitution(&mut self, coefficient: Real) {
|
||||||
|
self.co_material.restitution = coefficient
|
||||||
|
}
|
||||||
|
|
||||||
/// The combine rule used by this collider to combine its restitution
|
/// The combine rule used by this collider to combine its restitution
|
||||||
/// coefficient with the restitution coefficient of the other collider it
|
/// coefficient with the restitution coefficient of the other collider it
|
||||||
/// is in contact with.
|
/// is in contact with.
|
||||||
@@ -86,15 +117,22 @@ impl Collider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
/// Sets the translational part of this collider's position.
|
||||||
pub fn set_position_debug(&mut self, position: Isometry<Real>) {
|
pub fn set_translation(&mut self, translation: Vector<Real>) {
|
||||||
self.co_pos.0 = position;
|
self.co_changes.insert(ColliderChanges::POSITION);
|
||||||
|
self.co_pos.0.translation.vector = translation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The position of this collider expressed in the local-space of the rigid-body it is attached to.
|
/// Sets the rotational part of this collider's position.
|
||||||
#[deprecated(note = "use `.position_wrt_parent()` instead.")]
|
pub fn set_rotation(&mut self, rotation: AngVector<Real>) {
|
||||||
pub fn delta(&self) -> &Isometry<Real> {
|
self.co_changes.insert(ColliderChanges::POSITION);
|
||||||
&self.co_parent.pos_wrt_parent
|
self.co_pos.0.rotation = Rotation::new(rotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the position of this collider.
|
||||||
|
pub fn set_position(&mut self, position: Isometry<Real>) {
|
||||||
|
self.co_changes.insert(ColliderChanges::POSITION);
|
||||||
|
self.co_pos.0 = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The world-space position of this collider.
|
/// The world-space position of this collider.
|
||||||
@@ -102,15 +140,31 @@ impl Collider {
|
|||||||
&self.co_pos
|
&self.co_pos
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The translational part of this rigid-body's position.
|
||||||
|
pub fn translation(&self) -> &Vector<Real> {
|
||||||
|
&self.co_pos.0.translation.vector
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The rotational part of this rigid-body's position.
|
||||||
|
pub fn rotation(&self) -> &Rotation<Real> {
|
||||||
|
&self.co_pos.0.rotation
|
||||||
|
}
|
||||||
|
|
||||||
/// The position of this collider wrt the body it is attached to.
|
/// The position of this collider wrt the body it is attached to.
|
||||||
pub fn position_wrt_parent(&self) -> &Isometry<Real> {
|
pub fn position_wrt_parent(&self) -> Option<&Isometry<Real>> {
|
||||||
&self.co_parent.pos_wrt_parent
|
self.co_parent.as_ref().map(|p| &p.pos_wrt_parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the position of this collider wrt. its parent rigid-body.
|
/// Sets the position of this collider wrt. its parent rigid-body.
|
||||||
pub fn set_position_wrt_parent(&mut self, position: Isometry<Real>) {
|
///
|
||||||
|
/// Panics if the collider is not attached to a rigid-body.
|
||||||
|
pub fn set_position_wrt_parent(&mut self, pos_wrt_parent: Isometry<Real>) {
|
||||||
self.co_changes.insert(ColliderChanges::PARENT);
|
self.co_changes.insert(ColliderChanges::PARENT);
|
||||||
self.co_parent.pos_wrt_parent = position;
|
let co_parent = self
|
||||||
|
.co_parent
|
||||||
|
.as_mut()
|
||||||
|
.expect("This collider has no parent.");
|
||||||
|
co_parent.pos_wrt_parent = pos_wrt_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The collision groups used by this collider.
|
/// The collision groups used by this collider.
|
||||||
@@ -213,13 +267,12 @@ pub struct ColliderBuilder {
|
|||||||
pub restitution: Real,
|
pub restitution: Real,
|
||||||
/// The rule used to combine two restitution coefficients.
|
/// The rule used to combine two restitution coefficients.
|
||||||
pub restitution_combine_rule: CoefficientCombineRule,
|
pub restitution_combine_rule: CoefficientCombineRule,
|
||||||
/// The position of this collider relative to the local frame of the rigid-body it is attached to.
|
/// The position of this collider.
|
||||||
pub pos_wrt_parent: Isometry<Real>,
|
pub position: Isometry<Real>,
|
||||||
/// Is this collider a sensor?
|
/// Is this collider a sensor?
|
||||||
pub is_sensor: bool,
|
pub is_sensor: bool,
|
||||||
/// Do we have to always call the contact modifier
|
/// Physics hooks enabled for this collider.
|
||||||
/// on this collider?
|
pub active_hooks: PhysicsHooksFlags,
|
||||||
pub modify_solver_contacts: bool,
|
|
||||||
/// The user-data of the collider being built.
|
/// The user-data of the collider being built.
|
||||||
pub user_data: u128,
|
pub user_data: u128,
|
||||||
/// The collision groups for the collider being built.
|
/// The collision groups for the collider being built.
|
||||||
@@ -237,14 +290,14 @@ impl ColliderBuilder {
|
|||||||
mass_properties: None,
|
mass_properties: None,
|
||||||
friction: Self::default_friction(),
|
friction: Self::default_friction(),
|
||||||
restitution: 0.0,
|
restitution: 0.0,
|
||||||
pos_wrt_parent: Isometry::identity(),
|
position: Isometry::identity(),
|
||||||
is_sensor: false,
|
is_sensor: false,
|
||||||
user_data: 0,
|
user_data: 0,
|
||||||
collision_groups: InteractionGroups::all(),
|
collision_groups: InteractionGroups::all(),
|
||||||
solver_groups: InteractionGroups::all(),
|
solver_groups: InteractionGroups::all(),
|
||||||
friction_combine_rule: CoefficientCombineRule::Average,
|
friction_combine_rule: CoefficientCombineRule::Average,
|
||||||
restitution_combine_rule: CoefficientCombineRule::Average,
|
restitution_combine_rule: CoefficientCombineRule::Average,
|
||||||
modify_solver_contacts: false,
|
active_hooks: PhysicsHooksFlags::empty(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -489,6 +542,11 @@ impl ColliderBuilder {
|
|||||||
0.5
|
0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The default density used by the collider builder.
|
||||||
|
pub fn default_density() -> Real {
|
||||||
|
1.0
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets an arbitrary user-defined 128-bit integer associated to the colliders built by this builder.
|
/// Sets an arbitrary user-defined 128-bit integer associated to the colliders built by this builder.
|
||||||
pub fn user_data(mut self, data: u128) -> Self {
|
pub fn user_data(mut self, data: u128) -> Self {
|
||||||
self.user_data = data;
|
self.user_data = data;
|
||||||
@@ -522,10 +580,9 @@ impl ColliderBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If set to `true` then the physics hooks will always run to modify
|
/// The set of physics hooks enabled for this collider.
|
||||||
/// contacts involving this collider.
|
pub fn active_hooks(mut self, active_hooks: PhysicsHooksFlags) -> Self {
|
||||||
pub fn modify_solver_contacts(mut self, modify_solver_contacts: bool) -> Self {
|
self.active_hooks = active_hooks;
|
||||||
self.modify_solver_contacts = modify_solver_contacts;
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -571,51 +628,45 @@ impl ColliderBuilder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the initial translation of the collider to be created,
|
/// Sets the initial translation of the collider to be created.
|
||||||
/// relative to the rigid-body it is attached to.
|
///
|
||||||
#[cfg(feature = "dim2")]
|
/// If the collider will be attached to a rigid-body, this sets the translation relative to the
|
||||||
pub fn translation(mut self, x: Real, y: Real) -> Self {
|
/// rigid-body it will be attached to.
|
||||||
self.pos_wrt_parent.translation.x = x;
|
pub fn translation(mut self, translation: Vector<Real>) -> Self {
|
||||||
self.pos_wrt_parent.translation.y = y;
|
self.position.translation.vector = translation;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the initial translation of the collider to be created,
|
/// Sets the initial orientation of the collider to be created.
|
||||||
/// relative to the rigid-body it is attached to.
|
///
|
||||||
#[cfg(feature = "dim3")]
|
/// If the collider will be attached to a rigid-body, this sets the orientation relative to the
|
||||||
pub fn translation(mut self, x: Real, y: Real, z: Real) -> Self {
|
/// rigid-body it will be attached to.
|
||||||
self.pos_wrt_parent.translation.x = x;
|
|
||||||
self.pos_wrt_parent.translation.y = y;
|
|
||||||
self.pos_wrt_parent.translation.z = z;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the initial orientation of the collider to be created,
|
|
||||||
/// relative to the rigid-body it is attached to.
|
|
||||||
pub fn rotation(mut self, angle: AngVector<Real>) -> Self {
|
pub fn rotation(mut self, angle: AngVector<Real>) -> Self {
|
||||||
self.pos_wrt_parent.rotation = Rotation::new(angle);
|
self.position.rotation = Rotation::new(angle);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the initial position (translation and orientation) of the collider to be created,
|
/// Sets the initial position (translation and orientation) of the collider to be created.
|
||||||
/// relative to the rigid-body it is attached to.
|
///
|
||||||
pub fn position_wrt_parent(mut self, pos: Isometry<Real>) -> Self {
|
/// If the collider will be attached to a rigid-body, this sets the position relative
|
||||||
self.pos_wrt_parent = pos;
|
/// to the rigid-body it will be attached to.
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the initial position (translation and orientation) of the collider to be created,
|
|
||||||
/// relative to the rigid-body it is attached to.
|
|
||||||
#[deprecated(note = "Use `.position_wrt_parent` instead.")]
|
|
||||||
pub fn position(mut self, pos: Isometry<Real>) -> Self {
|
pub fn position(mut self, pos: Isometry<Real>) -> Self {
|
||||||
self.pos_wrt_parent = pos;
|
self.position = pos;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the initial position (translation and orientation) of the collider to be created,
|
||||||
|
/// relative to the rigid-body it is attached to.
|
||||||
|
#[deprecated(note = "Use `.position` instead.")]
|
||||||
|
pub fn position_wrt_parent(mut self, pos: Isometry<Real>) -> Self {
|
||||||
|
self.position = pos;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the position of this collider in the local-space of the rigid-body it is attached to.
|
/// Set the position of this collider in the local-space of the rigid-body it is attached to.
|
||||||
#[deprecated(note = "Use `.position_wrt_parent` instead.")]
|
#[deprecated(note = "Use `.position` instead.")]
|
||||||
pub fn delta(mut self, delta: Isometry<Real>) -> Self {
|
pub fn delta(mut self, delta: Isometry<Real>) -> Self {
|
||||||
self.pos_wrt_parent = delta;
|
self.position = delta;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -623,15 +674,11 @@ impl ColliderBuilder {
|
|||||||
pub fn build(&self) -> Collider {
|
pub fn build(&self) -> Collider {
|
||||||
let (co_changes, co_pos, co_bf_data, co_shape, co_type, co_groups, co_material, co_mprops) =
|
let (co_changes, co_pos, co_bf_data, co_shape, co_type, co_groups, co_material, co_mprops) =
|
||||||
self.components();
|
self.components();
|
||||||
let co_parent = ColliderParent {
|
|
||||||
pos_wrt_parent: co_pos.0,
|
|
||||||
handle: RigidBodyHandle::invalid(),
|
|
||||||
};
|
|
||||||
Collider {
|
Collider {
|
||||||
co_shape,
|
co_shape,
|
||||||
co_mprops,
|
co_mprops,
|
||||||
co_material,
|
co_material,
|
||||||
co_parent,
|
co_parent: None,
|
||||||
co_changes,
|
co_changes,
|
||||||
co_pos,
|
co_pos,
|
||||||
co_bf_data,
|
co_bf_data,
|
||||||
@@ -657,17 +704,11 @@ impl ColliderBuilder {
|
|||||||
let mass_info = if let Some(mp) = self.mass_properties {
|
let mass_info = if let Some(mp) = self.mass_properties {
|
||||||
ColliderMassProperties::MassProperties(Box::new(mp))
|
ColliderMassProperties::MassProperties(Box::new(mp))
|
||||||
} else {
|
} else {
|
||||||
let default_density = if self.is_sensor { 0.0 } else { 1.0 };
|
let default_density = Self::default_density();
|
||||||
let density = self.density.unwrap_or(default_density);
|
let density = self.density.unwrap_or(default_density);
|
||||||
ColliderMassProperties::Density(density)
|
ColliderMassProperties::Density(density)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut solver_flags = SolverFlags::default();
|
|
||||||
solver_flags.set(
|
|
||||||
SolverFlags::MODIFY_SOLVER_CONTACTS,
|
|
||||||
self.modify_solver_contacts,
|
|
||||||
);
|
|
||||||
|
|
||||||
let co_shape = self.shape.clone();
|
let co_shape = self.shape.clone();
|
||||||
let co_mprops = mass_info;
|
let co_mprops = mass_info;
|
||||||
let co_material = ColliderMaterial {
|
let co_material = ColliderMaterial {
|
||||||
@@ -675,10 +716,10 @@ impl ColliderBuilder {
|
|||||||
restitution: self.restitution,
|
restitution: self.restitution,
|
||||||
friction_combine_rule: self.friction_combine_rule,
|
friction_combine_rule: self.friction_combine_rule,
|
||||||
restitution_combine_rule: self.restitution_combine_rule,
|
restitution_combine_rule: self.restitution_combine_rule,
|
||||||
solver_flags,
|
active_hooks: self.active_hooks,
|
||||||
};
|
};
|
||||||
let co_changes = ColliderChanges::all();
|
let co_changes = ColliderChanges::all();
|
||||||
let co_pos = ColliderPosition(self.pos_wrt_parent);
|
let co_pos = ColliderPosition(self.position);
|
||||||
let co_bf_data = ColliderBroadPhaseData::default();
|
let co_bf_data = ColliderBroadPhaseData::default();
|
||||||
let co_groups = ColliderGroups {
|
let co_groups = ColliderGroups {
|
||||||
collision_groups: self.collision_groups,
|
collision_groups: self.collision_groups,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use crate::dynamics::{CoefficientCombineRule, MassProperties, RigidBodyHandle};
|
use crate::dynamics::{CoefficientCombineRule, MassProperties, RigidBodyHandle};
|
||||||
use crate::geometry::{InteractionGroups, SAPProxyIndex, Shape, SharedShape, SolverFlags};
|
use crate::geometry::{InteractionGroups, SAPProxyIndex, Shape, SharedShape};
|
||||||
use crate::math::{Isometry, Real};
|
use crate::math::{Isometry, Real};
|
||||||
use crate::parry::partitioning::IndexedData;
|
use crate::parry::partitioning::IndexedData;
|
||||||
|
use crate::pipeline::PhysicsHooksFlags;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
/// The unique identifier of a collider added to a collider set.
|
/// The unique identifier of a collider added to a collider set.
|
||||||
@@ -241,9 +242,8 @@ pub struct ColliderMaterial {
|
|||||||
pub friction_combine_rule: CoefficientCombineRule,
|
pub friction_combine_rule: CoefficientCombineRule,
|
||||||
/// The rule applied to combine the restitution coefficients of two colliders.
|
/// The rule applied to combine the restitution coefficients of two colliders.
|
||||||
pub restitution_combine_rule: CoefficientCombineRule,
|
pub restitution_combine_rule: CoefficientCombineRule,
|
||||||
/// The solver flags attached to this collider in order to customize the way the
|
/// The physics hooks enabled for contact pairs and intersection pairs involving this collider.
|
||||||
/// constraints solver will work with contacts involving this collider.
|
pub active_hooks: PhysicsHooksFlags,
|
||||||
pub solver_flags: SolverFlags,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ColliderMaterial {
|
impl ColliderMaterial {
|
||||||
@@ -264,7 +264,7 @@ impl Default for ColliderMaterial {
|
|||||||
restitution: 0.0,
|
restitution: 0.0,
|
||||||
friction_combine_rule: CoefficientCombineRule::default(),
|
friction_combine_rule: CoefficientCombineRule::default(),
|
||||||
restitution_combine_rule: CoefficientCombineRule::default(),
|
restitution_combine_rule: CoefficientCombineRule::default(),
|
||||||
solver_flags: SolverFlags::default(),
|
active_hooks: PhysicsHooksFlags::empty(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,12 +61,19 @@ impl_field_component_set!(ColliderType, co_type);
|
|||||||
impl_field_component_set!(ColliderShape, co_shape);
|
impl_field_component_set!(ColliderShape, co_shape);
|
||||||
impl_field_component_set!(ColliderMassProperties, co_mprops);
|
impl_field_component_set!(ColliderMassProperties, co_mprops);
|
||||||
impl_field_component_set!(ColliderChanges, co_changes);
|
impl_field_component_set!(ColliderChanges, co_changes);
|
||||||
impl_field_component_set!(ColliderParent, co_parent);
|
|
||||||
impl_field_component_set!(ColliderPosition, co_pos);
|
impl_field_component_set!(ColliderPosition, co_pos);
|
||||||
impl_field_component_set!(ColliderMaterial, co_material);
|
impl_field_component_set!(ColliderMaterial, co_material);
|
||||||
impl_field_component_set!(ColliderGroups, co_groups);
|
impl_field_component_set!(ColliderGroups, co_groups);
|
||||||
impl_field_component_set!(ColliderBroadPhaseData, co_bf_data);
|
impl_field_component_set!(ColliderBroadPhaseData, co_bf_data);
|
||||||
|
|
||||||
|
impl ComponentSetOption<ColliderParent> for ColliderSet {
|
||||||
|
#[inline(always)]
|
||||||
|
fn get(&self, handle: crate::data::Index) -> Option<&ColliderParent> {
|
||||||
|
self.get(ColliderHandle(handle))
|
||||||
|
.and_then(|b| b.co_parent.as_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ColliderSet {
|
impl ColliderSet {
|
||||||
/// Create a new empty set of colliders.
|
/// Create a new empty set of colliders.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
@@ -122,7 +129,17 @@ impl ColliderSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Inserts a new collider to this set and retrieve its handle.
|
/// Inserts a new collider to this set and retrieve its handle.
|
||||||
pub fn insert(
|
pub fn insert(&mut self, mut coll: Collider) -> ColliderHandle {
|
||||||
|
// Make sure the internal links are reset, they may not be
|
||||||
|
// if this rigid-body was obtained by cloning another one.
|
||||||
|
coll.reset_internal_references();
|
||||||
|
let handle = ColliderHandle(self.colliders.insert(coll));
|
||||||
|
self.modified_colliders.push(handle);
|
||||||
|
handle
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inserts a new collider to this set, attach it to the given rigid-body, and retrieve its handle.
|
||||||
|
pub fn insert_with_parent(
|
||||||
&mut self,
|
&mut self,
|
||||||
mut coll: Collider,
|
mut coll: Collider,
|
||||||
parent_handle: RigidBodyHandle,
|
parent_handle: RigidBodyHandle,
|
||||||
@@ -131,7 +148,10 @@ impl ColliderSet {
|
|||||||
// Make sure the internal links are reset, they may not be
|
// Make sure the internal links are reset, they may not be
|
||||||
// if this rigid-body was obtained by cloning another one.
|
// if this rigid-body was obtained by cloning another one.
|
||||||
coll.reset_internal_references();
|
coll.reset_internal_references();
|
||||||
coll.co_parent.handle = parent_handle;
|
coll.co_parent = Some(ColliderParent {
|
||||||
|
handle: parent_handle,
|
||||||
|
pos_wrt_parent: coll.co_pos.0,
|
||||||
|
});
|
||||||
|
|
||||||
// NOTE: we use `get_mut` instead of `get_mut_internal` so that the
|
// NOTE: we use `get_mut` instead of `get_mut_internal` so that the
|
||||||
// modification flag is updated properly.
|
// modification flag is updated properly.
|
||||||
@@ -144,7 +164,7 @@ impl ColliderSet {
|
|||||||
let coll = self.colliders.get_mut(handle.0).unwrap();
|
let coll = self.colliders.get_mut(handle.0).unwrap();
|
||||||
parent.add_collider(
|
parent.add_collider(
|
||||||
handle,
|
handle,
|
||||||
&mut coll.co_parent,
|
coll.co_parent.as_mut().unwrap(),
|
||||||
&mut coll.co_pos,
|
&mut coll.co_pos,
|
||||||
&coll.co_shape,
|
&coll.co_shape,
|
||||||
&coll.co_mprops,
|
&coll.co_mprops,
|
||||||
@@ -170,13 +190,15 @@ impl ColliderSet {
|
|||||||
*/
|
*/
|
||||||
// NOTE: we use `get_mut_internal_with_modification_tracking` instead of `get_mut_internal` so that the
|
// NOTE: we use `get_mut_internal_with_modification_tracking` instead of `get_mut_internal` so that the
|
||||||
// modification flag is updated properly.
|
// modification flag is updated properly.
|
||||||
|
if let Some(co_parent) = &collider.co_parent {
|
||||||
if let Some(parent) =
|
if let Some(parent) =
|
||||||
bodies.get_mut_internal_with_modification_tracking(collider.co_parent.handle)
|
bodies.get_mut_internal_with_modification_tracking(co_parent.handle)
|
||||||
{
|
{
|
||||||
parent.remove_collider_internal(handle, &collider);
|
parent.remove_collider_internal(handle, &collider);
|
||||||
|
|
||||||
if wake_up {
|
if wake_up {
|
||||||
islands.wake_up(bodies, collider.co_parent.handle, true);
|
islands.wake_up(bodies, co_parent.handle, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::dynamics::RigidBodyHandle;
|
use crate::dynamics::RigidBodyHandle;
|
||||||
use crate::geometry::{ColliderPair, Contact, ContactManifold};
|
use crate::geometry::{ColliderHandle, Contact, ContactManifold};
|
||||||
use crate::math::{Point, Real, Vector};
|
use crate::math::{Point, Real, Vector};
|
||||||
use parry::query::ContactManifoldsWorkspace;
|
use parry::query::ContactManifoldsWorkspace;
|
||||||
|
|
||||||
@@ -10,9 +10,6 @@ bitflags::bitflags! {
|
|||||||
/// The constraint solver will take this contact manifold into
|
/// The constraint solver will take this contact manifold into
|
||||||
/// account for force computation.
|
/// account for force computation.
|
||||||
const COMPUTE_IMPULSES = 0b001;
|
const COMPUTE_IMPULSES = 0b001;
|
||||||
/// The user-defined physics hooks will be used to
|
|
||||||
/// modify the solver contacts of this contact manifold.
|
|
||||||
const MODIFY_SOLVER_CONTACTS = 0b010;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,8 +53,10 @@ impl Default for ContactData {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
/// The description of all the contacts between a pair of colliders.
|
/// The description of all the contacts between a pair of colliders.
|
||||||
pub struct ContactPair {
|
pub struct ContactPair {
|
||||||
/// The pair of colliders involved.
|
/// The first collider involved in the contact pair.
|
||||||
pub pair: ColliderPair,
|
pub collider1: ColliderHandle,
|
||||||
|
/// The second collider involved in the contact pair.
|
||||||
|
pub collider2: ColliderHandle,
|
||||||
/// The set of contact manifolds between the two colliders.
|
/// The set of contact manifolds between the two colliders.
|
||||||
///
|
///
|
||||||
/// All contact manifold contain themselves contact points between the colliders.
|
/// All contact manifold contain themselves contact points between the colliders.
|
||||||
@@ -68,9 +67,10 @@ pub struct ContactPair {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ContactPair {
|
impl ContactPair {
|
||||||
pub(crate) fn new(pair: ColliderPair) -> Self {
|
pub(crate) fn new(collider1: ColliderHandle, collider2: ColliderHandle) -> Self {
|
||||||
Self {
|
Self {
|
||||||
pair,
|
collider1,
|
||||||
|
collider2,
|
||||||
has_any_active_contact: false,
|
has_any_active_contact: false,
|
||||||
manifolds: Vec::new(),
|
manifolds: Vec::new(),
|
||||||
workspace: None,
|
workspace: None,
|
||||||
|
|||||||
@@ -1,56 +1,66 @@
|
|||||||
#[repr(transparent)]
|
|
||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
|
||||||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
|
||||||
/// Pairwise filtering using bit masks.
|
/// Pairwise filtering using bit masks.
|
||||||
///
|
///
|
||||||
/// This filtering method is based on two 16-bit values:
|
/// This filtering method is based on two 32-bit values:
|
||||||
/// - The interaction groups (the 16 left-most bits of `self.0`).
|
/// - The interaction groups memberships.
|
||||||
/// - The interaction mask (the 16 right-most bits of `self.0`).
|
/// - The interaction groups filter.
|
||||||
///
|
///
|
||||||
/// An interaction is allowed between two filters `a` and `b` when two conditions
|
/// An interaction is allowed between two filters `a` and `b` when two conditions
|
||||||
/// are met simultaneously:
|
/// are met simultaneously:
|
||||||
/// - The interaction groups of `a` has at least one bit set to `1` in common with the interaction mask of `b`.
|
/// - The groups membership of `a` has at least one bit set to `1` in common with the groups filter of `b`.
|
||||||
/// - The interaction groups of `b` has at least one bit set to `1` in common with the interaction mask of `a`.
|
/// - The groups membership of `b` has at least one bit set to `1` in common with the groups filter of `a`.
|
||||||
///
|
///
|
||||||
/// In other words, interactions are allowed between two filter iff. the following condition is met:
|
/// In other words, interactions are allowed between two filter iff. the following condition is met:
|
||||||
/// ```ignore
|
/// ```ignore
|
||||||
/// ((self.0 >> 16) & rhs.0) != 0 && ((rhs.0 >> 16) & self.0) != 0
|
/// (self.memberships & rhs.filter) != 0 && (rhs.memberships & self.filter) != 0
|
||||||
/// ```
|
/// ```
|
||||||
pub struct InteractionGroups(pub u32);
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
|
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct InteractionGroups {
|
||||||
|
/// Groups memberships.
|
||||||
|
pub memberships: u32,
|
||||||
|
/// Groups filter.
|
||||||
|
pub filter: u32,
|
||||||
|
}
|
||||||
|
|
||||||
impl InteractionGroups {
|
impl InteractionGroups {
|
||||||
/// Initializes with the given interaction groups and interaction mask.
|
/// Initializes with the given interaction groups and interaction mask.
|
||||||
pub const fn new(groups: u16, masks: u16) -> Self {
|
pub const fn new(memberships: u32, filter: u32) -> Self {
|
||||||
Self::none().with_groups(groups).with_mask(masks)
|
Self {
|
||||||
|
memberships,
|
||||||
|
filter,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allow interaction with everything.
|
/// Allow interaction with everything.
|
||||||
pub const fn all() -> Self {
|
pub const fn all() -> Self {
|
||||||
Self(u32::MAX)
|
Self::new(u32::MAX, u32::MAX)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prevent all interactions.
|
/// Prevent all interactions.
|
||||||
pub const fn none() -> Self {
|
pub const fn none() -> Self {
|
||||||
Self(0)
|
Self::new(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the group this filter is part of.
|
/// Sets the group this filter is part of.
|
||||||
pub const fn with_groups(self, groups: u16) -> Self {
|
pub const fn with_memberships(mut self, memberships: u32) -> Self {
|
||||||
Self((self.0 & 0x0000ffff) | ((groups as u32) << 16))
|
self.memberships = memberships;
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the interaction mask of this filter.
|
/// Sets the interaction mask of this filter.
|
||||||
pub const fn with_mask(self, mask: u16) -> Self {
|
pub const fn with_filter(mut self, filter: u32) -> Self {
|
||||||
Self((self.0 & 0xffff0000) | (mask as u32))
|
self.filter = filter;
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if interactions should be allowed based on the interaction groups and mask.
|
/// Check if interactions should be allowed based on the interaction memberships and filter.
|
||||||
///
|
///
|
||||||
/// An interaction is allowed iff. the groups of `self` contain at least one bit set to 1 in common
|
/// An interaction is allowed iff. the memberships of `self` contain at least one bit set to 1 in common
|
||||||
/// with the mask of `rhs`, and vice-versa.
|
/// with the filter of `rhs`, and vice-versa.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn test(self, rhs: Self) -> bool {
|
pub const fn test(self, rhs: Self) -> bool {
|
||||||
((self.0 >> 16) & rhs.0) != 0 && ((rhs.0 >> 16) & self.0) != 0
|
(self.memberships & rhs.filter) != 0 && (rhs.memberships & self.filter) != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,18 @@ impl NarrowPhase {
|
|||||||
&self.intersection_graph
|
&self.intersection_graph
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// All the contacts involving the given collider.
|
||||||
|
///
|
||||||
|
/// It is strongly recommended to use the [`NarrowPhase::contacts_with`] method instead. This
|
||||||
|
/// method can be used if the generation number of the collider handle isn't known.
|
||||||
|
pub fn contacts_with_unknown_gen(
|
||||||
|
&self,
|
||||||
|
collider: u32,
|
||||||
|
) -> Option<impl Iterator<Item = (ColliderHandle, ColliderHandle, &ContactPair)>> {
|
||||||
|
let id = self.graph_indices.get_unknown_gen(collider)?;
|
||||||
|
Some(self.contact_graph.interactions_with(id.contact_graph_index))
|
||||||
|
}
|
||||||
|
|
||||||
/// All the contacts involving the given collider.
|
/// All the contacts involving the given collider.
|
||||||
pub fn contacts_with(
|
pub fn contacts_with(
|
||||||
&self,
|
&self,
|
||||||
@@ -106,6 +118,22 @@ impl NarrowPhase {
|
|||||||
Some(self.contact_graph.interactions_with(id.contact_graph_index))
|
Some(self.contact_graph.interactions_with(id.contact_graph_index))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// All the intersections involving the given collider.
|
||||||
|
///
|
||||||
|
/// It is strongly recommended to use the [`NarrowPhase::intersections_with`] method instead.
|
||||||
|
/// This method can be used if the generation number of the collider handle isn't known.
|
||||||
|
pub fn intersections_with_unknown_gen(
|
||||||
|
&self,
|
||||||
|
collider: u32,
|
||||||
|
) -> Option<impl Iterator<Item = (ColliderHandle, ColliderHandle, bool)> + '_> {
|
||||||
|
let id = self.graph_indices.get_unknown_gen(collider)?;
|
||||||
|
Some(
|
||||||
|
self.intersection_graph
|
||||||
|
.interactions_with(id.intersection_graph_index)
|
||||||
|
.map(|e| (e.0, e.1, *e.2)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// All the intersections involving the given collider.
|
/// All the intersections involving the given collider.
|
||||||
pub fn intersections_with(
|
pub fn intersections_with(
|
||||||
&self,
|
&self,
|
||||||
@@ -119,6 +147,22 @@ impl NarrowPhase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The contact pair involving two specific colliders.
|
||||||
|
///
|
||||||
|
/// It is strongly recommended to use the [`NarrowPhase::contact_pair`] method instead. This
|
||||||
|
/// method can be used if the generation number of the collider handle isn't known.
|
||||||
|
///
|
||||||
|
/// If this returns `None`, there is no contact between the two colliders.
|
||||||
|
/// If this returns `Some`, then there may be a contact between the two colliders. Check the
|
||||||
|
/// result [`ContactPair::has_any_active_collider`] method to see if there is an actual contact.
|
||||||
|
pub fn contact_pair_unknown_gen(&self, collider1: u32, collider2: u32) -> Option<&ContactPair> {
|
||||||
|
let id1 = self.graph_indices.get_unknown_gen(collider1)?;
|
||||||
|
let id2 = self.graph_indices.get_unknown_gen(collider2)?;
|
||||||
|
self.contact_graph
|
||||||
|
.interaction_pair(id1.contact_graph_index, id2.contact_graph_index)
|
||||||
|
.map(|c| c.2)
|
||||||
|
}
|
||||||
|
|
||||||
/// The contact pair involving two specific colliders.
|
/// The contact pair involving two specific colliders.
|
||||||
///
|
///
|
||||||
/// If this returns `None`, there is no contact between the two colliders.
|
/// If this returns `None`, there is no contact between the two colliders.
|
||||||
@@ -136,6 +180,21 @@ impl NarrowPhase {
|
|||||||
.map(|c| c.2)
|
.map(|c| c.2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The intersection pair involving two specific colliders.
|
||||||
|
///
|
||||||
|
/// It is strongly recommended to use the [`NarrowPhase::intersection_pair`] method instead. This
|
||||||
|
/// method can be used if the generation number of the collider handle isn't known.
|
||||||
|
///
|
||||||
|
/// If this returns `None` or `Some(false)`, then there is no intersection between the two colliders.
|
||||||
|
/// If this returns `Some(true)`, then there may be an intersection between the two colliders.
|
||||||
|
pub fn intersection_pair_unknown_gen(&self, collider1: u32, collider2: u32) -> Option<bool> {
|
||||||
|
let id1 = self.graph_indices.get_unknown_gen(collider1)?;
|
||||||
|
let id2 = self.graph_indices.get_unknown_gen(collider2)?;
|
||||||
|
self.intersection_graph
|
||||||
|
.interaction_pair(id1.intersection_graph_index, id2.intersection_graph_index)
|
||||||
|
.map(|c| *c.2)
|
||||||
|
}
|
||||||
|
|
||||||
/// The intersection pair involving two specific colliders.
|
/// The intersection pair involving two specific colliders.
|
||||||
///
|
///
|
||||||
/// If this returns `None` or `Some(false)`, then there is no intersection between the two colliders.
|
/// If this returns `None` or `Some(false)`, then there is no intersection between the two colliders.
|
||||||
@@ -527,7 +586,7 @@ impl NarrowPhase {
|
|||||||
.find_edge(gid1.contact_graph_index, gid2.contact_graph_index)
|
.find_edge(gid1.contact_graph_index, gid2.contact_graph_index)
|
||||||
.is_none()
|
.is_none()
|
||||||
{
|
{
|
||||||
let interaction = ContactPair::new(*pair);
|
let interaction = ContactPair::new(pair.collider1, pair.collider2);
|
||||||
let _ = self.contact_graph.add_edge(
|
let _ = self.contact_graph.add_edge(
|
||||||
gid1.contact_graph_index,
|
gid1.contact_graph_index,
|
||||||
gid2.contact_graph_index,
|
gid2.contact_graph_index,
|
||||||
@@ -585,7 +644,8 @@ impl NarrowPhase {
|
|||||||
+ ComponentSetOption<ColliderParent>
|
+ ComponentSetOption<ColliderParent>
|
||||||
+ ComponentSet<ColliderGroups>
|
+ ComponentSet<ColliderGroups>
|
||||||
+ ComponentSet<ColliderShape>
|
+ ComponentSet<ColliderShape>
|
||||||
+ ComponentSet<ColliderPosition>,
|
+ ComponentSet<ColliderPosition>
|
||||||
|
+ ComponentSet<ColliderMaterial>,
|
||||||
{
|
{
|
||||||
if modified_colliders.is_empty() {
|
if modified_colliders.is_empty() {
|
||||||
return;
|
return;
|
||||||
@@ -593,7 +653,6 @@ impl NarrowPhase {
|
|||||||
|
|
||||||
let nodes = &self.intersection_graph.graph.nodes;
|
let nodes = &self.intersection_graph.graph.nodes;
|
||||||
let query_dispatcher = &*self.query_dispatcher;
|
let query_dispatcher = &*self.query_dispatcher;
|
||||||
let active_hooks = hooks.active_hooks();
|
|
||||||
|
|
||||||
// TODO: don't iterate on all the edges.
|
// TODO: don't iterate on all the edges.
|
||||||
par_iter_mut!(&mut self.intersection_graph.graph.edges).for_each(|edge| {
|
par_iter_mut!(&mut self.intersection_graph.graph.edges).for_each(|edge| {
|
||||||
@@ -601,19 +660,21 @@ impl NarrowPhase {
|
|||||||
let handle2 = nodes[edge.target().index()].weight;
|
let handle2 = nodes[edge.target().index()].weight;
|
||||||
|
|
||||||
let co_parent1: Option<&ColliderParent> = colliders.get(handle1.0);
|
let co_parent1: Option<&ColliderParent> = colliders.get(handle1.0);
|
||||||
let (co_changes1, co_groups1, co_shape1, co_pos1): (
|
let (co_changes1, co_groups1, co_shape1, co_pos1, co_material1): (
|
||||||
&ColliderChanges,
|
&ColliderChanges,
|
||||||
&ColliderGroups,
|
&ColliderGroups,
|
||||||
&ColliderShape,
|
&ColliderShape,
|
||||||
&ColliderPosition,
|
&ColliderPosition,
|
||||||
|
&ColliderMaterial,
|
||||||
) = colliders.index_bundle(handle1.0);
|
) = colliders.index_bundle(handle1.0);
|
||||||
|
|
||||||
let co_parent2: Option<&ColliderParent> = colliders.get(handle2.0);
|
let co_parent2: Option<&ColliderParent> = colliders.get(handle2.0);
|
||||||
let (co_changes2, co_groups2, co_shape2, co_pos2): (
|
let (co_changes2, co_groups2, co_shape2, co_pos2, co_material2): (
|
||||||
&ColliderChanges,
|
&ColliderChanges,
|
||||||
&ColliderGroups,
|
&ColliderGroups,
|
||||||
&ColliderShape,
|
&ColliderShape,
|
||||||
&ColliderPosition,
|
&ColliderPosition,
|
||||||
|
&ColliderMaterial,
|
||||||
) = colliders.index_bundle(handle2.0);
|
) = colliders.index_bundle(handle2.0);
|
||||||
|
|
||||||
if !co_changes1.needs_narrow_phase_update() && !co_changes2.needs_narrow_phase_update()
|
if !co_changes1.needs_narrow_phase_update() && !co_changes2.needs_narrow_phase_update()
|
||||||
@@ -656,6 +717,8 @@ impl NarrowPhase {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let active_hooks = co_material1.active_hooks | co_material2.active_hooks;
|
||||||
|
|
||||||
if !active_hooks.contains(PhysicsHooksFlags::FILTER_INTERSECTION_PAIR)
|
if !active_hooks.contains(PhysicsHooksFlags::FILTER_INTERSECTION_PAIR)
|
||||||
&& !status1.is_dynamic()
|
&& !status1.is_dynamic()
|
||||||
&& !status2.is_dynamic()
|
&& !status2.is_dynamic()
|
||||||
@@ -721,29 +784,28 @@ impl NarrowPhase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let query_dispatcher = &*self.query_dispatcher;
|
let query_dispatcher = &*self.query_dispatcher;
|
||||||
let active_hooks = hooks.active_hooks();
|
|
||||||
|
|
||||||
// TODO: don't iterate on all the edges.
|
// TODO: don't iterate on all the edges.
|
||||||
par_iter_mut!(&mut self.contact_graph.graph.edges).for_each(|edge| {
|
par_iter_mut!(&mut self.contact_graph.graph.edges).for_each(|edge| {
|
||||||
let pair = &mut edge.weight;
|
let pair = &mut edge.weight;
|
||||||
|
|
||||||
let co_parent1: Option<&ColliderParent> = colliders.get(pair.pair.collider1.0);
|
let co_parent1: Option<&ColliderParent> = colliders.get(pair.collider1.0);
|
||||||
let (co_changes1, co_groups1, co_shape1, co_pos1, co_material1): (
|
let (co_changes1, co_groups1, co_shape1, co_pos1, co_material1): (
|
||||||
&ColliderChanges,
|
&ColliderChanges,
|
||||||
&ColliderGroups,
|
&ColliderGroups,
|
||||||
&ColliderShape,
|
&ColliderShape,
|
||||||
&ColliderPosition,
|
&ColliderPosition,
|
||||||
&ColliderMaterial,
|
&ColliderMaterial,
|
||||||
) = colliders.index_bundle(pair.pair.collider1.0);
|
) = colliders.index_bundle(pair.collider1.0);
|
||||||
|
|
||||||
let co_parent2: Option<&ColliderParent> = colliders.get(pair.pair.collider2.0);
|
let co_parent2: Option<&ColliderParent> = colliders.get(pair.collider2.0);
|
||||||
let (co_changes2, co_groups2, co_shape2, co_pos2, co_material2): (
|
let (co_changes2, co_groups2, co_shape2, co_pos2, co_material2): (
|
||||||
&ColliderChanges,
|
&ColliderChanges,
|
||||||
&ColliderGroups,
|
&ColliderGroups,
|
||||||
&ColliderShape,
|
&ColliderShape,
|
||||||
&ColliderPosition,
|
&ColliderPosition,
|
||||||
&ColliderMaterial,
|
&ColliderMaterial,
|
||||||
) = colliders.index_bundle(pair.pair.collider2.0);
|
) = colliders.index_bundle(pair.collider2.0);
|
||||||
|
|
||||||
if !co_changes1.needs_narrow_phase_update() && !co_changes2.needs_narrow_phase_update()
|
if !co_changes1.needs_narrow_phase_update() && !co_changes2.needs_narrow_phase_update()
|
||||||
{
|
{
|
||||||
@@ -785,6 +847,7 @@ impl NarrowPhase {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let active_hooks = co_material1.active_hooks | co_material2.active_hooks;
|
||||||
if !active_hooks.contains(PhysicsHooksFlags::FILTER_CONTACT_PAIR)
|
if !active_hooks.contains(PhysicsHooksFlags::FILTER_CONTACT_PAIR)
|
||||||
&& !status1.is_dynamic()
|
&& !status1.is_dynamic()
|
||||||
&& !status2.is_dynamic()
|
&& !status2.is_dynamic()
|
||||||
@@ -800,8 +863,8 @@ impl NarrowPhase {
|
|||||||
colliders,
|
colliders,
|
||||||
rigid_body1: co_parent1.map(|p| p.handle),
|
rigid_body1: co_parent1.map(|p| p.handle),
|
||||||
rigid_body2: co_parent2.map(|p| p.handle),
|
rigid_body2: co_parent2.map(|p| p.handle),
|
||||||
collider1: pair.pair.collider1,
|
collider1: pair.collider1,
|
||||||
collider2: pair.pair.collider2,
|
collider2: pair.collider2,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(solver_flags) = hooks.filter_contact_pair(&context) {
|
if let Some(solver_flags) = hooks.filter_contact_pair(&context) {
|
||||||
@@ -811,7 +874,7 @@ impl NarrowPhase {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
co_material1.solver_flags | co_material2.solver_flags
|
SolverFlags::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
if !co_groups1.solver_groups.test(co_groups2.solver_groups) {
|
if !co_groups1.solver_groups.test(co_groups2.solver_groups) {
|
||||||
@@ -896,12 +959,7 @@ impl NarrowPhase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply the user-defined contact modification.
|
// Apply the user-defined contact modification.
|
||||||
if active_hooks.contains(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS)
|
if active_hooks.contains(PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS) {
|
||||||
&& manifold
|
|
||||||
.data
|
|
||||||
.solver_flags
|
|
||||||
.contains(SolverFlags::MODIFY_SOLVER_CONTACTS)
|
|
||||||
{
|
|
||||||
let mut modifiable_solver_contacts =
|
let mut modifiable_solver_contacts =
|
||||||
std::mem::replace(&mut manifold.data.solver_contacts, Vec::new());
|
std::mem::replace(&mut manifold.data.solver_contacts, Vec::new());
|
||||||
let mut modifiable_user_data = manifold.data.user_data;
|
let mut modifiable_user_data = manifold.data.user_data;
|
||||||
@@ -912,8 +970,8 @@ impl NarrowPhase {
|
|||||||
colliders,
|
colliders,
|
||||||
rigid_body1: co_parent1.map(|p| p.handle),
|
rigid_body1: co_parent1.map(|p| p.handle),
|
||||||
rigid_body2: co_parent2.map(|p| p.handle),
|
rigid_body2: co_parent2.map(|p| p.handle),
|
||||||
collider1: pair.pair.collider1,
|
collider1: pair.collider1,
|
||||||
collider2: pair.pair.collider2,
|
collider2: pair.collider2,
|
||||||
manifold,
|
manifold,
|
||||||
solver_contacts: &mut modifiable_solver_contacts,
|
solver_contacts: &mut modifiable_solver_contacts,
|
||||||
normal: &mut modifiable_normal,
|
normal: &mut modifiable_normal,
|
||||||
@@ -931,13 +989,13 @@ impl NarrowPhase {
|
|||||||
if has_any_active_contact != pair.has_any_active_contact {
|
if has_any_active_contact != pair.has_any_active_contact {
|
||||||
if has_any_active_contact {
|
if has_any_active_contact {
|
||||||
events.handle_contact_event(ContactEvent::Started(
|
events.handle_contact_event(ContactEvent::Started(
|
||||||
pair.pair.collider1,
|
pair.collider1,
|
||||||
pair.pair.collider2,
|
pair.collider2,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
events.handle_contact_event(ContactEvent::Stopped(
|
events.handle_contact_event(ContactEvent::Stopped(
|
||||||
pair.pair.collider1,
|
pair.collider1,
|
||||||
pair.pair.collider2,
|
pair.collider2,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,3 +149,12 @@ pub mod math {
|
|||||||
#[cfg(feature = "dim3")]
|
#[cfg(feature = "dim3")]
|
||||||
pub const MAX_MANIFOLD_POINTS: usize = 4;
|
pub const MAX_MANIFOLD_POINTS: usize = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Prelude containing the common types defined by Rapier.
|
||||||
|
pub mod prelude {
|
||||||
|
pub use crate::dynamics::*;
|
||||||
|
pub use crate::geometry::*;
|
||||||
|
pub use crate::math::*;
|
||||||
|
pub use crate::pipeline::*;
|
||||||
|
pub use na::{point, vector, DMatrix, DVector};
|
||||||
|
}
|
||||||
|
|||||||
@@ -133,15 +133,30 @@ impl Default for PhysicsHooksFlags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// User-defined functions called by the physics engines during one timestep in order to customize its behavior.
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub trait PhysicsHooks<Bodies, Colliders>: Send + Sync {
|
pub trait PhysicsHooks<Bodies, Colliders> {
|
||||||
/// The sets of hooks that must be taken into account.
|
|
||||||
fn active_hooks(&self) -> PhysicsHooksFlags;
|
fn active_hooks(&self) -> PhysicsHooksFlags;
|
||||||
|
fn filter_contact_pair(
|
||||||
|
&self,
|
||||||
|
_context: &PairFilterContext<Bodies, Colliders>,
|
||||||
|
) -> Option<SolverFlags> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
fn filter_intersection_pair(&self, _context: &PairFilterContext<Bodies, Colliders>) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
fn modify_solver_contacts(&self, _context: &mut ContactModificationContext<Bodies, Colliders>) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// User-defined functions called by the physics engines during one timestep in order to customize its behavior.
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub trait PhysicsHooks<Bodies, Colliders>: Send + Sync {
|
||||||
/// Applies the contact pair filter.
|
/// Applies the contact pair filter.
|
||||||
///
|
///
|
||||||
/// Note that this method will only be called if `self.active_hooks()`
|
/// Note that this method will only be called if at least one of the colliders
|
||||||
/// contains the `PhysicsHooksFlags::FILTER_CONTACT_PAIR` flags.
|
/// involved in the contact contains the `PhysicsHooksFlags::FILTER_CONTACT_PAIR` flags
|
||||||
|
/// in its physics hooks flags.
|
||||||
///
|
///
|
||||||
/// User-defined filter for potential contact pairs detected by the broad-phase.
|
/// User-defined filter for potential contact pairs detected by the broad-phase.
|
||||||
/// This can be used to apply custom logic in order to decide whether two colliders
|
/// This can be used to apply custom logic in order to decide whether two colliders
|
||||||
@@ -165,13 +180,14 @@ pub trait PhysicsHooks<Bodies, Colliders>: Send + Sync {
|
|||||||
&self,
|
&self,
|
||||||
_context: &PairFilterContext<Bodies, Colliders>,
|
_context: &PairFilterContext<Bodies, Colliders>,
|
||||||
) -> Option<SolverFlags> {
|
) -> Option<SolverFlags> {
|
||||||
None
|
Some(SolverFlags::COMPUTE_IMPULSES)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies the intersection pair filter.
|
/// Applies the intersection pair filter.
|
||||||
///
|
///
|
||||||
/// Note that this method will only be called if `self.active_hooks()`
|
/// Note that this method will only be called if at least one of the colliders
|
||||||
/// contains the `PhysicsHooksFlags::FILTER_INTERSECTION_PAIR` flags.
|
/// involved in the contact contains the `PhysicsHooksFlags::FILTER_INTERSECTION_PAIR` flags
|
||||||
|
/// in its physics hooks flags.
|
||||||
///
|
///
|
||||||
/// User-defined filter for potential intersection pairs detected by the broad-phase.
|
/// User-defined filter for potential intersection pairs detected by the broad-phase.
|
||||||
///
|
///
|
||||||
@@ -188,13 +204,14 @@ pub trait PhysicsHooks<Bodies, Colliders>: Send + Sync {
|
|||||||
/// If this return `true` then the narrow-phase will compute intersection
|
/// If this return `true` then the narrow-phase will compute intersection
|
||||||
/// information for this pair.
|
/// information for this pair.
|
||||||
fn filter_intersection_pair(&self, _context: &PairFilterContext<Bodies, Colliders>) -> bool {
|
fn filter_intersection_pair(&self, _context: &PairFilterContext<Bodies, Colliders>) -> bool {
|
||||||
false
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modifies the set of contacts seen by the constraints solver.
|
/// Modifies the set of contacts seen by the constraints solver.
|
||||||
///
|
///
|
||||||
/// Note that this method will only be called if `self.active_hooks()`
|
/// Note that this method will only be called if at least one of the colliders
|
||||||
/// contains the `PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS` flags.
|
/// involved in the contact contains the `PhysicsHooksFlags::MODIFY_SOLVER_CONTACTS` flags
|
||||||
|
/// in its physics hooks flags.
|
||||||
///
|
///
|
||||||
/// By default, the content of `solver_contacts` is computed from `manifold.points`.
|
/// By default, the content of `solver_contacts` is computed from `manifold.points`.
|
||||||
/// This method will be called on each contact manifold which have the flag `SolverFlags::modify_solver_contacts` set.
|
/// This method will be called on each contact manifold which have the flag `SolverFlags::modify_solver_contacts` set.
|
||||||
@@ -220,16 +237,12 @@ pub trait PhysicsHooks<Bodies, Colliders>: Send + Sync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<Bodies, Colliders> PhysicsHooks<Bodies, Colliders> for () {
|
impl<Bodies, Colliders> PhysicsHooks<Bodies, Colliders> for () {
|
||||||
fn active_hooks(&self) -> PhysicsHooksFlags {
|
|
||||||
PhysicsHooksFlags::empty()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn filter_contact_pair(&self, _: &PairFilterContext<Bodies, Colliders>) -> Option<SolverFlags> {
|
fn filter_contact_pair(&self, _: &PairFilterContext<Bodies, Colliders>) -> Option<SolverFlags> {
|
||||||
None
|
Some(SolverFlags::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn filter_intersection_pair(&self, _: &PairFilterContext<Bodies, Colliders>) -> bool {
|
fn filter_intersection_pair(&self, _: &PairFilterContext<Bodies, Colliders>) -> bool {
|
||||||
false
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modify_solver_contacts(&self, _: &mut ContactModificationContext<Bodies, Colliders>) {}
|
fn modify_solver_contacts(&self, _: &mut ContactModificationContext<Bodies, Colliders>) {}
|
||||||
|
|||||||
@@ -87,11 +87,13 @@ impl Box2dWorld {
|
|||||||
|
|
||||||
fn insert_colliders(&mut self, colliders: &ColliderSet) {
|
fn insert_colliders(&mut self, colliders: &ColliderSet) {
|
||||||
for (_, collider) in colliders.iter() {
|
for (_, collider) in colliders.iter() {
|
||||||
let b2_body_handle = self.rapier2box2d[&collider.parent()];
|
if let Some(parent) = collider.parent() {
|
||||||
|
let b2_body_handle = self.rapier2box2d[&parent];
|
||||||
let mut b2_body = self.world.body_mut(b2_body_handle);
|
let mut b2_body = self.world.body_mut(b2_body_handle);
|
||||||
Self::create_fixture(&collider, &mut *b2_body);
|
Self::create_fixture(&collider, &mut *b2_body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn insert_joints(&mut self, joints: &JointSet) {
|
fn insert_joints(&mut self, joints: &JointSet) {
|
||||||
for joint in joints.iter() {
|
for joint in joints.iter() {
|
||||||
@@ -122,8 +124,8 @@ impl Box2dWorld {
|
|||||||
body_a,
|
body_a,
|
||||||
body_b,
|
body_b,
|
||||||
collide_connected: true,
|
collide_connected: true,
|
||||||
local_anchor_a: na_vec_to_b2_vec(params.local_anchor1.translation.vector),
|
local_anchor_a: na_vec_to_b2_vec(params.local_frame1.translation.vector),
|
||||||
local_anchor_b: na_vec_to_b2_vec(params.local_anchor2.translation.vector),
|
local_anchor_b: na_vec_to_b2_vec(params.local_frame2.translation.vector),
|
||||||
reference_angle: 0.0,
|
reference_angle: 0.0,
|
||||||
frequency: 0.0,
|
frequency: 0.0,
|
||||||
damping_ratio: 0.0,
|
damping_ratio: 0.0,
|
||||||
@@ -155,7 +157,14 @@ impl Box2dWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_fixture(collider: &Collider, body: &mut b2::MetaBody<NoUserData>) {
|
fn create_fixture(collider: &Collider, body: &mut b2::MetaBody<NoUserData>) {
|
||||||
let center = na_vec_to_b2_vec(collider.position_wrt_parent().translation.vector);
|
let center = na_vec_to_b2_vec(
|
||||||
|
collider
|
||||||
|
.position_wrt_parent()
|
||||||
|
.copied()
|
||||||
|
.unwrap_or(na::one())
|
||||||
|
.translation
|
||||||
|
.vector,
|
||||||
|
);
|
||||||
let mut fixture_def = b2::FixtureDef::new();
|
let mut fixture_def = b2::FixtureDef::new();
|
||||||
|
|
||||||
fixture_def.restitution = collider.material().restitution;
|
fixture_def.restitution = collider.material().restitution;
|
||||||
@@ -230,7 +239,9 @@ impl Box2dWorld {
|
|||||||
|
|
||||||
for coll_handle in body.colliders() {
|
for coll_handle in body.colliders() {
|
||||||
let collider = &mut colliders[*coll_handle];
|
let collider = &mut colliders[*coll_handle];
|
||||||
collider.set_position_debug(pos * collider.position_wrt_parent());
|
collider.set_position(
|
||||||
|
pos * collider.position_wrt_parent().copied().unwrap_or(na::one()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use na::Point3;
|
use na::{point, Point3};
|
||||||
|
|
||||||
use crate::math::Isometry;
|
use crate::math::Isometry;
|
||||||
use crate::objects::node::EntityWithGraphics;
|
use crate::objects::node::EntityWithGraphics;
|
||||||
@@ -34,7 +34,7 @@ impl GraphicsManager {
|
|||||||
b2sn: HashMap::new(),
|
b2sn: HashMap::new(),
|
||||||
b2color: HashMap::new(),
|
b2color: HashMap::new(),
|
||||||
c2color: HashMap::new(),
|
c2color: HashMap::new(),
|
||||||
ground_color: Point3::new(0.5, 0.5, 0.5),
|
ground_color: point![0.5, 0.5, 0.5],
|
||||||
b2wireframe: HashMap::new(),
|
b2wireframe: HashMap::new(),
|
||||||
prefab_meshes: HashMap::new(),
|
prefab_meshes: HashMap::new(),
|
||||||
}
|
}
|
||||||
@@ -57,9 +57,10 @@ impl GraphicsManager {
|
|||||||
pub fn remove_collider_nodes(
|
pub fn remove_collider_nodes(
|
||||||
&mut self,
|
&mut self,
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
body: RigidBodyHandle,
|
body: Option<RigidBodyHandle>,
|
||||||
collider: ColliderHandle,
|
collider: ColliderHandle,
|
||||||
) {
|
) {
|
||||||
|
let body = body.unwrap_or(RigidBodyHandle::invalid());
|
||||||
if let Some(sns) = self.b2sn.get_mut(&body) {
|
if let Some(sns) = self.b2sn.get_mut(&body) {
|
||||||
for sn in sns.iter_mut() {
|
for sn in sns.iter_mut() {
|
||||||
if sn.collider == collider {
|
if sn.collider == collider {
|
||||||
@@ -83,23 +84,23 @@ impl GraphicsManager {
|
|||||||
&mut self,
|
&mut self,
|
||||||
materials: &mut Assets<StandardMaterial>,
|
materials: &mut Assets<StandardMaterial>,
|
||||||
b: RigidBodyHandle,
|
b: RigidBodyHandle,
|
||||||
color: Point3<f32>,
|
color: [f32; 3],
|
||||||
) {
|
) {
|
||||||
self.b2color.insert(b, color);
|
self.b2color.insert(b, color.into());
|
||||||
|
|
||||||
if let Some(ns) = self.b2sn.get_mut(&b) {
|
if let Some(ns) = self.b2sn.get_mut(&b) {
|
||||||
for n in ns.iter_mut() {
|
for n in ns.iter_mut() {
|
||||||
n.set_color(materials, color)
|
n.set_color(materials, color.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_initial_body_color(&mut self, b: RigidBodyHandle, color: Point3<f32>) {
|
pub fn set_initial_body_color(&mut self, b: RigidBodyHandle, color: [f32; 3]) {
|
||||||
self.b2color.insert(b, color);
|
self.b2color.insert(b, color.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_initial_collider_color(&mut self, c: ColliderHandle, color: Point3<f32>) {
|
pub fn set_initial_collider_color(&mut self, c: ColliderHandle, color: [f32; 3]) {
|
||||||
self.c2color.insert(c, color);
|
self.c2color.insert(c, color.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_body_wireframe(&mut self, b: RigidBodyHandle, enabled: bool) {
|
pub fn set_body_wireframe(&mut self, b: RigidBodyHandle, enabled: bool) {
|
||||||
@@ -118,18 +119,18 @@ impl GraphicsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_wireframe_mode(&mut self, colliders: &ColliderSet, _enabled: bool) {
|
pub fn toggle_wireframe_mode(&mut self, _colliders: &ColliderSet, _enabled: bool) {
|
||||||
for n in self.b2sn.values_mut().flat_map(|val| val.iter_mut()) {
|
for _n in self.b2sn.values_mut().flat_map(|val| val.iter_mut()) {
|
||||||
let _force_wireframe = if let Some(collider) = colliders.get(n.collider) {
|
// let _force_wireframe = if let Some(collider) = colliders.get(n.collider) {
|
||||||
collider.is_sensor()
|
// collider.is_sensor()
|
||||||
|| self
|
// || self
|
||||||
.b2wireframe
|
// .b2wireframe
|
||||||
.get(&collider.parent())
|
// .get(&collider.parent())
|
||||||
.cloned()
|
// .cloned()
|
||||||
.unwrap_or(false)
|
// .unwrap_or(false)
|
||||||
} else {
|
// } else {
|
||||||
false
|
// false
|
||||||
};
|
// };
|
||||||
|
|
||||||
// if let Some(node) = n.scene_node_mut() {
|
// if let Some(node) = n.scene_node_mut() {
|
||||||
// if force_wireframe || enabled {
|
// if force_wireframe || enabled {
|
||||||
@@ -171,7 +172,7 @@ impl GraphicsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_body_color(materials, handle, color);
|
self.set_body_color(materials, handle, color.into());
|
||||||
|
|
||||||
color
|
color
|
||||||
}
|
}
|
||||||
@@ -257,10 +258,10 @@ impl GraphicsManager {
|
|||||||
colliders: &ColliderSet,
|
colliders: &ColliderSet,
|
||||||
) {
|
) {
|
||||||
let collider = &colliders[handle];
|
let collider = &colliders[handle];
|
||||||
let color = *self.b2color.get(&collider.parent()).unwrap();
|
let collider_parent = collider.parent().unwrap_or(RigidBodyHandle::invalid());
|
||||||
|
let color = *self.b2color.get(&collider_parent).unwrap();
|
||||||
let color = self.c2color.get(&handle).copied().unwrap_or(color);
|
let color = self.c2color.get(&handle).copied().unwrap_or(color);
|
||||||
let mut nodes =
|
let mut nodes = std::mem::replace(self.b2sn.get_mut(&collider_parent).unwrap(), Vec::new());
|
||||||
std::mem::replace(self.b2sn.get_mut(&collider.parent()).unwrap(), Vec::new());
|
|
||||||
self.do_add_shape(
|
self.do_add_shape(
|
||||||
commands,
|
commands,
|
||||||
meshes,
|
meshes,
|
||||||
@@ -273,7 +274,7 @@ impl GraphicsManager {
|
|||||||
color,
|
color,
|
||||||
&mut nodes,
|
&mut nodes,
|
||||||
);
|
);
|
||||||
self.b2sn.insert(collider.parent(), nodes);
|
self.b2sn.insert(collider_parent, nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_add_shape(
|
fn do_add_shape(
|
||||||
@@ -338,9 +339,9 @@ impl GraphicsManager {
|
|||||||
//
|
//
|
||||||
// if bo.is_dynamic() {
|
// if bo.is_dynamic() {
|
||||||
// if bo.is_ccd_active() {
|
// if bo.is_ccd_active() {
|
||||||
// n.set_color(Point3::new(1.0, 0.0, 0.0));
|
// n.set_color(point![1.0, 0.0, 0.0]);
|
||||||
// } else {
|
// } else {
|
||||||
// n.set_color(Point3::new(0.0, 1.0, 0.0));
|
// n.set_color(point![0.0, 1.0, 0.0]);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
@@ -365,9 +366,9 @@ impl GraphicsManager {
|
|||||||
// let y = rotmat.column(1) * 0.25f32;
|
// let y = rotmat.column(1) * 0.25f32;
|
||||||
// let z = rotmat.column(2) * 0.25f32;
|
// let z = rotmat.column(2) * 0.25f32;
|
||||||
|
|
||||||
// window.draw_line(center, &(*center + x), &Point3::new(1.0, 0.0, 0.0));
|
// window.draw_line(center, &(*center + x), &point![1.0, 0.0, 0.0]);
|
||||||
// window.draw_line(center, &(*center + y), &Point3::new(0.0, 1.0, 0.0));
|
// window.draw_line(center, &(*center + y), &point![0.0, 1.0, 0.0]);
|
||||||
// window.draw_line(center, &(*center + z), &Point3::new(0.0, 0.0, 1.0));
|
// window.draw_line(center, &(*center + z), &point![0.0, 0.0, 1.0]);
|
||||||
// // }
|
// // }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -55,8 +55,9 @@ impl NPhysicsWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (_, collider) in colliders.iter() {
|
for (_, collider) in colliders.iter() {
|
||||||
let parent = &bodies[collider.parent()];
|
if let Some(parent_handle) = collider.parent() {
|
||||||
let nphysics_rb_handle = rapier2nphysics[&collider.parent()];
|
let parent = &bodies[parent_handle];
|
||||||
|
let nphysics_rb_handle = rapier2nphysics[&parent_handle];
|
||||||
if let Some(collider) =
|
if let Some(collider) =
|
||||||
nphysics_collider_from_rapier_collider(&collider, parent.is_dynamic())
|
nphysics_collider_from_rapier_collider(&collider, parent.is_dynamic())
|
||||||
{
|
{
|
||||||
@@ -66,6 +67,7 @@ impl NPhysicsWorld {
|
|||||||
eprintln!("Creating shape unknown to the nphysics backend.")
|
eprintln!("Creating shape unknown to the nphysics backend.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for joint in joints.iter() {
|
for joint in joints.iter() {
|
||||||
let b1 = BodyPartHandle(rapier2nphysics[&joint.1.body1], 0);
|
let b1 = BodyPartHandle(rapier2nphysics[&joint.1.body1], 0);
|
||||||
@@ -76,10 +78,10 @@ impl NPhysicsWorld {
|
|||||||
let c = FixedConstraint::new(
|
let c = FixedConstraint::new(
|
||||||
b1,
|
b1,
|
||||||
b2,
|
b2,
|
||||||
params.local_anchor1.translation.vector.into(),
|
params.local_frame1.translation.vector.into(),
|
||||||
params.local_anchor1.rotation,
|
params.local_frame1.rotation,
|
||||||
params.local_anchor2.translation.vector.into(),
|
params.local_frame2.translation.vector.into(),
|
||||||
params.local_anchor2.rotation,
|
params.local_frame2.rotation,
|
||||||
);
|
);
|
||||||
nphysics_joints.insert(c);
|
nphysics_joints.insert(c);
|
||||||
}
|
}
|
||||||
@@ -172,7 +174,9 @@ impl NPhysicsWorld {
|
|||||||
|
|
||||||
for coll_handle in rb.colliders() {
|
for coll_handle in rb.colliders() {
|
||||||
let collider = &mut colliders[*coll_handle];
|
let collider = &mut colliders[*coll_handle];
|
||||||
collider.set_position_debug(pos * collider.position_wrt_parent());
|
collider.set_position(
|
||||||
|
pos * collider.position_wrt_parent().copied().unwrap_or(na::one()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,7 +187,7 @@ fn nphysics_collider_from_rapier_collider(
|
|||||||
is_dynamic: bool,
|
is_dynamic: bool,
|
||||||
) -> Option<ColliderDesc<f32>> {
|
) -> Option<ColliderDesc<f32>> {
|
||||||
let mut margin = ColliderDesc::<f32>::default_margin();
|
let mut margin = ColliderDesc::<f32>::default_margin();
|
||||||
let mut pos = *collider.position_wrt_parent();
|
let mut pos = collider.position_wrt_parent().copied().unwrap_or(na::one());
|
||||||
let shape = collider.shape();
|
let shape = collider.shape();
|
||||||
|
|
||||||
let shape = if let Some(cuboid) = shape.as_cuboid() {
|
let shape = if let Some(cuboid) = shape.as_cuboid() {
|
||||||
@@ -209,7 +213,7 @@ fn nphysics_collider_from_rapier_collider(
|
|||||||
trimesh
|
trimesh
|
||||||
.indices()
|
.indices()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|idx| na::Point3::new(idx[0] as usize, idx[1] as usize, idx[2] as usize))
|
.map(|idx| na::point![idx[0] as usize, idx[1] as usize, idx[2] as usize])
|
||||||
.collect(),
|
.collect(),
|
||||||
None,
|
None,
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use bevy::prelude::*;
|
|||||||
use bevy::render::mesh::{Indices, VertexAttributeValues};
|
use bevy::render::mesh::{Indices, VertexAttributeValues};
|
||||||
|
|
||||||
//use crate::objects::plane::Plane;
|
//use crate::objects::plane::Plane;
|
||||||
use na::{Point3, Vector3};
|
use na::{point, Point3, Vector3};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use bevy::render::pipeline::PrimitiveTopology;
|
use bevy::render::pipeline::PrimitiveTopology;
|
||||||
@@ -106,7 +106,7 @@ impl EntityWithGraphics {
|
|||||||
pub fn select(&mut self, materials: &mut Assets<StandardMaterial>) {
|
pub fn select(&mut self, materials: &mut Assets<StandardMaterial>) {
|
||||||
// NOTE: we don't just call `self.set_color` because that would
|
// NOTE: we don't just call `self.set_color` because that would
|
||||||
// overwrite self.base_color too.
|
// overwrite self.base_color too.
|
||||||
self.color = Point3::new(1.0, 0.0, 0.0);
|
self.color = point![1.0, 0.0, 0.0];
|
||||||
if let Some(material) = materials.get_mut(&self.material) {
|
if let Some(material) = materials.get_mut(&self.material) {
|
||||||
material.base_color = Color::rgb(self.color.x, self.color.y, self.color.z);
|
material.base_color = Color::rgb(self.color.x, self.color.y, self.color.z);
|
||||||
}
|
}
|
||||||
@@ -210,10 +210,10 @@ impl EntityWithGraphics {
|
|||||||
// Halfspace
|
// Halfspace
|
||||||
//
|
//
|
||||||
let vertices = vec![
|
let vertices = vec![
|
||||||
Point3::new(-1000.0, 0.0, -1000.0),
|
point![-1000.0, 0.0, -1000.0],
|
||||||
Point3::new(1000.0, 0.0, -1000.0),
|
point![1000.0, 0.0, -1000.0],
|
||||||
Point3::new(1000.0, 0.0, 1000.0),
|
point![1000.0, 0.0, 1000.0],
|
||||||
Point3::new(-1000.0, 0.0, 1000.0),
|
point![-1000.0, 0.0, 1000.0],
|
||||||
];
|
];
|
||||||
let indices = vec![[0, 1, 2], [0, 2, 3]];
|
let indices = vec![[0, 1, 2], [0, 2, 3]];
|
||||||
let mesh = bevy_mesh((vertices, indices));
|
let mesh = bevy_mesh((vertices, indices));
|
||||||
@@ -365,7 +365,7 @@ fn generate_collider_mesh(co_shape: &dyn Shape) -> Option<Mesh> {
|
|||||||
let vertices = trimesh
|
let vertices = trimesh
|
||||||
.vertices()
|
.vertices()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| Point3::new(p.x, p.y, 0.0))
|
.map(|p| point![p.x, p.y, 0.0])
|
||||||
.collect();
|
.collect();
|
||||||
bevy_mesh((vertices, trimesh.indices().to_vec()))
|
bevy_mesh((vertices, trimesh.indices().to_vec()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,25 +220,30 @@ impl PhysxWorld {
|
|||||||
if let Some((mut px_shape, px_material, collider_pos)) =
|
if let Some((mut px_shape, px_material, collider_pos)) =
|
||||||
physx_collider_from_rapier_collider(&mut *physics, &mut cooking, &collider)
|
physx_collider_from_rapier_collider(&mut *physics, &mut cooking, &collider)
|
||||||
{
|
{
|
||||||
let parent_body = &bodies[collider.parent()];
|
if let Some(parent_handle) = collider.parent() {
|
||||||
|
let parent_body = &bodies[parent_handle];
|
||||||
|
|
||||||
if !parent_body.is_dynamic() {
|
if !parent_body.is_dynamic() {
|
||||||
let actor = rapier2static.get_mut(&collider.parent()).unwrap();
|
let actor = rapier2static.get_mut(&parent_handle).unwrap();
|
||||||
actor.attach_shape(&mut px_shape);
|
actor.attach_shape(&mut px_shape);
|
||||||
} else {
|
} else {
|
||||||
let actor = rapier2dynamic.get_mut(&collider.parent()).unwrap();
|
let actor = rapier2dynamic.get_mut(&parent_handle).unwrap();
|
||||||
actor.attach_shape(&mut px_shape);
|
actor.attach_shape(&mut px_shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let pose = collider_pos.into_physx();
|
let pose = collider_pos.into_physx();
|
||||||
physx_sys::PxShape_setLocalPose_mut(px_shape.as_mut_ptr(), &pose.into());
|
physx_sys::PxShape_setLocalPose_mut(
|
||||||
|
px_shape.as_mut_ptr(),
|
||||||
|
&pose.into(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
shapes.push(px_shape);
|
shapes.push(px_shape);
|
||||||
materials.push(px_material);
|
materials.push(px_material);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update mass properties and CCD flags.
|
// Update mass properties and CCD flags.
|
||||||
for (rapier_handle, actor) in rapier2dynamic.iter_mut() {
|
for (rapier_handle, actor) in rapier2dynamic.iter_mut() {
|
||||||
@@ -454,8 +459,8 @@ impl PhysxWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
JointParams::FixedJoint(params) => {
|
JointParams::FixedJoint(params) => {
|
||||||
let frame1 = params.local_anchor1.into_physx().into();
|
let frame1 = params.local_frame1.into_physx().into();
|
||||||
let frame2 = params.local_anchor2.into_physx().into();
|
let frame2 = params.local_frame2.into_physx().into();
|
||||||
|
|
||||||
physx_sys::phys_PxFixedJointCreate(
|
physx_sys::phys_PxFixedJointCreate(
|
||||||
physics.as_mut_ptr(),
|
physics.as_mut_ptr(),
|
||||||
@@ -500,7 +505,9 @@ impl PhysxWorld {
|
|||||||
|
|
||||||
for coll_handle in rb.colliders() {
|
for coll_handle in rb.colliders() {
|
||||||
let collider = &mut colliders[*coll_handle];
|
let collider = &mut colliders[*coll_handle];
|
||||||
collider.set_position_debug(pos * collider.position_wrt_parent());
|
collider.set_position(
|
||||||
|
pos * collider.position_wrt_parent().copied().unwrap_or(na::one()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -511,7 +518,7 @@ fn physx_collider_from_rapier_collider(
|
|||||||
cooking: &PxCooking,
|
cooking: &PxCooking,
|
||||||
collider: &Collider,
|
collider: &Collider,
|
||||||
) -> Option<(Owner<PxShape>, Owner<PxMaterial>, Isometry3<f32>)> {
|
) -> Option<(Owner<PxShape>, Owner<PxMaterial>, Isometry3<f32>)> {
|
||||||
let mut local_pose = *collider.position_wrt_parent();
|
let mut local_pose = collider.position_wrt_parent().copied().unwrap_or(na::one());
|
||||||
let shape = collider.shape();
|
let shape = collider.shape();
|
||||||
let shape_flags = if collider.is_sensor() {
|
let shape_flags = if collider.is_sensor() {
|
||||||
ShapeFlag::TriggerShape.into()
|
ShapeFlag::TriggerShape.into()
|
||||||
|
|||||||
@@ -429,7 +429,7 @@ impl TestbedApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'c, 'd> TestbedGraphics<'a, 'b, 'c, 'd> {
|
impl<'a, 'b, 'c, 'd> TestbedGraphics<'a, 'b, 'c, 'd> {
|
||||||
pub fn set_body_color(&mut self, body: RigidBodyHandle, color: Point3<f32>) {
|
pub fn set_body_color(&mut self, body: RigidBodyHandle, color: [f32; 3]) {
|
||||||
self.manager
|
self.manager
|
||||||
.set_body_color(&mut self.materials, body, color);
|
.set_body_color(&mut self.materials, body, color);
|
||||||
}
|
}
|
||||||
@@ -588,13 +588,13 @@ impl<'a, 'b, 'c, 'd> Testbed<'a, 'b, 'c, 'd> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_initial_body_color(&mut self, body: RigidBodyHandle, color: Point3<f32>) {
|
pub fn set_initial_body_color(&mut self, body: RigidBodyHandle, color: [f32; 3]) {
|
||||||
if let Some(graphics) = &mut self.graphics {
|
if let Some(graphics) = &mut self.graphics {
|
||||||
graphics.manager.set_initial_body_color(body, color);
|
graphics.manager.set_initial_body_color(body, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_initial_collider_color(&mut self, collider: ColliderHandle, color: Point3<f32>) {
|
pub fn set_initial_collider_color(&mut self, collider: ColliderHandle, color: [f32; 3]) {
|
||||||
if let Some(graphics) = &mut self.graphics {
|
if let Some(graphics) = &mut self.graphics {
|
||||||
graphics.manager.set_initial_collider_color(collider, color);
|
graphics.manager.set_initial_collider_color(collider, color);
|
||||||
}
|
}
|
||||||
@@ -752,14 +752,14 @@ fn draw_contacts(_nf: &NarrowPhase, _colliders: &ColliderSet) {
|
|||||||
// let n = manifold.data.normal;
|
// let n = manifold.data.normal;
|
||||||
//
|
//
|
||||||
// use crate::engine::GraphicsWindow;
|
// use crate::engine::GraphicsWindow;
|
||||||
// window.draw_graphics_line(&p, &(p + n * 0.4), &Point3::new(0.5, 1.0, 0.5));
|
// window.draw_graphics_line(&p, &(p + n * 0.4), &point![0.5, 1.0, 0.5]);
|
||||||
// }
|
// }
|
||||||
// */
|
// */
|
||||||
// for pt in manifold.contacts() {
|
// for pt in manifold.contacts() {
|
||||||
// let color = if pt.dist > 0.0 {
|
// let color = if pt.dist > 0.0 {
|
||||||
// Point3::new(0.0, 0.0, 1.0)
|
// point![0.0, 0.0, 1.0]
|
||||||
// } else {
|
// } else {
|
||||||
// Point3::new(1.0, 0.0, 0.0)
|
// point![1.0, 0.0, 0.0]
|
||||||
// };
|
// };
|
||||||
// let pos1 = colliders[pair.pair.collider1].position();
|
// let pos1 = colliders[pair.pair.collider1].position();
|
||||||
// let pos2 = colliders[pair.pair.collider2].position();
|
// let pos2 = colliders[pair.pair.collider2].position();
|
||||||
@@ -771,7 +771,7 @@ fn draw_contacts(_nf: &NarrowPhase, _colliders: &ColliderSet) {
|
|||||||
// * manifold.subshape_pos1.unwrap_or(Isometry::identity())
|
// * manifold.subshape_pos1.unwrap_or(Isometry::identity())
|
||||||
// * manifold.local_n1;
|
// * manifold.local_n1;
|
||||||
//
|
//
|
||||||
// // window.draw_graphics_line(&start, &(start + n * 0.4), &Point3::new(0.5, 1.0, 0.5));
|
// // window.draw_graphics_line(&start, &(start + n * 0.4), &point![0.5, 1.0, 0.5]);
|
||||||
// // window.draw_graphics_line(&start, &end, &color);
|
// // window.draw_graphics_line(&start, &end, &color);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
@@ -1228,12 +1228,15 @@ fn highlight_hovered_body(
|
|||||||
|
|
||||||
if let Some((handle, _)) = hit {
|
if let Some((handle, _)) = hit {
|
||||||
let collider = &physics.colliders[handle];
|
let collider = &physics.colliders[handle];
|
||||||
if physics.bodies[collider.parent()].is_dynamic() {
|
|
||||||
testbed_state.highlighted_body = Some(collider.parent());
|
if let Some(parent_handle) = collider.parent() {
|
||||||
for node in graphics_manager.body_nodes_mut(collider.parent()).unwrap() {
|
if physics.bodies[parent_handle].is_dynamic() {
|
||||||
|
testbed_state.highlighted_body = Some(parent_handle);
|
||||||
|
for node in graphics_manager.body_nodes_mut(parent_handle).unwrap() {
|
||||||
node.select(materials)
|
node.select(materials)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user