Outsource the contact manifold, SAT, and some shapes.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use na::{DMatrix, Point3, Vector3};
|
||||
use na::{ComplexField, DMatrix, Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier_testbed3d::Testbed;
|
||||
@@ -23,7 +23,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
} else {
|
||||
let x = i as f32 * ground_size.x / (nsubdivs as f32);
|
||||
let z = j as f32 * ground_size.z / (nsubdivs as f32);
|
||||
x.sin() + z.cos()
|
||||
|
||||
// NOTE: make sure we use the sin/cos from simba to ensure
|
||||
// cross-platform determinism of the example when the
|
||||
// enhanced_determinism feature is enabled.
|
||||
<f32 as ComplexField>::sin(x) + <f32 as ComplexField>::cos(z)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use na::Point3;
|
||||
use na::{ComplexField, DMatrix, Point3, Vector3};
|
||||
use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet};
|
||||
use rapier3d::geometry::{ColliderBuilder, ColliderSet, HeightField};
|
||||
use rapier_testbed3d::Testbed;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
@@ -14,28 +14,27 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 200.0f32;
|
||||
let ground_height = 1.0;
|
||||
let ground_size = Vector3::new(200.0, 1.0, 200.0);
|
||||
let nsubdivs = 20;
|
||||
|
||||
let quad = rapier3d::ncollide::procedural::quad(ground_size, ground_size, nsubdivs, nsubdivs);
|
||||
let indices = quad
|
||||
.flat_indices()
|
||||
.chunks(3)
|
||||
.map(|is| Point3::new(is[0], is[2], is[1]))
|
||||
.collect();
|
||||
let mut vertices = quad.coords;
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
if i == 0 || i == nsubdivs || j == 0 || j == nsubdivs {
|
||||
10.0
|
||||
} else {
|
||||
let x = i as f32 * ground_size.x / (nsubdivs as f32);
|
||||
let z = j as f32 * ground_size.z / (nsubdivs as f32);
|
||||
|
||||
// ncollide generates a quad with `z` as the normal.
|
||||
// so we switch z and y here and set a random altitude at each point.
|
||||
for p in vertices.iter_mut() {
|
||||
p.z = p.y;
|
||||
p.y = (p.x.sin() + p.z.cos()) * ground_height;
|
||||
|
||||
if p.x.abs() == ground_size / 2.0 || p.z.abs() == ground_size / 2.0 {
|
||||
p.y = 10.0;
|
||||
// NOTE: make sure we use the sin/cos from simba to ensure
|
||||
// cross-platform determinism of the example when the
|
||||
// enhanced_determinism feature is enabled.
|
||||
<f32 as ComplexField>::sin(x) + <f32 as ComplexField>::cos(z)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Here we will build our trimesh from the mesh representation of an
|
||||
// heightfield.
|
||||
let heightfield = HeightField::new(heights, ground_size);
|
||||
let (vertices, indices) = heightfield.to_trimesh();
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new_static().build();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
Reference in New Issue
Block a user