feat: migrate to glam whenever relevant + migrate testbed to kiss3d instead of bevy + release v0.32.0 (#909)
* feat: migrate to glam whenever relevant + migrate testbed to kiss3d instead of bevy * chore: update changelog * Fix warnings and tests * Release v0.32.0
This commit is contained in:
@@ -21,10 +21,12 @@ serde = "1"
|
||||
bincode = "1"
|
||||
serde_json = "1"
|
||||
dot_vox = "5"
|
||||
glam = { version = "0.30.9", features = ["fast-math"] }
|
||||
kiss3d = { version = "0.40.0", features = ["egui", "parry", "serde"] }
|
||||
|
||||
[dependencies.rapier_testbed3d]
|
||||
path = "../crates/rapier_testbed3d"
|
||||
features = ["profiler_ui"]
|
||||
#features = ["profiler_ui"]
|
||||
|
||||
[dependencies.rapier3d]
|
||||
path = "../crates/rapier3d"
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
#![allow(dead_code)]
|
||||
#![allow(clippy::type_complexity)]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use rapier_testbed3d::{Testbed, TestbedApp};
|
||||
use std::cmp::Ordering;
|
||||
use rapier_testbed3d::{Example, TestbedApp};
|
||||
|
||||
mod utils;
|
||||
|
||||
mod ccd3;
|
||||
mod character_controller3;
|
||||
mod collision_groups3;
|
||||
mod compound3;
|
||||
mod convex_decomposition3;
|
||||
@@ -20,36 +17,34 @@ mod debug_articulations3;
|
||||
mod debug_balls3;
|
||||
mod debug_big_colliders3;
|
||||
mod debug_boxes3;
|
||||
mod debug_chain_high_mass_ratio3;
|
||||
mod debug_cube_high_mass_ratio3;
|
||||
mod debug_cylinder3;
|
||||
mod debug_deserialize3;
|
||||
mod debug_disabled3;
|
||||
mod debug_dynamic_collider_add3;
|
||||
mod debug_friction3;
|
||||
mod debug_infinite_fall3;
|
||||
mod debug_internal_edges3;
|
||||
mod debug_long_chain3;
|
||||
mod debug_multibody_ang_motor_pos3;
|
||||
mod debug_pop3;
|
||||
mod debug_prismatic3;
|
||||
mod debug_rollback3;
|
||||
mod debug_shape_modification3;
|
||||
mod debug_sleeping_kinematic3;
|
||||
mod debug_thin_cube_on_mesh3;
|
||||
mod debug_triangle3;
|
||||
mod debug_trimesh3;
|
||||
mod debug_two_cubes3;
|
||||
mod domino3;
|
||||
mod dynamic_trimesh3;
|
||||
mod fountain3;
|
||||
mod heightfield3;
|
||||
mod joints3;
|
||||
// mod joints3;
|
||||
mod character_controller3;
|
||||
mod debug_chain_high_mass_ratio3;
|
||||
mod debug_cube_high_mass_ratio3;
|
||||
mod debug_disabled3;
|
||||
mod debug_internal_edges3;
|
||||
mod debug_long_chain3;
|
||||
mod debug_multibody_ang_motor_pos3;
|
||||
mod debug_sleeping_kinematic3;
|
||||
mod debug_two_cubes3;
|
||||
mod gyroscopic3;
|
||||
mod heightfield3;
|
||||
mod inverse_kinematics3;
|
||||
mod joint_motor_position3;
|
||||
mod joints3;
|
||||
mod keva3;
|
||||
mod locked_rotations3;
|
||||
mod newton_cradle3;
|
||||
@@ -60,101 +55,162 @@ mod restitution3;
|
||||
mod rope_joints3;
|
||||
mod sensor3;
|
||||
mod spring_joints3;
|
||||
mod stress_tests;
|
||||
mod trimesh3;
|
||||
mod urdf3;
|
||||
mod vehicle_controller3;
|
||||
mod vehicle_joints3;
|
||||
mod voxels3;
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
|
||||
pub fn main() {
|
||||
let mut builders: Vec<(_, fn(&mut Testbed))> = vec![
|
||||
("Character controller", character_controller3::init_world),
|
||||
("Fountain", fountain3::init_world),
|
||||
("Primitives", primitives3::init_world),
|
||||
("Multibody joints", joints3::init_world_with_articulations),
|
||||
("CCD", ccd3::init_world),
|
||||
("Collision groups", collision_groups3::init_world),
|
||||
("Compound", compound3::init_world),
|
||||
("Convex decomposition", convex_decomposition3::init_world),
|
||||
("Convex polyhedron", convex_polyhedron3::init_world),
|
||||
("Damping", damping3::init_world),
|
||||
("Gyroscopic", gyroscopic3::init_world),
|
||||
("Domino", domino3::init_world),
|
||||
("Dynamic trimeshes", dynamic_trimesh3::init_world),
|
||||
("Heightfield", heightfield3::init_world),
|
||||
("Impulse Joints", joints3::init_world_with_joints),
|
||||
("Inverse kinematics", inverse_kinematics3::init_world),
|
||||
("Joint Motor Position", joint_motor_position3::init_world),
|
||||
("Locked rotations", locked_rotations3::init_world),
|
||||
("One-way platforms", one_way_platforms3::init_world),
|
||||
("Platform", platform3::init_world),
|
||||
("Restitution", restitution3::init_world),
|
||||
("Rope Joints", rope_joints3::init_world),
|
||||
("Sensor", sensor3::init_world),
|
||||
("Spring Joints", spring_joints3::init_world),
|
||||
("TriMesh", trimesh3::init_world),
|
||||
("Urdf", urdf3::init_world),
|
||||
("Voxels", voxels3::init_world),
|
||||
("Vehicle controller", vehicle_controller3::init_world),
|
||||
("Vehicle joints", vehicle_joints3::init_world),
|
||||
("Keva tower", keva3::init_world),
|
||||
("Newton cradle", newton_cradle3::init_world),
|
||||
("(Debug) multibody_joints", debug_articulations3::init_world),
|
||||
(
|
||||
"(Debug) add/rm collider",
|
||||
#[kiss3d::main]
|
||||
pub async fn main() {
|
||||
const COLLISIONS: &str = "Collisions";
|
||||
const DYNAMICS: &str = "Dynamics";
|
||||
const COMPLEX: &str = "Complex Shapes";
|
||||
const JOINTS: &str = "Joints";
|
||||
const CONTROLS: &str = "Controls";
|
||||
const DEBUG: &str = "Debug";
|
||||
const ROBOTICS: &str = "Robotics";
|
||||
|
||||
let mut builders: Vec<Example> = vec![
|
||||
// ── Collisions ──────────────────────────────────────────────────────────
|
||||
Example::new(COLLISIONS, "Fountain", fountain3::init_world),
|
||||
Example::new(COLLISIONS, "Primitives", primitives3::init_world),
|
||||
Example::new(COLLISIONS, "Keva tower", keva3::init_world),
|
||||
Example::new(COLLISIONS, "Newton cradle", newton_cradle3::init_world),
|
||||
Example::new(COLLISIONS, "Domino", domino3::init_world),
|
||||
Example::new(COLLISIONS, "Platform", platform3::init_world),
|
||||
Example::new(COLLISIONS, "Sensor", sensor3::init_world),
|
||||
Example::new(COLLISIONS, "Compound", compound3::init_world),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
Example::new(
|
||||
COLLISIONS,
|
||||
"Convex decomposition",
|
||||
convex_decomposition3::init_world,
|
||||
),
|
||||
Example::new(
|
||||
COLLISIONS,
|
||||
"Convex polyhedron",
|
||||
convex_polyhedron3::init_world,
|
||||
),
|
||||
Example::new(COLLISIONS, "TriMesh", trimesh3::init_world),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
Example::new(
|
||||
COLLISIONS,
|
||||
"Dynamic trimeshes",
|
||||
dynamic_trimesh3::init_world,
|
||||
),
|
||||
Example::new(COLLISIONS, "Heightfield", heightfield3::init_world),
|
||||
Example::new(COLLISIONS, "Voxels", voxels3::init_world),
|
||||
Example::new(
|
||||
COLLISIONS,
|
||||
"Collision groups",
|
||||
collision_groups3::init_world,
|
||||
),
|
||||
Example::new(
|
||||
COLLISIONS,
|
||||
"One-way platforms",
|
||||
one_way_platforms3::init_world,
|
||||
),
|
||||
// ── Dynamics ─────────────────────────────────────────────────────────
|
||||
Example::new(DYNAMICS, "Locked rotations", locked_rotations3::init_world),
|
||||
Example::new(DYNAMICS, "Restitution", restitution3::init_world),
|
||||
Example::new(DYNAMICS, "Damping", damping3::init_world),
|
||||
Example::new(DYNAMICS, "Gyroscopic", gyroscopic3::init_world),
|
||||
Example::new(DYNAMICS, "CCD", ccd3::init_world),
|
||||
// ── Joints ─────────────────────────────────────────────────────────
|
||||
Example::new(JOINTS, "Impulse Joints", joints3::init_world_with_joints),
|
||||
Example::new(
|
||||
JOINTS,
|
||||
"Multibody Joints",
|
||||
joints3::init_world_with_articulations,
|
||||
),
|
||||
Example::new(JOINTS, "Rope Joints", rope_joints3::init_world),
|
||||
Example::new(JOINTS, "Spring Joints", spring_joints3::init_world),
|
||||
Example::new(
|
||||
JOINTS,
|
||||
"Joint Motor Position",
|
||||
joint_motor_position3::init_world,
|
||||
),
|
||||
Example::new(
|
||||
JOINTS,
|
||||
"Inverse kinematics",
|
||||
inverse_kinematics3::init_world,
|
||||
),
|
||||
// ── Controls ─────────────────────────────────────────────────────
|
||||
Example::new(
|
||||
CONTROLS,
|
||||
"Character controller",
|
||||
character_controller3::init_world,
|
||||
),
|
||||
Example::new(
|
||||
CONTROLS,
|
||||
"Vehicle controller",
|
||||
vehicle_controller3::init_world,
|
||||
),
|
||||
Example::new(CONTROLS, "Vehicle joints", vehicle_joints3::init_world),
|
||||
// ── Robotics ───────────────────────────────────────────────────────
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
Example::new(ROBOTICS, "URDF", urdf3::init_world),
|
||||
// ── Debug ──────────────────────────────────────────────────────────
|
||||
Example::new(DEBUG, "Multibody joints", debug_articulations3::init_world),
|
||||
Example::new(
|
||||
DEBUG,
|
||||
"Add/rm collider",
|
||||
debug_add_remove_collider3::init_world,
|
||||
),
|
||||
("(Debug) big colliders", debug_big_colliders3::init_world),
|
||||
("(Debug) boxes", debug_boxes3::init_world),
|
||||
("(Debug) balls", debug_balls3::init_world),
|
||||
("(Debug) disabled", debug_disabled3::init_world),
|
||||
("(Debug) two cubes", debug_two_cubes3::init_world),
|
||||
("(Debug) pop", debug_pop3::init_world),
|
||||
(
|
||||
"(Debug) dyn. coll. add",
|
||||
Example::new(DEBUG, "Big colliders", debug_big_colliders3::init_world),
|
||||
Example::new(DEBUG, "Boxes", debug_boxes3::init_world),
|
||||
Example::new(DEBUG, "Balls", debug_balls3::init_world),
|
||||
Example::new(DEBUG, "Disabled", debug_disabled3::init_world),
|
||||
Example::new(DEBUG, "Two cubes", debug_two_cubes3::init_world),
|
||||
Example::new(DEBUG, "Pop", debug_pop3::init_world),
|
||||
Example::new(
|
||||
DEBUG,
|
||||
"Dyn. collider add",
|
||||
debug_dynamic_collider_add3::init_world,
|
||||
),
|
||||
("(Debug) friction", debug_friction3::init_world),
|
||||
("(Debug) internal edges", debug_internal_edges3::init_world),
|
||||
("(Debug) long chain", debug_long_chain3::init_world),
|
||||
(
|
||||
"(Debug) high mass ratio: chain",
|
||||
Example::new(DEBUG, "Friction", debug_friction3::init_world),
|
||||
Example::new(DEBUG, "Internal edges", debug_internal_edges3::init_world),
|
||||
Example::new(DEBUG, "Long chain", debug_long_chain3::init_world),
|
||||
Example::new(
|
||||
DEBUG,
|
||||
"High mass ratio: chain",
|
||||
debug_chain_high_mass_ratio3::init_world,
|
||||
),
|
||||
(
|
||||
"(Debug) high mass ratio: cube",
|
||||
Example::new(
|
||||
DEBUG,
|
||||
"High mass ratio: cube",
|
||||
debug_cube_high_mass_ratio3::init_world,
|
||||
),
|
||||
("(Debug) triangle", debug_triangle3::init_world),
|
||||
("(Debug) trimesh", debug_trimesh3::init_world),
|
||||
("(Debug) thin cube", debug_thin_cube_on_mesh3::init_world),
|
||||
("(Debug) cylinder", debug_cylinder3::init_world),
|
||||
("(Debug) infinite fall", debug_infinite_fall3::init_world),
|
||||
("(Debug) prismatic", debug_prismatic3::init_world),
|
||||
("(Debug) rollback", debug_rollback3::init_world),
|
||||
(
|
||||
"(Debug) shape modification",
|
||||
Example::new(DEBUG, "Triangle", debug_triangle3::init_world),
|
||||
Example::new(DEBUG, "Trimesh", debug_trimesh3::init_world),
|
||||
Example::new(DEBUG, "Thin cube", debug_thin_cube_on_mesh3::init_world),
|
||||
Example::new(DEBUG, "Cylinder", debug_cylinder3::init_world),
|
||||
Example::new(DEBUG, "Infinite fall", debug_infinite_fall3::init_world),
|
||||
Example::new(DEBUG, "Prismatic", debug_prismatic3::init_world),
|
||||
Example::new(DEBUG, "Rollback", debug_rollback3::init_world),
|
||||
Example::new(
|
||||
DEBUG,
|
||||
"Shape modification",
|
||||
debug_shape_modification3::init_world,
|
||||
),
|
||||
(
|
||||
"(Debug) sleeping kinematics",
|
||||
Example::new(
|
||||
DEBUG,
|
||||
"Sleeping kinematics",
|
||||
debug_sleeping_kinematic3::init_world,
|
||||
),
|
||||
("(Debug) deserialize", debug_deserialize3::init_world),
|
||||
(
|
||||
"(Debug) multibody ang. motor pos.",
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
Example::new(DEBUG, "Deserialize", debug_deserialize3::init_world),
|
||||
Example::new(
|
||||
DEBUG,
|
||||
"Multibody ang. motor pos.",
|
||||
debug_multibody_ang_motor_pos3::init_world,
|
||||
),
|
||||
];
|
||||
|
||||
// Lexicographic sort, with stress tests moved at the end of the list.
|
||||
builders.sort_by(|a, b| match (a.0.starts_with('('), b.0.starts_with('(')) {
|
||||
(true, true) | (false, false) => a.0.cmp(b.0),
|
||||
(true, false) => Ordering::Greater,
|
||||
(false, true) => Ordering::Less,
|
||||
});
|
||||
let mut benches = stress_tests::builders();
|
||||
builders.append(&mut benches);
|
||||
|
||||
let testbed = TestbedApp::from_builders(builders);
|
||||
testbed.run()
|
||||
testbed.run().await
|
||||
}
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use rapier_testbed3d::{Testbed, TestbedApp};
|
||||
use std::cmp::Ordering;
|
||||
|
||||
mod ccd3;
|
||||
mod collision_groups3;
|
||||
mod compound3;
|
||||
mod convex_decomposition3;
|
||||
mod convex_polyhedron3;
|
||||
mod damping3;
|
||||
mod debug_add_remove_collider3;
|
||||
mod debug_big_colliders3;
|
||||
mod debug_boxes3;
|
||||
mod debug_cylinder3;
|
||||
mod debug_dynamic_collider_add3;
|
||||
mod debug_friction3;
|
||||
mod debug_infinite_fall3;
|
||||
mod debug_prismatic3;
|
||||
mod debug_rollback3;
|
||||
mod debug_shape_modification3;
|
||||
mod debug_triangle3;
|
||||
mod debug_trimesh3;
|
||||
mod domino3;
|
||||
mod fountain3;
|
||||
mod heightfield3;
|
||||
mod joints3;
|
||||
mod keva3;
|
||||
mod locked_rotations3;
|
||||
mod one_way_platforms3;
|
||||
mod platform3;
|
||||
mod primitives3;
|
||||
mod restitution3;
|
||||
mod sensor3;
|
||||
mod trimesh3;
|
||||
|
||||
fn demo_name_from_command_line() -> Option<String> {
|
||||
let mut args = std::env::args();
|
||||
|
||||
while let Some(arg) = args.next() {
|
||||
if &arg[..] == "--example" {
|
||||
return args.next();
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn demo_name_from_url() -> Option<String> {
|
||||
None
|
||||
// let window = stdweb::web::window();
|
||||
// let hash = window.location()?.search().ok()?;
|
||||
// if hash.len() > 0 {
|
||||
// Some(hash[1..].to_string())
|
||||
// } else {
|
||||
// None
|
||||
// }
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn demo_name_from_url() -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
|
||||
pub fn main() {
|
||||
let demo = demo_name_from_command_line()
|
||||
.or_else(|| demo_name_from_url())
|
||||
.unwrap_or(String::new())
|
||||
.to_camel_case();
|
||||
|
||||
let mut builders: Vec<(_, fn(&mut Testbed))> = vec![
|
||||
("Fountain", fountain3::init_world),
|
||||
("Primitives", primitives3::init_world),
|
||||
("CCD", ccd3::init_world),
|
||||
("Collision groups", collision_groups3::init_world),
|
||||
("Compound", compound3::init_world),
|
||||
("Convex decomposition", convex_decomposition3::init_world),
|
||||
("Convex polyhedron", convex_polyhedron3::init_world),
|
||||
("Damping", damping3::init_world),
|
||||
("Domino", domino3::init_world),
|
||||
("Heightfield", heightfield3::init_world),
|
||||
("Joints", joints3::init_world),
|
||||
("Locked rotations", locked_rotations3::init_world),
|
||||
("One-way platforms", one_way_platforms3::init_world),
|
||||
("Platform", platform3::init_world),
|
||||
("Restitution", restitution3::init_world),
|
||||
("Sensor", sensor3::init_world),
|
||||
("TriMesh", trimesh3::init_world),
|
||||
("Keva tower", keva3::init_world),
|
||||
(
|
||||
"(Debug) add/rm collider",
|
||||
debug_add_remove_collider3::init_world,
|
||||
),
|
||||
("(Debug) big colliders", debug_big_colliders3::init_world),
|
||||
("(Debug) boxes", debug_boxes3::init_world),
|
||||
(
|
||||
"(Debug) dyn. coll. add",
|
||||
debug_dynamic_collider_add3::init_world,
|
||||
),
|
||||
("(Debug) friction", debug_friction3::init_world),
|
||||
("(Debug) triangle", debug_triangle3::init_world),
|
||||
("(Debug) trimesh", debug_trimesh3::init_world),
|
||||
("(Debug) cylinder", debug_cylinder3::init_world),
|
||||
("(Debug) infinite fall", debug_infinite_fall3::init_world),
|
||||
("(Debug) prismatic", debug_prismatic3::init_world),
|
||||
("(Debug) rollback", debug_rollback3::init_world),
|
||||
(
|
||||
"(Debug) shape modification",
|
||||
debug_shape_modification3::init_world,
|
||||
),
|
||||
];
|
||||
|
||||
// Lexicographic sort, with stress tests moved at the end of the list.
|
||||
builders.sort_by(|a, b| match (a.0.starts_with("("), b.0.starts_with("(")) {
|
||||
(true, true) | (false, false) => a.0.cmp(b.0),
|
||||
(true, false) => Ordering::Greater,
|
||||
(false, true) => Ordering::Less,
|
||||
});
|
||||
|
||||
let testbed = TestbedApp::from_builders(builders);
|
||||
testbed.run()
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
use kiss3d::color::Color;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
@@ -5,9 +6,9 @@ fn create_wall(
|
||||
testbed: &mut Testbed,
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vector<f32>,
|
||||
offset: Vector,
|
||||
stack_height: usize,
|
||||
half_extents: Vector<f32>,
|
||||
half_extents: Vector,
|
||||
) {
|
||||
let shift = half_extents * 2.0;
|
||||
let mut k = 0;
|
||||
@@ -21,15 +22,17 @@ fn create_wall(
|
||||
- stack_height as f32 * half_extents.z;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
k += 1;
|
||||
if k % 2 == 0 {
|
||||
testbed.set_initial_body_color(handle, [1., 131. / 255., 244.0 / 255.]);
|
||||
testbed
|
||||
.set_initial_body_color(handle, Color::new(1., 131. / 255., 244.0 / 255., 1.0));
|
||||
} else {
|
||||
testbed.set_initial_body_color(handle, [131. / 255., 1., 244.0 / 255.]);
|
||||
testbed
|
||||
.set_initial_body_color(handle, Color::new(131. / 255., 1., 244.0 / 255., 1.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +53,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 50.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
@@ -69,18 +72,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
testbed,
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
vector![x, shift_y, 0.0],
|
||||
Vector::new(x, shift_y, 0.0),
|
||||
num_z,
|
||||
vector![0.5, 0.5, 1.0],
|
||||
Vector::new(0.5, 0.5, 1.0),
|
||||
);
|
||||
|
||||
create_wall(
|
||||
testbed,
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
vector![x, shift_y, shift_z],
|
||||
Vector::new(x, shift_y, shift_z),
|
||||
num_z,
|
||||
vector![0.5, 0.5, 1.0],
|
||||
Vector::new(0.5, 0.5, 1.0),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -94,8 +97,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
.sensor(true)
|
||||
.active_events(ActiveEvents::COLLISION_EVENTS);
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.linvel(vector![1000.0, 0.0, 0.0])
|
||||
.translation(vector![-20.0, shift_y + 2.0, 0.0])
|
||||
.linvel(Vector::new(1000.0, 0.0, 0.0))
|
||||
.translation(Vector::new(-20.0, shift_y + 2.0, 0.0))
|
||||
.ccd_enabled(true);
|
||||
let sensor_handle = bodies.insert(rigid_body);
|
||||
colliders.insert_with_parent(collider, sensor_handle, &mut bodies);
|
||||
@@ -103,20 +106,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// Second rigid-body with CCD enabled.
|
||||
let collider = ColliderBuilder::ball(1.0).density(10.0);
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.linvel(vector![1000.0, 0.0, 0.0])
|
||||
.translation(vector![-20.0, shift_y + 2.0, shift_z])
|
||||
.linvel(Vector::new(1000.0, 0.0, 0.0))
|
||||
.translation(Vector::new(-20.0, shift_y + 2.0, shift_z))
|
||||
.ccd_enabled(true);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
colliders.insert_with_parent(collider.clone(), handle, &mut bodies);
|
||||
testbed.set_initial_body_color(handle, [0.2, 0.2, 1.0]);
|
||||
testbed.set_initial_body_color(handle, Color::new(0.2, 0.2, 1.0, 1.0));
|
||||
|
||||
// Callback that will be executed on the main loop to handle proximities.
|
||||
testbed.add_callback(move |mut graphics, physics, events, _| {
|
||||
while let Ok(prox) = events.collision_events.try_recv() {
|
||||
let color = if prox.started() {
|
||||
[1.0, 1.0, 0.0]
|
||||
Color::new(1.0, 1.0, 0.0, 1.0)
|
||||
} else {
|
||||
[0.5, 0.5, 1.0]
|
||||
Color::new(0.5, 0.5, 1.0, 1.0)
|
||||
};
|
||||
|
||||
let parent_handle1 = physics
|
||||
@@ -134,10 +137,10 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
if let Some(graphics) = &mut graphics {
|
||||
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
||||
graphics.set_body_color(parent_handle1, color);
|
||||
graphics.set_body_color(parent_handle1, color, false);
|
||||
}
|
||||
if parent_handle2 != ground_handle && parent_handle2 != sensor_handle {
|
||||
graphics.set_body_color(parent_handle2, color);
|
||||
graphics.set_body_color(parent_handle2, color, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,5 +150,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::utils::character::{self, CharacterControlMode};
|
||||
use kiss3d::color::Color;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::{
|
||||
control::{KinematicCharacterController, PidController},
|
||||
@@ -22,7 +23,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0] * scale);
|
||||
RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0) * scale);
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(
|
||||
ground_size * scale,
|
||||
@@ -31,8 +32,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, -ground_size] * scale); //.rotation(vector![-0.1, 0.0, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed()
|
||||
.translation(Vector::new(0.0, -ground_height, -ground_size) * scale); //.rotation(Vector::new(-0.1, 0.0, 0.0));
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(
|
||||
ground_size * scale,
|
||||
@@ -45,7 +46,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Character we will control manually.
|
||||
*/
|
||||
let rigid_body = RigidBodyBuilder::kinematic_position_based()
|
||||
.translation(vector![0.0, 0.5, 0.0] * scale)
|
||||
.translation(Vector::new(0.0, 0.5, 0.0) * scale)
|
||||
// The two config below makes the character
|
||||
// nicer to control with the PID control enabled.
|
||||
.gravity_scale(10.0)
|
||||
@@ -53,7 +54,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let character_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_y(0.3 * scale, 0.15 * scale); // 0.15, 0.3, 0.15);
|
||||
colliders.insert_with_parent(collider, character_handle, &mut bodies);
|
||||
testbed.set_initial_body_color(character_handle, [0.8, 0.1, 0.1]);
|
||||
testbed.set_initial_body_color(character_handle, Color::new(0.8, 0.1, 0.1, 1.0));
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -72,7 +73,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = j as f32 * shift + centery;
|
||||
let z = k as f32 * shift + centerx;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z] * scale);
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z) * scale);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad * scale, rad * scale, rad * scale);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -94,7 +96,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
stair_height / 2.0 * scale,
|
||||
stair_width * scale,
|
||||
)
|
||||
.translation(vector![x * scale, y * scale, 0.0]);
|
||||
.translation(Vector::new(x * scale, y * scale, 0.0));
|
||||
colliders.insert(collider);
|
||||
}
|
||||
|
||||
@@ -104,8 +106,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let slope_angle = 0.2;
|
||||
let slope_size = 2.0;
|
||||
let collider = ColliderBuilder::cuboid(slope_size, ground_height, slope_size)
|
||||
.translation(vector![0.1 + slope_size, -ground_height + 0.4, 0.0])
|
||||
.rotation(Vector::z() * slope_angle);
|
||||
.translation(Vector::new(0.1 + slope_size, -ground_height + 0.4, 0.0))
|
||||
.rotation(Vector::Z * slope_angle);
|
||||
colliders.insert(collider);
|
||||
|
||||
/*
|
||||
@@ -119,20 +121,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
ground_size * scale,
|
||||
)
|
||||
.translation(
|
||||
vector![
|
||||
Vector::new(
|
||||
0.1 + slope_size * 2.0 + impossible_slope_size - 0.9,
|
||||
-ground_height + 1.7,
|
||||
0.0
|
||||
] * scale,
|
||||
0.0,
|
||||
) * scale,
|
||||
)
|
||||
.rotation(Vector::z() * impossible_slope_angle);
|
||||
.rotation(Vector::Z * impossible_slope_angle);
|
||||
colliders.insert(collider);
|
||||
|
||||
/*
|
||||
* Create a moving platform.
|
||||
*/
|
||||
let body =
|
||||
RigidBodyBuilder::kinematic_velocity_based().translation(vector![-8.0, 0.0, 0.0] * scale);
|
||||
let body = RigidBodyBuilder::kinematic_velocity_based()
|
||||
.translation(Vector::new(-8.0, 0.0, 0.0) * scale);
|
||||
// .rotation(-0.3);
|
||||
let platform_handle = bodies.insert(body);
|
||||
let collider = ColliderBuilder::cuboid(2.0 * scale, ground_height * scale, 2.0 * scale);
|
||||
@@ -144,36 +146,36 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = Vector::new(10.0, 1.0, 10.0);
|
||||
let nsubdivs = 20;
|
||||
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
let heights = Array2::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
(i as f32 * ground_size.x / (nsubdivs as f32) / 2.0).cos()
|
||||
+ (j as f32 * ground_size.z / (nsubdivs as f32) / 2.0).cos()
|
||||
});
|
||||
|
||||
let collider = ColliderBuilder::heightfield(heights, ground_size * scale)
|
||||
.translation(vector![-8.0, 5.0, 0.0] * scale);
|
||||
.translation(Vector::new(-8.0, 5.0, 0.0) * scale);
|
||||
colliders.insert(collider);
|
||||
|
||||
/*
|
||||
* A tilting dynamic body with a limited joint.
|
||||
*/
|
||||
let ground = RigidBodyBuilder::fixed().translation(vector![0.0, 5.0, 0.0] * scale);
|
||||
let ground = RigidBodyBuilder::fixed().translation(Vector::new(0.0, 5.0, 0.0) * scale);
|
||||
let ground_handle = bodies.insert(ground);
|
||||
let body = RigidBodyBuilder::dynamic().translation(vector![0.0, 5.0, 0.0] * scale);
|
||||
let body = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 5.0, 0.0) * scale);
|
||||
let handle = bodies.insert(body);
|
||||
let collider = ColliderBuilder::cuboid(1.0 * scale, 0.1 * scale, 2.0 * scale);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
let joint = RevoluteJointBuilder::new(Vector::z_axis()).limits([-0.3, 0.3]);
|
||||
let joint = RevoluteJointBuilder::new(Vector::Z).limits([-0.3, 0.3]);
|
||||
impulse_joints.insert(ground_handle, handle, joint, true);
|
||||
|
||||
/*
|
||||
* Setup a callback to move the platform.
|
||||
*/
|
||||
testbed.add_callback(move |_, physics, _, run_state| {
|
||||
let linvel = vector![
|
||||
let linvel = Vector::new(
|
||||
(run_state.time * 2.0).sin() * 2.0,
|
||||
(run_state.time * 5.0).sin() * 1.5,
|
||||
0.0
|
||||
] * scale;
|
||||
0.0,
|
||||
) * scale;
|
||||
// let angvel = run_state.time.sin() * 0.5;
|
||||
|
||||
// Update the velocity-based kinematic body by setting its velocity.
|
||||
@@ -213,5 +215,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point!(10.0, 10.0, 10.0), Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use kiss3d::color::{BLUE, GREEN};
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
@@ -16,7 +17,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 5.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
@@ -33,22 +34,22 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* A green floor that will collide with the GREEN group only.
|
||||
*/
|
||||
let green_floor = ColliderBuilder::cuboid(1.0, 0.1, 1.0)
|
||||
.translation(vector![0.0, 1.0, 0.0])
|
||||
.translation(Vector::new(0.0, 1.0, 0.0))
|
||||
.collision_groups(GREEN_GROUP);
|
||||
let green_collider_handle =
|
||||
colliders.insert_with_parent(green_floor, floor_handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_collider_color(green_collider_handle, [0.0, 1.0, 0.0]);
|
||||
testbed.set_initial_collider_color(green_collider_handle, BLUE);
|
||||
|
||||
/*
|
||||
* A blue floor that will collide with the BLUE group only.
|
||||
*/
|
||||
let blue_floor = ColliderBuilder::cuboid(1.0, 0.1, 1.0)
|
||||
.translation(vector![0.0, 2.0, 0.0])
|
||||
.translation(Vector::new(0.0, 2.0, 0.0))
|
||||
.collision_groups(BLUE_GROUP);
|
||||
let blue_collider_handle = colliders.insert_with_parent(blue_floor, floor_handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_collider_color(blue_collider_handle, [0.0, 0.0, 1.0]);
|
||||
testbed.set_initial_collider_color(blue_collider_handle, GREEN);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
@@ -70,12 +71,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Alternate between the green and blue groups.
|
||||
let (group, color) = if k % 2 == 0 {
|
||||
(GREEN_GROUP, [0.0, 1.0, 0.0])
|
||||
(GREEN_GROUP, GREEN)
|
||||
} else {
|
||||
(BLUE_GROUP, [0.0, 0.0, 1.0])
|
||||
(BLUE_GROUP, BLUE)
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).collision_groups(group);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -89,5 +90,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point!(10.0, 10.0, 10.0), Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 50.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -43,32 +43,29 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift * 2.0 - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
// First option: attach several colliders to a single rigid-body.
|
||||
if j < numy / 2 {
|
||||
let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad);
|
||||
let collider2 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
||||
.translation(vector![rad * 10.0, rad * 10.0, 0.0]);
|
||||
.translation(Vector::new(rad * 10.0, rad * 10.0, 0.0));
|
||||
let collider3 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
||||
.translation(vector![-rad * 10.0, rad * 10.0, 0.0]);
|
||||
.translation(Vector::new(-rad * 10.0, rad * 10.0, 0.0));
|
||||
colliders.insert_with_parent(collider1, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider2, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider3, handle, &mut bodies);
|
||||
} else {
|
||||
// Second option: create a compound shape and attach it to a single collider.
|
||||
let shapes = vec![
|
||||
(Pose::IDENTITY, SharedShape::cuboid(rad * 10.0, rad, rad)),
|
||||
(
|
||||
Isometry::identity(),
|
||||
SharedShape::cuboid(rad * 10.0, rad, rad),
|
||||
),
|
||||
(
|
||||
Isometry::translation(rad * 10.0, rad * 10.0, 0.0),
|
||||
Pose::from_translation(Vector::new(rad * 10.0, rad * 10.0, 0.0)),
|
||||
SharedShape::cuboid(rad, rad * 10.0, rad),
|
||||
),
|
||||
(
|
||||
Isometry::translation(-rad * 10.0, rad * 10.0, 0.0),
|
||||
Pose::from_translation(Vector::new(-rad * 10.0, rad * 10.0, 0.0)),
|
||||
SharedShape::cuboid(rad, rad * 10.0, rad),
|
||||
),
|
||||
];
|
||||
@@ -86,5 +83,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 40.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -47,12 +47,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
let mut points = Vec::new();
|
||||
for _ in 0..10 {
|
||||
let pt: Point<f32> = distribution.sample(&mut rng);
|
||||
points.push(pt * scale);
|
||||
let pt: SimdPoint<f32> = distribution.sample(&mut rng);
|
||||
points.push(Vector::new(pt.x, pt.y, pt.z) * scale);
|
||||
}
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::round_convex_hull(&points, border_rad).unwrap();
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -64,5 +64,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![30.0, 30.0, 30.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(30.0, 30.0, 30.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Build the rigid body.
|
||||
let rb = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![x, y, 0.0])
|
||||
.linvel(vector![x * 10.0, y * 10.0, 0.0])
|
||||
.angvel(Vector::z() * 100.0)
|
||||
.translation(Vector::new(x, y, 0.0))
|
||||
.linvel(Vector::new(x * 10.0, y * 10.0, 0.0))
|
||||
.angvel(Vector::Z * 100.0)
|
||||
.linear_damping((i + 1) as f32 * subdiv * 10.0)
|
||||
.angular_damping((num - i) as f32 * subdiv * 10.0);
|
||||
let rb_handle = bodies.insert(rb);
|
||||
@@ -43,8 +43,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
colliders,
|
||||
impulse_joints,
|
||||
multibody_joints,
|
||||
Vector::zeros(),
|
||||
Vector::ZERO,
|
||||
(),
|
||||
);
|
||||
testbed.look_at(point![2.0, 2.5, 20.0], point![2.0, 2.5, 0.0]);
|
||||
testbed.look_at(Vec3::new(2.0, 2.5, 20.0), Vec3::new(2.0, 2.5, 0.0));
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 3.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4);
|
||||
let mut ground_collider_handle =
|
||||
@@ -26,7 +26,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Rolling ball
|
||||
*/
|
||||
let ball_rad = 0.1;
|
||||
let rb = RigidBodyBuilder::dynamic().translation(vector![0.0, 0.2, 0.0]);
|
||||
let rb = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 0.2, 0.0));
|
||||
let ball_handle = bodies.insert(rb);
|
||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0);
|
||||
colliders.insert_with_parent(collider, ball_handle, &mut bodies);
|
||||
@@ -53,5 +53,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ fn create_ball_articulations(
|
||||
RigidBodyType::Dynamic
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(vector![
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(Vector::new(
|
||||
fk * shift,
|
||||
0.0,
|
||||
fi * shift * 2.0
|
||||
]);
|
||||
fi * shift * 2.0,
|
||||
));
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_z(rad * 1.25, rad);
|
||||
colliders.insert_with_parent(collider, child_handle, bodies);
|
||||
@@ -38,7 +38,7 @@ fn create_ball_articulations(
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint =
|
||||
SphericalJointBuilder::new().local_anchor2(point![0.0, 0.0, -shift * 2.0]);
|
||||
SphericalJointBuilder::new().local_anchor2(Vector::new(0.0, 0.0, -shift * 2.0));
|
||||
multibody_joints.insert(parent_handle, child_handle, joint, true);
|
||||
}
|
||||
|
||||
@@ -46,12 +46,13 @@ fn create_ball_articulations(
|
||||
if k > 0 && i > 0 {
|
||||
let parent_index = body_handles.len() - num;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = SphericalJointBuilder::new().local_anchor2(point![-shift, 0.0, 0.0]);
|
||||
let joint =
|
||||
SphericalJointBuilder::new().local_anchor2(Vector::new(-shift, 0.0, 0.0));
|
||||
// let joint =
|
||||
// PrismaticJoint::new(Vector::y_axis()).local_anchor2(point![-shift, 0.0, 0.0]);
|
||||
// let joint = FixedJoint::new().local_anchor2(point![-shift, 0.0, 0.0]);
|
||||
// PrismaticJoint::new(Vector::Y).local_anchor2(Vector::new(-shift, 0.0, 0.0));
|
||||
// let joint = FixedJoint::new().local_anchor2(Vector::new(-shift, 0.0, 0.0));
|
||||
// let joint =
|
||||
// RevoluteJoint::new(Vector::x_axis()).local_anchor2(point![-shift, 0.0, 0.0]);
|
||||
// RevoluteJoint::new(Vector::X).local_anchor2(Vector::new(-shift, 0.0, 0.0));
|
||||
impulse_joints.insert(parent_handle, child_handle, joint, true);
|
||||
}
|
||||
|
||||
@@ -70,14 +71,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let mut multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
let collider = ColliderBuilder::cuboid(30.0, 0.01, 30.0)
|
||||
.translation(vector![0.0, -3.02, 0.0])
|
||||
.rotation(vector![0.1, 0.0, 0.1]);
|
||||
.translation(Vector::new(0.0, -3.02, 0.0))
|
||||
.rotation(Vector::new(0.1, 0.0, 0.1));
|
||||
colliders.insert(collider);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::dynamic();
|
||||
let collider = ColliderBuilder::cuboid(30.0, 0.01, 30.0)
|
||||
.translation(vector![0.0, -3.0, 0.0])
|
||||
.rotation(vector![0.1, 0.0, 0.1]);
|
||||
.translation(Vector::new(0.0, -3.0, 0.0))
|
||||
.rotation(Vector::new(0.1, 0.0, 0.1));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
@@ -93,5 +94,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![15.0, 5.0, 42.0], point![13.0, 1.0, 1.0]);
|
||||
testbed.look_at(Vec3::new(15.0, 5.0, 42.0), Vec3::new(13.0, 1.0, 1.0));
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(vector![x, y, z])
|
||||
.translation(Vector::new(x, y, z))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).friction(0.0);
|
||||
@@ -55,5 +55,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
let rigid_body = RigidBodyBuilder::fixed();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let halfspace = SharedShape::new(HalfSpace::new(Vector::y_axis()));
|
||||
let halfspace = SharedShape::new(HalfSpace::new(Vector::Y));
|
||||
let collider = ColliderBuilder::new(halfspace);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
@@ -26,7 +26,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let curr_height = 0.1f32.min(curr_width);
|
||||
curr_y += curr_height * 4.0;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, curr_y, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, curr_y, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(curr_width, curr_height, curr_width);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -38,5 +38,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 0.1;
|
||||
|
||||
for _ in 0..6 {
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -26,8 +27,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// Build the dynamic box rigid body.
|
||||
for _ in 0..2 {
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![1.1, 0.0, 0.0])
|
||||
// .rotation(vector![0.8, 0.2, 0.1])
|
||||
.translation(Vector::new(1.1, 0.0, 0.0))
|
||||
// .rotation(Vector::new(0.8, 0.2, 0.1))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(2.0, 0.1, 1.0);
|
||||
@@ -38,5 +39,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(vector![0.0, 0.0, z])
|
||||
.translation(Vector::new(0.0, 0.0, z))
|
||||
.additional_solver_iterations(16);
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(ball_rad);
|
||||
@@ -48,11 +48,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint = if i == 1 {
|
||||
SphericalJointBuilder::new().local_anchor2(point![0.0, 0.0, -shift1 * 2.0])
|
||||
SphericalJointBuilder::new().local_anchor2(Vector::new(0.0, 0.0, -shift1 * 2.0))
|
||||
} else {
|
||||
SphericalJointBuilder::new()
|
||||
.local_anchor1(point![0.0, 0.0, shift1])
|
||||
.local_anchor2(point![0.0, 0.0, -shift2])
|
||||
.local_anchor1(Vector::new(0.0, 0.0, shift1))
|
||||
.local_anchor2(Vector::new(0.0, 0.0, -shift2))
|
||||
};
|
||||
|
||||
if use_articulations {
|
||||
@@ -69,5 +69,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Floor.
|
||||
*/
|
||||
let floor_body =
|
||||
RigidBodyBuilder::fixed().translation(vector![0.0, -stick_len - stick_rad, 0.0]);
|
||||
RigidBodyBuilder::fixed().translation(Vector::new(0.0, -stick_len - stick_rad, 0.0));
|
||||
let floor_handle = bodies.insert(floor_body);
|
||||
let floor_cube = ColliderBuilder::cuboid(stick_len, stick_len, stick_len);
|
||||
colliders.insert_with_parent(floor_cube, floor_handle, &mut bodies);
|
||||
@@ -29,38 +29,38 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
for i in 0..num_levels {
|
||||
let fi = i as f32;
|
||||
|
||||
let body = RigidBodyBuilder::dynamic().translation(vector![
|
||||
let body = RigidBodyBuilder::dynamic().translation(Vector::new(
|
||||
0.0,
|
||||
fi * stick_rad * 4.0,
|
||||
-(stick_len / 2.0 - stick_rad)
|
||||
]);
|
||||
-(stick_len / 2.0 - stick_rad),
|
||||
));
|
||||
let handle = bodies.insert(body);
|
||||
let capsule = ColliderBuilder::cuboid(stick_len / 2.0, stick_rad, stick_rad);
|
||||
colliders.insert_with_parent(capsule, handle, &mut bodies);
|
||||
|
||||
let body = RigidBodyBuilder::dynamic().translation(vector![
|
||||
let body = RigidBodyBuilder::dynamic().translation(Vector::new(
|
||||
0.0,
|
||||
fi * stick_rad * 4.0,
|
||||
(stick_len / 2.0 - stick_rad)
|
||||
]);
|
||||
stick_len / 2.0 - stick_rad,
|
||||
));
|
||||
let handle = bodies.insert(body);
|
||||
let capsule = ColliderBuilder::cuboid(stick_len / 2.0, stick_rad, stick_rad);
|
||||
colliders.insert_with_parent(capsule, handle, &mut bodies);
|
||||
|
||||
let body = RigidBodyBuilder::dynamic().translation(vector![
|
||||
let body = RigidBodyBuilder::dynamic().translation(Vector::new(
|
||||
-(stick_len / 2.0 - stick_rad),
|
||||
(fi + 0.5) * stick_rad * 4.0,
|
||||
0.0
|
||||
]);
|
||||
0.0,
|
||||
));
|
||||
let handle = bodies.insert(body);
|
||||
let capsule = ColliderBuilder::cuboid(stick_rad, stick_rad, stick_len / 2.0);
|
||||
colliders.insert_with_parent(capsule, handle, &mut bodies);
|
||||
|
||||
let body = RigidBodyBuilder::dynamic().translation(vector![
|
||||
(stick_len / 2.0 - stick_rad),
|
||||
let body = RigidBodyBuilder::dynamic().translation(Vector::new(
|
||||
stick_len / 2.0 - stick_rad,
|
||||
(fi + 0.5) * stick_rad * 4.0,
|
||||
0.0
|
||||
]);
|
||||
0.0,
|
||||
));
|
||||
let handle = bodies.insert(body);
|
||||
let capsule = ColliderBuilder::cuboid(stick_rad, stick_rad, stick_len / 2.0);
|
||||
colliders.insert_with_parent(capsule, handle, &mut bodies);
|
||||
@@ -71,21 +71,23 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
let cube_len = stick_len * 2.0;
|
||||
let floor_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![
|
||||
.translation(Vector::new(
|
||||
0.0,
|
||||
cube_len / 2.0 + (num_levels as f32 - 0.25) * stick_rad * 4.0,
|
||||
0.0
|
||||
])
|
||||
0.0,
|
||||
))
|
||||
.additional_solver_iterations(36);
|
||||
let floor_handle = bodies.insert(floor_body);
|
||||
let floor_cube = ColliderBuilder::cuboid(cube_len / 2.0, cube_len / 2.0, cube_len / 2.0);
|
||||
colliders.insert_with_parent(floor_cube, floor_handle, &mut bodies);
|
||||
|
||||
let small_mass =
|
||||
MassProperties::from_cuboid(1.0, vector![stick_rad, stick_rad, stick_len / 2.0]).mass();
|
||||
let big_mass =
|
||||
MassProperties::from_cuboid(1.0, vector![cube_len / 2.0, cube_len / 2.0, cube_len / 2.0])
|
||||
.mass();
|
||||
MassProperties::from_cuboid(1.0, Vector::new(stick_rad, stick_rad, stick_len / 2.0)).mass();
|
||||
let big_mass = MassProperties::from_cuboid(
|
||||
1.0,
|
||||
Vector::new(cube_len / 2.0, cube_len / 2.0, cube_len / 2.0),
|
||||
)
|
||||
.mass();
|
||||
println!(
|
||||
"debug_cube_high_mass_ratio3: small stick mass: {small_mass}, big cube mass: {big_mass}, mass_ratio: {}",
|
||||
big_mass / small_mass
|
||||
@@ -95,5 +97,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 100.1;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -44,7 +44,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = -centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cylinder(rad, rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -53,5 +53,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use rapier3d::prelude::*;
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct PhysicsState {
|
||||
pub gravity: Vector<f32>,
|
||||
pub gravity: Vector,
|
||||
pub integration_parameters: IntegrationParameters,
|
||||
pub islands: IslandManager,
|
||||
pub broad_phase: DefaultBroadPhase,
|
||||
@@ -41,7 +41,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
println!("\timpulse_joints: {:?}", state.impulse_joints.len());
|
||||
|
||||
for (_, rb) in state.bodies.iter() {
|
||||
if rb.linvel().norm() != 0.0 {
|
||||
if rb.linvel().length() != 0.0 {
|
||||
println!("\tlinvel: {:?}", rb.linvel());
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
testbed.harness_mut().physics.integration_parameters = state.integration_parameters;
|
||||
testbed.harness_mut().physics.gravity = state.gravity;
|
||||
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], point![0.0, 0.0, 0.0]);
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::new(0.0, 0.0, 0.0));
|
||||
}
|
||||
Err(err) => println!("Failed to deserialize the world state: {err}"),
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 10.1;
|
||||
let ground_height = 2.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -23,7 +23,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Platform that will be enabled/disabled.
|
||||
*/
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, 5.0, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 5.0, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(5.0, 1.0, 5.0);
|
||||
let handle_to_disable = colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -38,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
}
|
||||
|
||||
if run_state.timestep_id % 25 == 0 {
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, 20.0, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 20.0, 0.0));
|
||||
let handle = physics.bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
physics
|
||||
@@ -55,5 +55,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![-30.0, 4.0, -30.0], point![0.0, 1.0, 0.0]);
|
||||
testbed.look_at(Vec3::new(30.0, 4.0, 30.0), Vec3::new(0.0, 1.0, 0.0));
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 20.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4)
|
||||
.friction(0.15)
|
||||
@@ -29,15 +29,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
let ball_rad = 0.1;
|
||||
let rb = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![0.0, 0.2, 0.0])
|
||||
.linvel(vector![10.0, 0.0, 0.0]);
|
||||
.translation(Vector::new(0.0, 0.2, 0.0))
|
||||
.linvel(Vector::new(10.0, 0.0, 0.0));
|
||||
let ball_handle = bodies.insert(rb);
|
||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0);
|
||||
colliders.insert_with_parent(collider, ball_handle, &mut bodies);
|
||||
|
||||
let mut linvel = Vector::zeros();
|
||||
let mut angvel = Vector::zeros();
|
||||
let mut pos = Isometry::identity();
|
||||
let mut linvel = Vector::ZERO;
|
||||
let mut angvel = AngVector::ZERO;
|
||||
let mut pos = Pose::IDENTITY;
|
||||
let mut step = 0;
|
||||
let mut extra_colliders = Vec::new();
|
||||
let snapped_frame = 51;
|
||||
@@ -62,8 +62,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ball = physics.bodies.get_mut(ball_handle).unwrap();
|
||||
|
||||
if step == snapped_frame {
|
||||
linvel = *ball.linvel();
|
||||
angvel = *ball.angvel();
|
||||
linvel = ball.linvel();
|
||||
angvel = ball.angvel();
|
||||
pos = *ball.position();
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
for handle in &extra_colliders {
|
||||
if let Some(graphics) = &mut graphics {
|
||||
graphics.remove_collider(*handle, &physics.colliders);
|
||||
graphics.remove_collider(*handle);
|
||||
}
|
||||
|
||||
physics
|
||||
@@ -88,7 +88,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Remove then re-add the ground collider.
|
||||
// let ground = physics.bodies.get_mut(ground_handle).unwrap();
|
||||
// ground.set_position(Isometry::translation(0.0, step as f32 * 0.001, 0.0), false);
|
||||
// ground.set_position(Pose::from_translation(Vector::new(0.0, step as f32 * 0.001, 0.0)), false);
|
||||
// let coll = physics
|
||||
// .colliders
|
||||
// .remove(ground_collider_handle, &mut physics.bodies, true)
|
||||
@@ -111,5 +111,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -16,20 +16,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 100.1;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
// Build the dynamic box rigid body.
|
||||
let (mut vtx, idx) = Cuboid::new(vector![1.0, 1.0, 1.0]).to_trimesh();
|
||||
let (mut vtx, idx) = Cuboid::new(Vector::new(1.0, 1.0, 1.0)).to_trimesh();
|
||||
vtx.iter_mut()
|
||||
.for_each(|pt| *pt += vector![100.0, 100.0, 100.0]);
|
||||
.for_each(|pt| *pt += Vector::new(100.0, 100.0, 100.0));
|
||||
let shape = SharedShape::convex_mesh(vtx, &idx).unwrap();
|
||||
|
||||
for _ in 0..2 {
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![-100.0, -100.0 + 10.0, -100.0])
|
||||
.translation(Vector::new(-100.0, -100.0 + 10.0, -100.0))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::new(shape.clone());
|
||||
@@ -40,5 +40,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -23,19 +23,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Build a dynamic box rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![0.0, 1.1, 0.0])
|
||||
.rotation(Vector::y() * 0.3);
|
||||
.translation(Vector::new(0.0, 1.1, 0.0))
|
||||
.rotation(Vector::Y * 0.3);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(2.0, 1.0, 3.0).friction(1.5);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = &mut bodies[handle];
|
||||
let force = rigid_body.position() * Vector::z() * 50.0;
|
||||
let force = rigid_body.rotation() * Vector::Z * 50.0;
|
||||
rigid_body.set_linvel(force, true);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 100.1;
|
||||
let ground_height = 2.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, 4.0, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, 4.0, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -24,14 +24,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rad = 1.0;
|
||||
// Build the dynamic box rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![0.0, 7.0 * rad, 0.0])
|
||||
.translation(Vector::new(0.0, 7.0 * rad, 0.0))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![0.0, 2.0 * rad, 0.0])
|
||||
.translation(Vector::new(0.0, 2.0 * rad, 0.0))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad);
|
||||
@@ -40,6 +40,6 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.look_at(point![100.0, -10.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, -10.0, 100.0), Vec3::ZERO);
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
}
|
||||
|
||||
@@ -10,10 +10,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
let heights = DMatrix::zeros(100, 100);
|
||||
let heightfield =
|
||||
HeightField::with_flags(heights, vector![60.0, 1.0, 60.0], HeightFieldFlags::all());
|
||||
let rotation = vector![0.0, 0.0, 0.0]; // vector![-0.1, 0.0, 0.0];
|
||||
let heights = Array2::zeros(100, 100);
|
||||
let heightfield = HeightField::with_flags(
|
||||
heights,
|
||||
Vector::new(60.0, 1.0, 60.0),
|
||||
HeightFieldFlags::all(),
|
||||
);
|
||||
let rotation = Vector::new(0.0, 0.0, 0.0); // Vector::new(-0.1, 0.0, 0.0);
|
||||
colliders
|
||||
.insert(ColliderBuilder::new(SharedShape::new(heightfield.clone())).rotation(rotation));
|
||||
|
||||
@@ -29,33 +32,36 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Dynamic rigid bodies.
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![4.0, 0.5, 0.0])
|
||||
.linvel(vector![0.0, -40.0, 20.0])
|
||||
.translation(Vector::new(4.0, 0.5, 0.0))
|
||||
.linvel(Vector::new(0.0, -40.0, 20.0))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(0.5);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![-3.0, 5.0, 0.0])
|
||||
.linvel(vector![0.0, -4.0, 20.0])
|
||||
.translation(Vector::new(-3.0, 5.0, 0.0))
|
||||
.linvel(Vector::new(0.0, -4.0, 20.0))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(0.5, 0.5, 0.5);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![8.0, 0.2, 0.0])
|
||||
.linvel(vector![0.0, -4.0, 20.0])
|
||||
.translation(Vector::new(8.0, 0.2, 0.0))
|
||||
.linvel(Vector::new(0.0, -4.0, 20.0))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider =
|
||||
ColliderBuilder::cylinder(0.5, 0.2).rotation(vector![0.0, 0.0, std::f32::consts::PI / 2.0]);
|
||||
let collider = ColliderBuilder::cylinder(0.5, 0.2).rotation(Vector::new(
|
||||
0.0,
|
||||
0.0,
|
||||
std::f32::consts::PI / 2.0,
|
||||
));
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
RigidBodyType::Dynamic
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(vector![0.0, 0.0, fi * shift]);
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::new(status).translation(Vector::new(0.0, 0.0, fi * shift));
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad);
|
||||
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||
@@ -38,11 +39,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint = if i == 1 {
|
||||
SphericalJointBuilder::new().local_anchor2(point![0.0, 0.0, -shift])
|
||||
SphericalJointBuilder::new().local_anchor2(Vector::new(0.0, 0.0, -shift))
|
||||
} else {
|
||||
SphericalJointBuilder::new()
|
||||
.local_anchor1(point![0.0, 0.0, shift / 2.0])
|
||||
.local_anchor2(point![0.0, 0.0, -shift / 2.0])
|
||||
.local_anchor1(Vector::new(0.0, 0.0, shift / 2.0))
|
||||
.local_anchor2(Vector::new(0.0, 0.0, -shift / 2.0))
|
||||
};
|
||||
|
||||
if use_articulations {
|
||||
@@ -59,5 +60,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -7,19 +7,20 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let mut multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
let ground = RigidBodyBuilder::fixed().translation(vector![0.0, 0.0, 0.0]);
|
||||
let ground = RigidBodyBuilder::fixed().translation(Vector::new(0.0, 0.0, 0.0));
|
||||
let body = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(1.0, 1.0, 1.0);
|
||||
colliders.insert_with_parent(collider, body, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::dynamic().pose(Isometry::translation(0.0, 1.0, 0.0));
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::dynamic().pose(Pose::from_translation(Vector::new(0.0, 1.0, 0.0)));
|
||||
let body_part = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(1.0, 1.0, 1.0).density(1.0);
|
||||
colliders.insert_with_parent(collider, body_part, &mut bodies);
|
||||
|
||||
let joint = SphericalJointBuilder::new()
|
||||
.local_anchor1(point![0.0, 4.0, 0.0])
|
||||
.local_anchor2(point![0.0, 0.0, 0.0])
|
||||
.local_anchor1(Vector::new(0.0, 4.0, 0.0))
|
||||
.local_anchor2(Vector::new(0.0, 0.0, 0.0))
|
||||
.motor_position(JointAxis::AngX, 1.0, 1000.0, 200.0)
|
||||
.motor_position(JointAxis::AngY, 0.0, 1000.0, 200.0)
|
||||
.motor_position(JointAxis::AngZ, 0.0, 1000.0, 200.0);
|
||||
@@ -27,5 +28,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
multibody_joints.insert(body, body_part, joint, true);
|
||||
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![20.0, 0.0, 0.0], point![0.0, 0.0, 0.0]);
|
||||
testbed.look_at(Vec3::new(20.0, 0.0, 0.0), Vec3::new(0.0, 0.0, 0.0));
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_height = 10.0;
|
||||
|
||||
for _ in 0..1 {
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -26,8 +27,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// Build the dynamic box rigid body.
|
||||
for _ in 0..1 {
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
// .translation(vector![0.0, 0.1, 0.0])
|
||||
// .rotation(vector![0.8, 0.2, 0.1])
|
||||
// .translation(Vector::new(0.0, 0.1, 0.0))
|
||||
// .rotation(Vector::new(0.8, 0.2, 0.1))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(1.0, 1.0, 1.0);
|
||||
@@ -38,5 +39,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -5,46 +5,38 @@ fn prismatic_repro(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
impulse_joints: &mut ImpulseJointSet,
|
||||
box_center: Point<f32>,
|
||||
box_center: Vector,
|
||||
) {
|
||||
let box_rb = bodies.insert(RigidBodyBuilder::dynamic().translation(vector![
|
||||
box_center.x,
|
||||
box_center.y,
|
||||
box_center.z
|
||||
]));
|
||||
let box_rb = bodies.insert(RigidBodyBuilder::dynamic().translation(box_center));
|
||||
colliders.insert_with_parent(ColliderBuilder::cuboid(1.0, 0.25, 1.0), box_rb, bodies);
|
||||
|
||||
let wheel_y = -1.0;
|
||||
let wheel_positions = vec![
|
||||
vector![1.0, wheel_y, -1.0],
|
||||
vector![-1.0, wheel_y, -1.0],
|
||||
vector![1.0, wheel_y, 1.0],
|
||||
vector![-1.0, wheel_y, 1.0],
|
||||
Vector::new(1.0, wheel_y, -1.0),
|
||||
Vector::new(-1.0, wheel_y, -1.0),
|
||||
Vector::new(1.0, wheel_y, 1.0),
|
||||
Vector::new(-1.0, wheel_y, 1.0),
|
||||
];
|
||||
|
||||
for pos in wheel_positions {
|
||||
let wheel_pos_in_world = box_center + pos;
|
||||
let wheel_rb = bodies.insert(RigidBodyBuilder::dynamic().translation(vector![
|
||||
wheel_pos_in_world.x,
|
||||
wheel_pos_in_world.y,
|
||||
wheel_pos_in_world.z
|
||||
]));
|
||||
let wheel_rb = bodies.insert(RigidBodyBuilder::dynamic().translation(wheel_pos_in_world));
|
||||
colliders.insert_with_parent(ColliderBuilder::ball(0.5), wheel_rb, bodies);
|
||||
|
||||
let (stiffness, damping) = (0.05, 0.2);
|
||||
|
||||
let prismatic = PrismaticJointBuilder::new(Vector::y_axis())
|
||||
.local_anchor1(point![pos.x, pos.y, pos.z])
|
||||
let prismatic = PrismaticJointBuilder::new(Vector::Y)
|
||||
.local_anchor1(pos)
|
||||
.motor_position(0.0, stiffness, damping);
|
||||
impulse_joints.insert(box_rb, wheel_rb, prismatic, true);
|
||||
}
|
||||
|
||||
// put a small box under one of the wheels
|
||||
let gravel = bodies.insert(RigidBodyBuilder::dynamic().translation(vector![
|
||||
let gravel = bodies.insert(RigidBodyBuilder::dynamic().translation(Vector::new(
|
||||
box_center.x + 1.0,
|
||||
box_center.y - 2.4,
|
||||
-1.0
|
||||
]));
|
||||
-1.0,
|
||||
)));
|
||||
colliders.insert_with_parent(ColliderBuilder::cuboid(0.5, 0.1, 0.5), gravel, bodies);
|
||||
}
|
||||
|
||||
@@ -63,7 +55,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 50.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -72,12 +64,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
&mut impulse_joints,
|
||||
point![0.0, 5.0, 0.0],
|
||||
Vector::new(0.0, 5.0, 0.0),
|
||||
);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 20.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 0.4)
|
||||
.friction(0.15)
|
||||
@@ -29,15 +29,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
let ball_rad = 0.1;
|
||||
let rb = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![0.0, 0.2, 0.0])
|
||||
.linvel(vector![10.0, 0.0, 0.0]);
|
||||
.translation(Vector::new(0.0, 0.2, 0.0))
|
||||
.linvel(Vector::new(10.0, 0.0, 0.0));
|
||||
let ball_handle = bodies.insert(rb);
|
||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0);
|
||||
colliders.insert_with_parent(collider, ball_handle, &mut bodies);
|
||||
|
||||
let mut linvel = Vector::zeros();
|
||||
let mut angvel = Vector::zeros();
|
||||
let mut pos = Isometry::identity();
|
||||
let mut linvel = Vector::ZERO;
|
||||
let mut angvel = AngVector::ZERO;
|
||||
let mut pos = Pose::IDENTITY;
|
||||
let mut step = 0;
|
||||
let snapped_frame = 51;
|
||||
|
||||
@@ -48,8 +48,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ball = physics.bodies.get_mut(ball_handle).unwrap();
|
||||
|
||||
if step == snapped_frame {
|
||||
linvel = *ball.linvel();
|
||||
angvel = *ball.angvel();
|
||||
linvel = ball.linvel();
|
||||
angvel = ball.angvel();
|
||||
pos = *ball.position();
|
||||
}
|
||||
|
||||
@@ -65,5 +65,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 20.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size)
|
||||
.friction(0.15)
|
||||
@@ -29,8 +29,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
let ball_rad = 0.1;
|
||||
let rb = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![0.0, 0.2, 0.0])
|
||||
.linvel(vector![10.0, 0.0, 0.0]);
|
||||
.translation(Vector::new(0.0, 0.2, 0.0))
|
||||
.linvel(Vector::new(10.0, 0.0, 0.0));
|
||||
let ball_handle = bodies.insert(rb);
|
||||
let collider = ColliderBuilder::ball(ball_rad).density(100.0);
|
||||
let ball_coll_handle = colliders.insert_with_parent(collider, ball_handle, &mut bodies);
|
||||
@@ -40,7 +40,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
let shape_size = 3.0;
|
||||
let static_collider =
|
||||
ColliderBuilder::ball(shape_size).translation(vector![-15.0, shape_size, 18.0]);
|
||||
ColliderBuilder::ball(shape_size).translation(Vector::new(-15.0, shape_size, 18.0));
|
||||
colliders.insert(static_collider);
|
||||
|
||||
let shapes = [
|
||||
@@ -51,12 +51,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
];
|
||||
let mut shape_idx = 0;
|
||||
let shapeshifting_collider = ColliderBuilder::new(shapes[shape_idx].clone())
|
||||
.translation(vector![-15.0, shape_size, 9.0]);
|
||||
.translation(Vector::new(-15.0, shape_size, 9.0));
|
||||
let shapeshifting_coll_handle = colliders.insert(shapeshifting_collider);
|
||||
|
||||
let mut linvel = Vector::zeros();
|
||||
let mut angvel = Vector::zeros();
|
||||
let mut pos = Isometry::identity();
|
||||
let mut linvel = Vector::ZERO;
|
||||
let mut angvel = AngVector::ZERO;
|
||||
let mut pos = Pose::IDENTITY;
|
||||
let mut step = 0;
|
||||
let snapped_frame = 51;
|
||||
|
||||
@@ -67,8 +67,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ball = physics.bodies.get_mut(ball_handle).unwrap();
|
||||
|
||||
if step == snapped_frame {
|
||||
linvel = *ball.linvel();
|
||||
angvel = *ball.angvel();
|
||||
linvel = ball.linvel();
|
||||
angvel = ball.angvel();
|
||||
pos = *ball.position();
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shiftz - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = match j % 5 {
|
||||
@@ -144,5 +144,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![40.0, 40.0, 40.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(40.0, 40.0, 40.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Setup a velocity-based kinematic rigid body.
|
||||
*/
|
||||
let platform_body =
|
||||
RigidBodyBuilder::kinematic_velocity_based().translation(vector![0.0, 1.5 + 0.8, 0.0]);
|
||||
RigidBodyBuilder::kinematic_velocity_based().translation(Vector::new(0.0, 1.5 + 0.8, 0.0));
|
||||
let platform_handle = bodies.insert(platform_body);
|
||||
let collider = ColliderBuilder::cuboid(5.0, 0.5, 5.0);
|
||||
colliders.insert_with_parent(collider, platform_handle, &mut bodies);
|
||||
|
||||
// A second velocity-based platform but this one will move super slow.
|
||||
let slow_platform_body =
|
||||
RigidBodyBuilder::kinematic_velocity_based().translation(vector![0.0, 0.0, 0.0]);
|
||||
RigidBodyBuilder::kinematic_velocity_based().translation(Vector::new(0.0, 0.0, 0.0));
|
||||
let slow_platform_handle = bodies.insert(slow_platform_body);
|
||||
let collider = ColliderBuilder::cuboid(5.0, 0.5, 5.0);
|
||||
colliders.insert_with_parent(collider, slow_platform_handle, &mut bodies);
|
||||
@@ -40,10 +40,10 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
assert!(!physics.bodies[slow_platform_handle].is_sleeping());
|
||||
|
||||
if let Some(slow_platform) = physics.bodies.get_mut(slow_platform_handle) {
|
||||
slow_platform.set_linvel(Vector::zeros(), true);
|
||||
slow_platform.set_linvel(Vector::ZERO, true);
|
||||
}
|
||||
if let Some(platform) = physics.bodies.get_mut(platform_handle) {
|
||||
platform.set_linvel(Vector::zeros(), true);
|
||||
platform.set_linvel(Vector::ZERO, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,17 +62,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
assert!(physics.bodies[platform_handle].is_sleeping());
|
||||
assert!(physics.bodies[slow_platform_handle].is_sleeping());
|
||||
|
||||
let slow_velocity = vector![0.0, 0.01, 0.0];
|
||||
let slow_velocity = Vector::new(0.0, 0.01, 0.0);
|
||||
if let Some(slow_platform) = physics.bodies.get_mut(slow_platform_handle) {
|
||||
slow_platform.set_linvel(slow_velocity, true);
|
||||
}
|
||||
}
|
||||
|
||||
let velocity = vector![
|
||||
let velocity = Vector::new(
|
||||
0.0,
|
||||
(run_state.time * 2.0).cos(),
|
||||
run_state.time.sin() * 2.0
|
||||
];
|
||||
run_state.time.sin() * 2.0,
|
||||
);
|
||||
|
||||
// Update the velocity-based kinematic body by setting its velocity.
|
||||
if let Some(platform) = physics.bodies.get_mut(platform_handle) {
|
||||
@@ -84,5 +84,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Run the simulation.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![-10.0, 5.0, -10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 5.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -17,17 +17,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Ground
|
||||
*/
|
||||
// let vertices = vec![
|
||||
// point![-50.0, 0.0, -50.0],
|
||||
// point![-50.0, 0.0, 50.0],
|
||||
// point![50.0, 0.0, 50.0],
|
||||
// point![50.0, 0.0, -50.0],
|
||||
// Vec3::new(-50.0, 0.0, -50.0),
|
||||
// Vec3::new(-50.0, 0.0, 50.0),
|
||||
// Vec3::new(50.0, 0.0, 50.0),
|
||||
// Vec3::new(50.0, 0.0, -50.0),
|
||||
// ];
|
||||
// let indices = vec![[0, 1, 2], [0, 2, 3]];
|
||||
//
|
||||
// let collider = ColliderBuilder::trimesh_with_flags(vertices, indices, TriMeshFlags::all());
|
||||
// colliders.insert(collider);
|
||||
|
||||
let heights = DMatrix::repeat(2, 2, 0.0);
|
||||
let heights = Array2::repeat(2, 2, 0.0);
|
||||
let collider = ColliderBuilder::heightfield_with_flags(
|
||||
heights,
|
||||
Vector::new(50.0, 1.0, 50.0),
|
||||
@@ -40,9 +40,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![0.0, 5.0, 0.0])
|
||||
.rotation(vector![0.5, 0.0, 0.5])
|
||||
.linvel(vector![0.0, -100.0, 0.0])
|
||||
.translation(Vector::new(0.0, 5.0, 0.0))
|
||||
.rotation(Vector::new(0.5, 0.0, 0.5))
|
||||
.linvel(Vector::new(0.0, -100.0, 0.0))
|
||||
.soft_ccd_prediction(10.0);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(5.0, 0.015, 5.0);
|
||||
@@ -52,5 +52,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -12,19 +12,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Triangle ground.
|
||||
let vtx = [
|
||||
point![-10.0, 0.0, -10.0],
|
||||
point![10.0, 0.0, -10.0],
|
||||
point![0.0, 0.0, 10.0],
|
||||
Vector::new(-10.0, 0.0, -10.0),
|
||||
Vector::new(10.0, 0.0, -10.0),
|
||||
Vector::new(0.0, 0.0, 10.0),
|
||||
];
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, 0.0, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, 0.0, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::triangle(vtx[0], vtx[1], vtx[2]);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
// Dynamic box rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![1.1, 0.01, 0.0])
|
||||
.translation(Vector::new(1.1, 0.01, 0.0))
|
||||
// .rotation(Vector3::new(0.8, 0.2, 0.1))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
@@ -35,5 +35,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use kiss3d::color::LIGHT_GRAY;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
@@ -13,14 +14,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// Triangle ground.
|
||||
let width = 0.5;
|
||||
let vtx = vec![
|
||||
point![-width, 0.0, -width],
|
||||
point![width, 0.0, -width],
|
||||
point![width, 0.0, width],
|
||||
point![-width, 0.0, width],
|
||||
point![-width, -width, -width],
|
||||
point![width, -width, -width],
|
||||
point![width, -width, width],
|
||||
point![-width, -width, width],
|
||||
Vector::new(-width, 0.0, -width),
|
||||
Vector::new(width, 0.0, -width),
|
||||
Vector::new(width, 0.0, width),
|
||||
Vector::new(-width, 0.0, width),
|
||||
Vector::new(-width, -width, -width),
|
||||
Vector::new(width, -width, -width),
|
||||
Vector::new(width, -width, width),
|
||||
Vector::new(-width, -width, width),
|
||||
];
|
||||
let idx = vec![
|
||||
[0, 2, 1],
|
||||
@@ -39,22 +40,22 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Dynamic box rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![0.0, 35.0, 0.0])
|
||||
.translation(Vector::new(0.0, 35.0, 0.0))
|
||||
// .rotation(Vector3::new(0.8, 0.2, 0.1))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.0);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, 0.0, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, 0.0, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::trimesh(vtx, idx).expect("Could not create trimesh collider.");
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
testbed.set_initial_body_color(handle, [0.3, 0.3, 0.3]);
|
||||
testbed.set_initial_body_color(handle, LIGHT_GRAY);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
// Dynamic box rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, 2.0, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 2.0, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(0.5, 0.5, 0.5);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -25,5 +25,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use kiss3d::color::Color;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
@@ -16,7 +17,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 200.1;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -28,7 +29,10 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let width = 1.0;
|
||||
let thickness = 0.1;
|
||||
|
||||
let colors = [[0.7, 0.5, 0.9], [0.6, 1.0, 0.6]];
|
||||
let colors = [
|
||||
Color::new(0.7, 0.5, 0.9, 1.0),
|
||||
Color::new(0.6, 1.0, 0.6, 1.0),
|
||||
];
|
||||
|
||||
let mut curr_angle = 0.0;
|
||||
let mut curr_rad = 10.0;
|
||||
@@ -47,12 +51,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let tilt = if nudged || i == num - 1 { 0.2 } else { 0.0 };
|
||||
|
||||
if skip == 0 {
|
||||
let rot = Rotation::new(Vector::y() * curr_angle);
|
||||
let tilt = Rotation::new(rot * Vector::z() * tilt);
|
||||
let position =
|
||||
Translation::new(x * curr_rad, width * 2.0 + ground_height, z * curr_rad)
|
||||
* tilt
|
||||
* rot;
|
||||
let rot = Rotation::from_rotation_y(curr_angle);
|
||||
let tilt_axis = rot * Vector::Z;
|
||||
let tilt_rot = Rotation::from_axis_angle(tilt_axis, tilt);
|
||||
let position = Pose::from_parts(
|
||||
Vector::new(x * curr_rad, width * 2.0 + ground_height, z * curr_rad),
|
||||
tilt_rot * rot,
|
||||
);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().pose(position);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(thickness, width * 2.0, width);
|
||||
@@ -73,5 +78,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -24,18 +24,18 @@ pub fn do_init_world(testbed: &mut Testbed, use_convex_decomposition: bool) {
|
||||
//// OPTION 1: floor made of a single big box.
|
||||
// let ground_size = 50.0;
|
||||
// let ground_height = 0.1;
|
||||
// let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
// let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
// let handle = bodies.insert(rigid_body);
|
||||
// let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
// colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
//// OPTION 2: floor made of a wavy mesh.
|
||||
let nsubdivs = 100;
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
let heights = Array2::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
-(i as f32 * 40.0 / (nsubdivs as f32) / 2.0).cos()
|
||||
- (j as f32 * 40.0 / (nsubdivs as f32) / 2.0).cos()
|
||||
});
|
||||
let heightfield = HeightField::new(heights, vector![100.0, 2.0, 100.0]);
|
||||
let heightfield = HeightField::new(heights, Vector::new(100.0, 2.0, 100.0));
|
||||
let mut trimesh = TriMesh::from(heightfield);
|
||||
let _ = trimesh.set_flags(TriMeshFlags::FIX_INTERNAL_EDGES);
|
||||
colliders.insert(ColliderBuilder::new(SharedShape::new(trimesh.clone())));
|
||||
@@ -51,17 +51,17 @@ pub fn do_init_world(testbed: &mut Testbed, use_convex_decomposition: bool) {
|
||||
let shift_xz = 9.0f32;
|
||||
|
||||
for (igeom, obj_path) in geoms.into_iter().enumerate() {
|
||||
let deltas = Isometry::identity();
|
||||
let deltas = Pose::IDENTITY;
|
||||
|
||||
let mut shapes = Vec::new();
|
||||
println!("Parsing and decomposing: {obj_path}");
|
||||
let input = BufReader::new(File::open(obj_path).unwrap());
|
||||
|
||||
if let Ok(model) = obj::raw::parse_obj(input) {
|
||||
let mut vertices: Vec<_> = model
|
||||
let mut vertices: Vec<Vector> = model
|
||||
.positions
|
||||
.iter()
|
||||
.map(|v| point![v.0, v.1, v.2])
|
||||
.map(|v| Vector::new(v.0, v.1, v.2))
|
||||
.collect();
|
||||
let indices: Vec<_> = model
|
||||
.polygons
|
||||
@@ -78,11 +78,12 @@ pub fn do_init_world(testbed: &mut Testbed, use_convex_decomposition: bool) {
|
||||
let aabb =
|
||||
bounding_volume::details::point_cloud_aabb(&deltas, vertices.iter().copied());
|
||||
let center = aabb.center();
|
||||
let diag = (aabb.maxs - aabb.mins).norm();
|
||||
let center_v = Vector::new(center.x, center.y, center.z);
|
||||
let diag = (aabb.maxs - aabb.mins).length();
|
||||
|
||||
vertices
|
||||
.iter_mut()
|
||||
.for_each(|p| *p = (*p - center.coords) * 10.0 / diag);
|
||||
.for_each(|p| *p = (*p - center_v) * 10.0 / diag);
|
||||
|
||||
let indices: Vec<_> = indices
|
||||
.chunks(3)
|
||||
@@ -106,7 +107,7 @@ pub fn do_init_world(testbed: &mut Testbed, use_convex_decomposition: bool) {
|
||||
let y = (igeom / width) as f32 * shift_y + 7.0;
|
||||
let z = k as f32 * shift_xz - num_duplications as f32 * shift_xz / 2.0;
|
||||
|
||||
let body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(body);
|
||||
|
||||
for shape in &shapes {
|
||||
@@ -121,7 +122,7 @@ pub fn do_init_world(testbed: &mut Testbed, use_convex_decomposition: bool) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
fn models() -> Vec<String> {
|
||||
|
||||
@@ -14,12 +14,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 100.1;
|
||||
let ground_size = 40.0;
|
||||
let ground_height = 2.1; // 16.0;
|
||||
|
||||
for k in 0..3 {
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height - k as f32, 0.0]);
|
||||
RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height - k as f32, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -27,7 +27,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
// Callback that will be executed on the main loop to handle proximities.
|
||||
testbed.add_callback(move |mut graphics, physics, _, run_state| {
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, 10.0, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 10.0, 0.0));
|
||||
let handle = physics.bodies.insert(rigid_body);
|
||||
let collider = match run_state.timestep_id % 3 {
|
||||
0 => ColliderBuilder::round_cylinder(rad, rad, rad / 10.0),
|
||||
@@ -44,11 +44,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
}
|
||||
|
||||
if physics.bodies.len() > MAX_NUMBER_OF_BODIES {
|
||||
let mut to_remove: Vec<_> = physics
|
||||
let mut to_remove: Vec<(RigidBodyHandle, Vector)> = physics
|
||||
.bodies
|
||||
.iter()
|
||||
.filter(|e| e.1.is_dynamic())
|
||||
.map(|e| (e.0, e.1.position().translation.vector))
|
||||
.map(|e| (e.0, e.1.translation()))
|
||||
.collect();
|
||||
|
||||
to_remove.sort_by(|a, b| {
|
||||
@@ -84,5 +84,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// .physics_state_mut()
|
||||
// .integration_parameters
|
||||
// .erp = 0.2;
|
||||
testbed.look_at(point![-30.0, 4.0, -30.0], point![0.0, 1.0, 0.0]);
|
||||
testbed.look_at(Vec3::new(30.0, 4.0, 30.0), Vec3::new(0.0, 1.0, 0.0));
|
||||
}
|
||||
|
||||
@@ -10,21 +10,21 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
let shapes = vec![
|
||||
(Isometry::identity(), SharedShape::cuboid(2.0, 0.2, 0.2)),
|
||||
(Pose::IDENTITY, SharedShape::cuboid(2.0, 0.2, 0.2)),
|
||||
(
|
||||
Isometry::translation(0.0, 0.8, 0.0),
|
||||
Pose::from_translation(Vector::new(0.0, 0.8, 0.0)),
|
||||
SharedShape::cuboid(0.2, 0.4, 0.2),
|
||||
),
|
||||
];
|
||||
|
||||
let body = RigidBodyBuilder::dynamic()
|
||||
.gravity_scale(0.0)
|
||||
.angvel(vector![0.0, 20.0, 0.1])
|
||||
.angvel(Vector::new(0.0, 20.0, 0.1))
|
||||
.gyroscopic_forces_enabled(true);
|
||||
let body_handle = bodies.insert(body);
|
||||
let collider = ColliderBuilder::compound(shapes);
|
||||
colliders.insert_with_parent(collider, body_handle, &mut bodies);
|
||||
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![8.0, 0.0, 8.0], point![0.0, 0.0, 0.0]);
|
||||
testbed.look_at(Vec3::new(8.0, 0.0, 8.0), Vec3::new(0.0, 0.0, 0.0));
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(harness: &mut Harness) {
|
||||
let ground_size = 200.1;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -43,7 +43,7 @@ pub fn init_world(harness: &mut Harness) {
|
||||
let z = k as f32 * shift - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_y(rad, rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
@@ -17,7 +17,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = Vector::new(100.0, 1.0, 100.0);
|
||||
let nsubdivs = 20;
|
||||
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
let heights = Array2::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
if i == 0 || i == nsubdivs || j == 0 || j == nsubdivs {
|
||||
10.0
|
||||
} else {
|
||||
@@ -55,7 +55,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = match j % 6 {
|
||||
@@ -69,15 +69,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
_ => {
|
||||
let shapes = vec![
|
||||
(
|
||||
Isometry::identity(),
|
||||
Pose::IDENTITY,
|
||||
SharedShape::cuboid(rad, rad / 2.0, rad / 2.0),
|
||||
),
|
||||
(
|
||||
Isometry::translation(rad, 0.0, 0.0),
|
||||
Pose::from_translation(Vector::new(rad, 0.0, 0.0)),
|
||||
SharedShape::cuboid(rad / 2.0, rad, rad / 2.0),
|
||||
),
|
||||
(
|
||||
Isometry::translation(-rad, 0.0, 0.0),
|
||||
Pose::from_translation(Vector::new(-rad, 0.0, 0.0)),
|
||||
SharedShape::cuboid(rad / 2.0, rad, rad / 2.0),
|
||||
),
|
||||
];
|
||||
@@ -95,5 +95,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 0.2;
|
||||
let ground_height = 0.01;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
@@ -41,8 +41,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
colliders.insert_with_parent(collider, new_body, &mut bodies);
|
||||
|
||||
let link_ab = SphericalJointBuilder::new()
|
||||
.local_anchor1(point![0.0, size / 2.0 * (i != 0) as usize as f32, 0.0])
|
||||
.local_anchor2(point![0.0, -size / 2.0, 0.0])
|
||||
.local_anchor1(Vector::new(0.0, size / 2.0 * (i != 0) as usize as f32, 0.0))
|
||||
.local_anchor2(Vector::new(0.0, -size / 2.0, 0.0))
|
||||
.build()
|
||||
.data;
|
||||
|
||||
@@ -70,14 +70,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
};
|
||||
|
||||
// Cast a ray on a plane aligned with the camera passing through the origin.
|
||||
let halfspace = HalfSpace {
|
||||
normal: -UnitVector::new_normalize(graphics.camera_fwd_dir()),
|
||||
};
|
||||
let mouse_ray = Ray::new(mouse_ray.0, mouse_ray.1);
|
||||
let Some(hit) = halfspace.cast_local_ray(&mouse_ray, f32::MAX, false) else {
|
||||
let fwd = graphics.camera_fwd_dir();
|
||||
let fwd_glam = Vector::new(-fwd.x, -fwd.y, -fwd.z).normalize();
|
||||
let halfspace = HalfSpace { normal: fwd_glam };
|
||||
let (mouse_orig, mouse_dir) = mouse_ray;
|
||||
let ray = Ray::new(
|
||||
Vector::new(mouse_orig.x, mouse_orig.y, mouse_orig.z),
|
||||
Vector::new(mouse_dir.x, mouse_dir.y, mouse_dir.z),
|
||||
);
|
||||
let Some(hit) = halfspace.cast_local_ray(&ray, f32::MAX, false) else {
|
||||
return;
|
||||
};
|
||||
let target_point = mouse_ray.point_at(hit);
|
||||
let target_point = ray.point_at(hit);
|
||||
|
||||
let options = InverseKinematicsOption {
|
||||
constrained_axes: JointAxesMask::LIN_AXES,
|
||||
@@ -88,7 +92,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
&physics.bodies,
|
||||
link_id,
|
||||
&options,
|
||||
&Isometry::from(target_point),
|
||||
&Pose::from_translation(target_point),
|
||||
|_| true,
|
||||
&mut displacements,
|
||||
);
|
||||
@@ -100,5 +104,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![0.0, 0.5, 2.5], point![0.0, 0.5, 0.0]);
|
||||
testbed.look_at(Vec3::new(0.0, 0.5, 2.5), Vec3::new(0.0, 0.5, 0.0));
|
||||
}
|
||||
|
||||
@@ -23,16 +23,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
for num in 0..9 {
|
||||
let x_pos = -6.0 + 1.5 * num as f32;
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![x_pos, 2.0, 0.0])
|
||||
.translation(Vector::new(x_pos, 2.0, 0.0))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(0.1, 0.5, 0.1);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let target_angle = -std::f32::consts::PI + std::f32::consts::PI / 4.0 * num as f32;
|
||||
let joint = RevoluteJointBuilder::new(Vector::z_axis())
|
||||
.local_anchor1(point![x_pos, 1.5, 0.0])
|
||||
.local_anchor2(point![0.0, -0.5, 0.0])
|
||||
let joint = RevoluteJointBuilder::new(Vector::Z)
|
||||
.local_anchor1(Vector::new(x_pos, 1.5, 0.0))
|
||||
.local_anchor2(Vector::new(0.0, -0.5, 0.0))
|
||||
.motor_position(target_angle, 1000.0, 150.0);
|
||||
impulse_joints.insert(ground_handle, handle, joint, true);
|
||||
target_angles.push(target_angle);
|
||||
@@ -44,17 +44,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
for num in 0..8 {
|
||||
let x_pos = -6.0 + 1.5 * num as f32;
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![x_pos, 4.5, 0.0])
|
||||
.rotation(vector![0.0, 0.0, std::f32::consts::PI])
|
||||
.translation(Vector::new(x_pos, 4.5, 0.0))
|
||||
.rotation(Vector::new(0.0, 0.0, std::f32::consts::PI))
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(0.1, 0.5, 0.1);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
let max_angle_limit = -std::f32::consts::PI + std::f32::consts::PI / 4.0 * num as f32;
|
||||
let joint = RevoluteJointBuilder::new(Vector::z_axis())
|
||||
.local_anchor1(point![x_pos, 5.0, 0.0])
|
||||
.local_anchor2(point![0.0, -0.5, 0.0])
|
||||
let joint = RevoluteJointBuilder::new(Vector::Z)
|
||||
.local_anchor1(Vector::new(x_pos, 5.0, 0.0))
|
||||
.local_anchor2(Vector::new(0.0, -0.5, 0.0))
|
||||
.motor_velocity(1.5, 30.0)
|
||||
.motor_max_force(100.0)
|
||||
.limits([-std::f32::consts::PI, max_angle_limit]);
|
||||
@@ -84,8 +84,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
colliders,
|
||||
impulse_joints,
|
||||
multibody_joints,
|
||||
vector![0.0, 0.0, 0.0],
|
||||
Vector::new(0.0, 0.0, 0.0),
|
||||
(),
|
||||
);
|
||||
testbed.look_at(point![15.0, 5.0, 42.0], point![13.0, 1.0, 1.0]);
|
||||
testbed.look_at(Vec3::new(15.0, 5.0, 42.0), Vec3::new(13.0, 1.0, 1.0));
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@ fn create_coupled_joints(
|
||||
colliders: &mut ColliderSet,
|
||||
impulse_joints: &mut ImpulseJointSet,
|
||||
multibody_joints: &mut MultibodyJointSet,
|
||||
origin: Point<f32>,
|
||||
origin: Vector,
|
||||
use_articulations: bool,
|
||||
) {
|
||||
let ground = bodies.insert(RigidBodyBuilder::fixed().translation(origin.coords));
|
||||
let ground = bodies.insert(RigidBodyBuilder::fixed().translation(origin));
|
||||
let body1 = bodies.insert(
|
||||
RigidBodyBuilder::dynamic()
|
||||
.translation(origin.coords)
|
||||
.linvel(vector![5.0, 5.0, 5.0]),
|
||||
.translation(origin)
|
||||
.linvel(Vector::new(5.0, 5.0, 5.0)),
|
||||
);
|
||||
colliders.insert_with_parent(ColliderBuilder::cuboid(1.0, 1.0, 1.0), body1, bodies);
|
||||
|
||||
@@ -34,34 +34,35 @@ fn create_prismatic_joints(
|
||||
colliders: &mut ColliderSet,
|
||||
impulse_joints: &mut ImpulseJointSet,
|
||||
multibody_joints: &mut MultibodyJointSet,
|
||||
origin: Point<f32>,
|
||||
origin: Vector,
|
||||
num: usize,
|
||||
use_articulations: bool,
|
||||
) {
|
||||
let rad = 0.4;
|
||||
let shift = 2.0;
|
||||
|
||||
let ground = RigidBodyBuilder::fixed().translation(vector![origin.x, origin.y, origin.z]);
|
||||
let ground = RigidBodyBuilder::fixed().translation(origin);
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, curr_parent, bodies);
|
||||
|
||||
for i in 0..num {
|
||||
let z = origin.z + (i + 1) as f32 * shift;
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![origin.x, origin.y, z]);
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::dynamic().translation(Vector::new(origin.x, origin.y, z));
|
||||
let curr_child = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, curr_child, bodies);
|
||||
|
||||
let axis = if i % 2 == 0 {
|
||||
UnitVector::new_normalize(vector![1.0f32, 1.0, 0.0])
|
||||
Vector::new(1.0f32, 1.0, 0.0).normalize()
|
||||
} else {
|
||||
UnitVector::new_normalize(vector![-1.0f32, 1.0, 0.0])
|
||||
Vector::new(-1.0f32, 1.0, 0.0).normalize()
|
||||
};
|
||||
|
||||
let prism = PrismaticJointBuilder::new(axis)
|
||||
.local_anchor1(point![0.0, 0.0, 0.0])
|
||||
.local_anchor2(point![0.0, 0.0, -shift])
|
||||
.local_anchor1(Vector::new(0.0, 0.0, 0.0))
|
||||
.local_anchor2(Vector::new(0.0, 0.0, -shift))
|
||||
.limits([-2.0, 2.0]);
|
||||
|
||||
if use_articulations {
|
||||
@@ -78,34 +79,35 @@ fn create_actuated_prismatic_joints(
|
||||
colliders: &mut ColliderSet,
|
||||
impulse_joints: &mut ImpulseJointSet,
|
||||
multibody_joints: &mut MultibodyJointSet,
|
||||
origin: Point<f32>,
|
||||
origin: Vector,
|
||||
num: usize,
|
||||
use_articulations: bool,
|
||||
) {
|
||||
let rad = 0.4;
|
||||
let shift = 2.0;
|
||||
|
||||
let ground = RigidBodyBuilder::fixed().translation(vector![origin.x, origin.y, origin.z]);
|
||||
let ground = RigidBodyBuilder::fixed().translation(origin);
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, curr_parent, bodies);
|
||||
|
||||
for i in 0..num {
|
||||
let z = origin.z + (i + 1) as f32 * shift;
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![origin.x, origin.y, z]);
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::dynamic().translation(Vector::new(origin.x, origin.y, z));
|
||||
let curr_child = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, curr_child, bodies);
|
||||
|
||||
let axis = if i % 2 == 0 {
|
||||
UnitVector::new_normalize(vector![1.0, 1.0, 0.0])
|
||||
Vector::new(1.0, 1.0, 0.0).normalize()
|
||||
} else {
|
||||
UnitVector::new_normalize(vector![-1.0, 1.0, 0.0])
|
||||
Vector::new(-1.0, 1.0, 0.0).normalize()
|
||||
};
|
||||
|
||||
let mut prism = PrismaticJointBuilder::new(axis)
|
||||
.local_anchor1(point![0.0, 0.0, shift])
|
||||
.local_anchor2(point![0.0, 0.0, 0.0])
|
||||
.local_anchor1(Vector::new(0.0, 0.0, shift))
|
||||
.local_anchor2(Vector::new(0.0, 0.0, 0.0))
|
||||
.build();
|
||||
|
||||
if i == 0 {
|
||||
@@ -143,14 +145,14 @@ fn create_revolute_joints(
|
||||
colliders: &mut ColliderSet,
|
||||
impulse_joints: &mut ImpulseJointSet,
|
||||
multibody_joints: &mut MultibodyJointSet,
|
||||
origin: Point<f32>,
|
||||
origin: Vector,
|
||||
num: usize,
|
||||
use_articulations: bool,
|
||||
) {
|
||||
let rad = 0.4;
|
||||
let shift = 2.0;
|
||||
|
||||
let ground = RigidBodyBuilder::fixed().translation(vector![origin.x, origin.y, 0.0]);
|
||||
let ground = RigidBodyBuilder::fixed().translation(Vector::new(origin.x, origin.y, 0.0));
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, curr_parent, bodies);
|
||||
@@ -159,10 +161,10 @@ fn create_revolute_joints(
|
||||
// Create four bodies.
|
||||
let z = origin.z + i as f32 * shift * 2.0 + shift;
|
||||
let positions = [
|
||||
Isometry::translation(origin.x, origin.y, z),
|
||||
Isometry::translation(origin.x + shift, origin.y, z),
|
||||
Isometry::translation(origin.x + shift, origin.y, z + shift),
|
||||
Isometry::translation(origin.x, origin.y, z + shift),
|
||||
Pose::from_translation(Vector::new(origin.x, origin.y, z)),
|
||||
Pose::from_translation(Vector::new(origin.x + shift, origin.y, z)),
|
||||
Pose::from_translation(Vector::new(origin.x + shift, origin.y, z + shift)),
|
||||
Pose::from_translation(Vector::new(origin.x, origin.y, z + shift)),
|
||||
];
|
||||
|
||||
let mut handles = [curr_parent; 4];
|
||||
@@ -174,13 +176,13 @@ fn create_revolute_joints(
|
||||
}
|
||||
|
||||
// Setup four impulse_joints.
|
||||
let x = Vector::x_axis();
|
||||
let z = Vector::z_axis();
|
||||
let x = Vector::X;
|
||||
let z = Vector::Z;
|
||||
let revs = [
|
||||
RevoluteJointBuilder::new(z).local_anchor2(point![0.0, 0.0, -shift]),
|
||||
RevoluteJointBuilder::new(x).local_anchor2(point![-shift, 0.0, 0.0]),
|
||||
RevoluteJointBuilder::new(z).local_anchor2(point![0.0, 0.0, -shift]),
|
||||
RevoluteJointBuilder::new(x).local_anchor2(point![shift, 0.0, 0.0]),
|
||||
RevoluteJointBuilder::new(z).local_anchor2(Vector::new(0.0, 0.0, -shift)),
|
||||
RevoluteJointBuilder::new(x).local_anchor2(Vector::new(-shift, 0.0, 0.0)),
|
||||
RevoluteJointBuilder::new(z).local_anchor2(Vector::new(0.0, 0.0, -shift)),
|
||||
RevoluteJointBuilder::new(x).local_anchor2(Vector::new(shift, 0.0, 0.0)),
|
||||
];
|
||||
|
||||
if use_articulations {
|
||||
@@ -204,19 +206,20 @@ fn create_revolute_joints_with_limits(
|
||||
colliders: &mut ColliderSet,
|
||||
impulse_joints: &mut ImpulseJointSet,
|
||||
multibody_joints: &mut MultibodyJointSet,
|
||||
origin: Point<f32>,
|
||||
origin: Vector,
|
||||
use_articulations: bool,
|
||||
) {
|
||||
let ground = bodies.insert(RigidBodyBuilder::fixed().translation(origin.coords));
|
||||
let origin_v = origin;
|
||||
let ground = bodies.insert(RigidBodyBuilder::fixed().translation(origin_v));
|
||||
|
||||
let platform1 = bodies.insert(RigidBodyBuilder::dynamic().translation(origin.coords));
|
||||
let platform1 = bodies.insert(RigidBodyBuilder::dynamic().translation(origin_v));
|
||||
colliders.insert_with_parent(ColliderBuilder::cuboid(4.0, 0.2, 2.0), platform1, bodies);
|
||||
|
||||
let shift = vector![0.0, 0.0, 6.0];
|
||||
let platform2 = bodies.insert(RigidBodyBuilder::dynamic().translation(origin.coords + shift));
|
||||
let shift = Vector::new(0.0, 0.0, 6.0);
|
||||
let platform2 = bodies.insert(RigidBodyBuilder::dynamic().translation(origin_v + shift));
|
||||
colliders.insert_with_parent(ColliderBuilder::cuboid(4.0, 0.2, 2.0), platform2, bodies);
|
||||
|
||||
let z = Vector::z_axis();
|
||||
let z = Vector::Z;
|
||||
let joint1 = RevoluteJointBuilder::new(z).limits([-0.2, 0.2]);
|
||||
// let joint1 = GenericJointBuilder::new(JointAxesMask::X | JointAxesMask::Y | JointAxesMask::Z)
|
||||
// .local_axis1(z)
|
||||
@@ -233,7 +236,7 @@ fn create_revolute_joints_with_limits(
|
||||
}
|
||||
|
||||
let joint2 = RevoluteJointBuilder::new(z)
|
||||
.local_anchor2(-Point::from(shift))
|
||||
.local_anchor2(-shift)
|
||||
.limits([-0.2, 0.2]);
|
||||
|
||||
// let joint2 = GenericJointBuilder::new(JointAxesMask::X | JointAxesMask::Y | JointAxesMask::Z)
|
||||
@@ -251,9 +254,9 @@ fn create_revolute_joints_with_limits(
|
||||
impulse_joints.insert(platform1, platform2, joint2, true);
|
||||
}
|
||||
|
||||
// Let’s add a couple of cuboids that will fall on the platforms, triggering the joint limits.
|
||||
// Let's add a couple of cuboids that will fall on the platforms, triggering the joint limits.
|
||||
let cuboid_body1 = bodies
|
||||
.insert(RigidBodyBuilder::dynamic().translation(origin.coords + vector![-2.0, 4.0, 0.0]));
|
||||
.insert(RigidBodyBuilder::dynamic().translation(origin_v + Vector::new(-2.0, 4.0, 0.0)));
|
||||
colliders.insert_with_parent(
|
||||
ColliderBuilder::cuboid(0.6, 0.6, 0.6).friction(1.0),
|
||||
cuboid_body1,
|
||||
@@ -261,7 +264,7 @@ fn create_revolute_joints_with_limits(
|
||||
);
|
||||
|
||||
let cuboid_body2 = bodies.insert(
|
||||
RigidBodyBuilder::dynamic().translation(origin.coords + shift + vector![2.0, 16.0, 0.0]),
|
||||
RigidBodyBuilder::dynamic().translation(origin_v + shift + Vector::new(2.0, 16.0, 0.0)),
|
||||
);
|
||||
colliders.insert_with_parent(
|
||||
ColliderBuilder::cuboid(0.6, 0.6, 0.6).friction(1.0),
|
||||
@@ -275,7 +278,7 @@ fn create_fixed_joints(
|
||||
colliders: &mut ColliderSet,
|
||||
impulse_joints: &mut ImpulseJointSet,
|
||||
multibody_joints: &mut MultibodyJointSet,
|
||||
origin: Point<f32>,
|
||||
origin: Vector,
|
||||
num: usize,
|
||||
use_articulations: bool,
|
||||
) {
|
||||
@@ -298,11 +301,11 @@ fn create_fixed_joints(
|
||||
RigidBodyType::Dynamic
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(vector![
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(Vector::new(
|
||||
origin.x + fk * shift,
|
||||
origin.y,
|
||||
origin.z + fi * shift
|
||||
]);
|
||||
origin.z + fi * shift,
|
||||
));
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad);
|
||||
colliders.insert_with_parent(collider, child_handle, bodies);
|
||||
@@ -311,7 +314,7 @@ fn create_fixed_joints(
|
||||
if i > 0 {
|
||||
let parent_index = body_handles.len() - num;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = FixedJointBuilder::new().local_anchor2(point![0.0, 0.0, -shift]);
|
||||
let joint = FixedJointBuilder::new().local_anchor2(Vector::new(0.0, 0.0, -shift));
|
||||
|
||||
if use_articulations {
|
||||
multibody_joints.insert(parent_handle, child_handle, joint, true);
|
||||
@@ -324,7 +327,7 @@ fn create_fixed_joints(
|
||||
if k > 0 {
|
||||
let parent_index = body_handles.len() - 1;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = FixedJointBuilder::new().local_anchor2(point![-shift, 0.0, 0.0]);
|
||||
let joint = FixedJointBuilder::new().local_anchor2(Vector::new(-shift, 0.0, 0.0));
|
||||
impulse_joints.insert(parent_handle, child_handle, joint, true);
|
||||
}
|
||||
|
||||
@@ -357,11 +360,11 @@ fn create_spherical_joints(
|
||||
RigidBodyType::Dynamic
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(vector![
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(Vector::new(
|
||||
fk * shift,
|
||||
0.0,
|
||||
fi * shift * 2.0
|
||||
]);
|
||||
fi * shift * 2.0,
|
||||
));
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_z(rad * 1.25, rad);
|
||||
colliders.insert_with_parent(collider, child_handle, bodies);
|
||||
@@ -370,7 +373,7 @@ fn create_spherical_joints(
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint =
|
||||
SphericalJointBuilder::new().local_anchor2(point![0.0, 0.0, -shift * 2.0]);
|
||||
SphericalJointBuilder::new().local_anchor2(Vector::new(0.0, 0.0, -shift * 2.0));
|
||||
|
||||
if use_articulations {
|
||||
multibody_joints.insert(parent_handle, child_handle, joint, true);
|
||||
@@ -383,7 +386,8 @@ fn create_spherical_joints(
|
||||
if k > 0 {
|
||||
let parent_index = body_handles.len() - num;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = SphericalJointBuilder::new().local_anchor2(point![-shift, 0.0, 0.0]);
|
||||
let joint =
|
||||
SphericalJointBuilder::new().local_anchor2(Vector::new(-shift, 0.0, 0.0));
|
||||
impulse_joints.insert(parent_handle, child_handle, joint, true);
|
||||
}
|
||||
|
||||
@@ -397,30 +401,31 @@ fn create_spherical_joints_with_limits(
|
||||
colliders: &mut ColliderSet,
|
||||
impulse_joints: &mut ImpulseJointSet,
|
||||
multibody_joints: &mut MultibodyJointSet,
|
||||
origin: Point<f32>,
|
||||
origin: Vector,
|
||||
use_articulations: bool,
|
||||
) {
|
||||
let shift = vector![0.0, 0.0, 3.0];
|
||||
let shift = Vector::new(0.0, 0.0, 3.0);
|
||||
let origin_v = origin;
|
||||
|
||||
let ground = bodies.insert(RigidBodyBuilder::fixed().translation(origin.coords));
|
||||
let ground = bodies.insert(RigidBodyBuilder::fixed().translation(origin_v));
|
||||
|
||||
let ball1 = bodies.insert(
|
||||
RigidBodyBuilder::dynamic()
|
||||
.translation(origin.coords + shift)
|
||||
.linvel(vector![20.0, 20.0, 0.0]),
|
||||
.translation(origin_v + shift)
|
||||
.linvel(Vector::new(20.0, 20.0, 0.0)),
|
||||
);
|
||||
colliders.insert_with_parent(ColliderBuilder::cuboid(1.0, 1.0, 1.0), ball1, bodies);
|
||||
|
||||
let ball2 = bodies.insert(RigidBodyBuilder::dynamic().translation(origin.coords + shift * 2.0));
|
||||
let ball2 = bodies.insert(RigidBodyBuilder::dynamic().translation(origin_v + shift * 2.0));
|
||||
colliders.insert_with_parent(ColliderBuilder::cuboid(1.0, 1.0, 1.0), ball2, bodies);
|
||||
|
||||
let joint1 = SphericalJointBuilder::new()
|
||||
.local_anchor2(Point::from(-shift))
|
||||
.local_anchor2(-shift)
|
||||
.limits(JointAxis::LinX, [-0.2, 0.2])
|
||||
.limits(JointAxis::LinY, [-0.2, 0.2]);
|
||||
|
||||
let joint2 = SphericalJointBuilder::new()
|
||||
.local_anchor2(Point::from(-shift))
|
||||
.local_anchor2(-shift)
|
||||
.limits(JointAxis::LinX, [-0.3, 0.3])
|
||||
.limits(JointAxis::LinY, [-0.3, 0.3]);
|
||||
|
||||
@@ -438,7 +443,7 @@ fn create_actuated_revolute_joints(
|
||||
colliders: &mut ColliderSet,
|
||||
impulse_joints: &mut ImpulseJointSet,
|
||||
multibody_joints: &mut MultibodyJointSet,
|
||||
origin: Point<f32>,
|
||||
origin: Vector,
|
||||
num: usize,
|
||||
use_articulations: bool,
|
||||
) {
|
||||
@@ -446,8 +451,8 @@ fn create_actuated_revolute_joints(
|
||||
let shift = 2.0;
|
||||
|
||||
// We will reuse this base configuration for all the impulse_joints here.
|
||||
let z = Vector::z_axis();
|
||||
let joint_template = RevoluteJointBuilder::new(z).local_anchor2(point![0.0, 0.0, -shift]);
|
||||
let z = Vector::Z;
|
||||
let joint_template = RevoluteJointBuilder::new(z).local_anchor2(Vector::new(0.0, 0.0, -shift));
|
||||
|
||||
let mut parent_handle = RigidBodyHandle::invalid();
|
||||
|
||||
@@ -466,7 +471,7 @@ fn create_actuated_revolute_joints(
|
||||
let shifty = (i >= 1) as u32 as f32 * -2.0;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(vector![origin.x, origin.y + shifty, origin.z + fi * shift])
|
||||
.translation(Vector::new(origin.x, origin.y + shifty, origin.z + fi * shift))
|
||||
// .rotation(Vector3::new(0.0, fi * 1.1, 0.0))
|
||||
;
|
||||
|
||||
@@ -487,7 +492,7 @@ fn create_actuated_revolute_joints(
|
||||
|
||||
if i == 1 {
|
||||
joint = joint
|
||||
.local_anchor2(point![0.0, 2.0, -shift])
|
||||
.local_anchor2(Vector::new(0.0, 2.0, -shift))
|
||||
.motor_velocity(-2.0, 1000.0);
|
||||
}
|
||||
|
||||
@@ -507,7 +512,7 @@ fn create_actuated_spherical_joints(
|
||||
colliders: &mut ColliderSet,
|
||||
impulse_joints: &mut ImpulseJointSet,
|
||||
multibody_joints: &mut MultibodyJointSet,
|
||||
origin: Point<f32>,
|
||||
origin: Vector,
|
||||
num: usize,
|
||||
use_articulations: bool,
|
||||
) {
|
||||
@@ -515,7 +520,7 @@ fn create_actuated_spherical_joints(
|
||||
let shift = 2.0;
|
||||
|
||||
// We will reuse this base configuration for all the impulse_joints here.
|
||||
let joint_template = SphericalJointBuilder::new().local_anchor1(point![0.0, 0.0, shift]);
|
||||
let joint_template = SphericalJointBuilder::new().local_anchor1(Vector::new(0.0, 0.0, shift));
|
||||
|
||||
let mut parent_handle = RigidBodyHandle::invalid();
|
||||
|
||||
@@ -532,7 +537,7 @@ fn create_actuated_spherical_joints(
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(vector![origin.x, origin.y, origin.z + fi * shift])
|
||||
.translation(Vector::new(origin.x, origin.y, origin.z + fi * shift))
|
||||
// .rotation(Vector3::new(0.0, fi * 1.1, 0.0))
|
||||
;
|
||||
|
||||
@@ -587,7 +592,7 @@ fn do_init_world(testbed: &mut Testbed, use_articulations: bool) {
|
||||
&mut colliders,
|
||||
&mut impulse_joints,
|
||||
&mut multibody_joints,
|
||||
point![20.0, 5.0, 0.0],
|
||||
Vector::new(20.0, 5.0, 0.0),
|
||||
4,
|
||||
use_articulations,
|
||||
);
|
||||
@@ -596,7 +601,7 @@ fn do_init_world(testbed: &mut Testbed, use_articulations: bool) {
|
||||
&mut colliders,
|
||||
&mut impulse_joints,
|
||||
&mut multibody_joints,
|
||||
point![25.0, 5.0, 0.0],
|
||||
Vector::new(25.0, 5.0, 0.0),
|
||||
4,
|
||||
use_articulations,
|
||||
);
|
||||
@@ -605,7 +610,7 @@ fn do_init_world(testbed: &mut Testbed, use_articulations: bool) {
|
||||
&mut colliders,
|
||||
&mut impulse_joints,
|
||||
&mut multibody_joints,
|
||||
point![20.0, 0.0, 0.0],
|
||||
Vector::new(20.0, 0.0, 0.0),
|
||||
3,
|
||||
use_articulations,
|
||||
);
|
||||
@@ -614,7 +619,7 @@ fn do_init_world(testbed: &mut Testbed, use_articulations: bool) {
|
||||
&mut colliders,
|
||||
&mut impulse_joints,
|
||||
&mut multibody_joints,
|
||||
point![34.0, 0.0, 0.0],
|
||||
Vector::new(34.0, 0.0, 0.0),
|
||||
use_articulations,
|
||||
);
|
||||
create_fixed_joints(
|
||||
@@ -622,7 +627,7 @@ fn do_init_world(testbed: &mut Testbed, use_articulations: bool) {
|
||||
&mut colliders,
|
||||
&mut impulse_joints,
|
||||
&mut multibody_joints,
|
||||
point![0.0, 10.0, 0.0],
|
||||
Vector::new(0.0, 10.0, 0.0),
|
||||
10,
|
||||
use_articulations,
|
||||
);
|
||||
@@ -631,7 +636,7 @@ fn do_init_world(testbed: &mut Testbed, use_articulations: bool) {
|
||||
&mut colliders,
|
||||
&mut impulse_joints,
|
||||
&mut multibody_joints,
|
||||
point![20.0, 10.0, 0.0],
|
||||
Vector::new(20.0, 10.0, 0.0),
|
||||
6,
|
||||
use_articulations,
|
||||
);
|
||||
@@ -640,7 +645,7 @@ fn do_init_world(testbed: &mut Testbed, use_articulations: bool) {
|
||||
&mut colliders,
|
||||
&mut impulse_joints,
|
||||
&mut multibody_joints,
|
||||
point![13.0, 10.0, 0.0],
|
||||
Vector::new(13.0, 10.0, 0.0),
|
||||
3,
|
||||
use_articulations,
|
||||
);
|
||||
@@ -657,7 +662,7 @@ fn do_init_world(testbed: &mut Testbed, use_articulations: bool) {
|
||||
&mut colliders,
|
||||
&mut impulse_joints,
|
||||
&mut multibody_joints,
|
||||
point![-5.0, 0.0, 0.0],
|
||||
Vector::new(-5.0, 0.0, 0.0),
|
||||
use_articulations,
|
||||
);
|
||||
create_coupled_joints(
|
||||
@@ -665,7 +670,7 @@ fn do_init_world(testbed: &mut Testbed, use_articulations: bool) {
|
||||
&mut colliders,
|
||||
&mut impulse_joints,
|
||||
&mut multibody_joints,
|
||||
point![0.0, 20.0, 0.0],
|
||||
Vector::new(0.0, 20.0, 0.0),
|
||||
use_articulations,
|
||||
);
|
||||
|
||||
@@ -673,7 +678,7 @@ fn do_init_world(testbed: &mut Testbed, use_articulations: bool) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![15.0, 5.0, 42.0], point![13.0, 1.0, 1.0]);
|
||||
testbed.look_at(Vec3::new(15.0, 5.0, 42.0), Vec3::new(13.0, 1.0, 1.0));
|
||||
}
|
||||
|
||||
pub fn init_world_with_joints(testbed: &mut Testbed) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use kiss3d::color::Color;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
@@ -5,16 +6,19 @@ pub fn build_block(
|
||||
testbed: &mut Testbed,
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
half_extents: Vector<f32>,
|
||||
shift: Vector<f32>,
|
||||
half_extents: Vector,
|
||||
shift: Vector,
|
||||
(mut numx, numy, mut numz): (usize, usize, usize),
|
||||
) {
|
||||
let dimensions = [half_extents.xyz(), half_extents.zyx()];
|
||||
let dimensions = [
|
||||
half_extents,
|
||||
Vector::new(half_extents.z, half_extents.y, half_extents.x),
|
||||
];
|
||||
let block_width = 2.0 * half_extents.z * numx as f32;
|
||||
let block_height = 2.0 * half_extents.y * numy as f32;
|
||||
let spacing = (half_extents.z * numx as f32 - half_extents.x) / (numz as f32 - 1.0);
|
||||
let mut color0 = [0.7, 0.5, 0.9];
|
||||
let mut color1 = [0.6, 1.0, 0.6];
|
||||
let mut color0 = Color::new(0.7, 0.5, 0.9, 1.0);
|
||||
let mut color1 = Color::new(0.6, 1.0, 0.6, 1.0);
|
||||
|
||||
for i in 0..numy {
|
||||
std::mem::swap(&mut numx, &mut numz);
|
||||
@@ -36,11 +40,11 @@ pub fn build_block(
|
||||
};
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(
|
||||
x + dim.x + shift.x,
|
||||
y + dim.y + shift.y,
|
||||
z + dim.z + shift.z
|
||||
]);
|
||||
z + dim.z + shift.z,
|
||||
));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
@@ -52,16 +56,16 @@ pub fn build_block(
|
||||
}
|
||||
|
||||
// Close the top.
|
||||
let dim = half_extents.zxy();
|
||||
let dim = Vector::new(half_extents.z, half_extents.x, half_extents.y);
|
||||
|
||||
for i in 0..(block_width / (dim.x * 2.0)) as usize {
|
||||
for j in 0..(block_width / (dim.z * 2.0)) as usize {
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(
|
||||
i as f32 * dim.x * 2.0 + dim.x + shift.x,
|
||||
dim.y + shift.y + block_height,
|
||||
j as f32 * dim.z * 2.0 + dim.z + shift.z
|
||||
]);
|
||||
j as f32 * dim.z * 2.0 + dim.z + shift.z,
|
||||
));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
@@ -86,7 +90,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 50.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -94,7 +98,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let half_extents = vector![0.02, 0.1, 0.4] / 2.0 * 10.0;
|
||||
let half_extents = Vector::new(0.02, 0.1, 0.4) / 2.0 * 10.0;
|
||||
let mut block_height = 0.0;
|
||||
// These should only be set to odd values otherwise
|
||||
// the blocks won't align in the nicest way.
|
||||
@@ -111,7 +115,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
half_extents,
|
||||
vector![-block_width / 2.0, block_height, -block_width / 2.0],
|
||||
Vector::new(-block_width / 2.0, block_height, -block_width / 2.0),
|
||||
(numx, numy, numz),
|
||||
);
|
||||
block_height += numy as f32 * half_extents.y * 2.0 + half_extents.x * 2.0;
|
||||
@@ -124,5 +128,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 5.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -28,7 +28,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* A rectangle that only rotates along the `x` axis.
|
||||
*/
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![0.0, 3.0, 0.0])
|
||||
.translation(Vector::new(0.0, 3.0, 0.0))
|
||||
.lock_translations()
|
||||
.enabled_rotations(true, false, false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
@@ -39,8 +39,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* A tilted capsule that cannot rotate.
|
||||
*/
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(vector![0.0, 5.0, 0.0])
|
||||
.rotation(Vector::x() * 1.0)
|
||||
.translation(Vector::new(0.0, 5.0, 0.0))
|
||||
.rotation(Vector::X * 1.0)
|
||||
.lock_rotations();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_y(0.6, 0.4);
|
||||
@@ -52,5 +52,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 3.0, 0.0], point![0.0, 3.0, 0.0]);
|
||||
testbed.look_at(Vec3::new(10.0, 3.0, 0.0), Vec3::new(0.0, 3.0, 0.0));
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
for i in 0..n {
|
||||
let (ball_pos, attach) = (
|
||||
vector![i as Real * 2.2 * radius, 0.0, 0.0],
|
||||
Vector::y() * length,
|
||||
Vector::new(i as Real * 2.2 * radius, 0.0, 0.0),
|
||||
Vector::Y * length,
|
||||
);
|
||||
let vel = if i >= n - 1 {
|
||||
vector![7.0, 0.0, 0.0]
|
||||
Vector::new(7.0, 0.0, 0.0)
|
||||
} else {
|
||||
Vector::zeros()
|
||||
Vector::ZERO
|
||||
};
|
||||
|
||||
let ground = bodies.insert(RigidBodyBuilder::fixed().translation(ball_pos + attach));
|
||||
@@ -33,7 +33,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let handle = bodies.insert(rb);
|
||||
colliders.insert_with_parent(co.clone(), handle, &mut bodies);
|
||||
|
||||
let joint = SphericalJointBuilder::new().local_anchor2(attach.into());
|
||||
let joint = SphericalJointBuilder::new().local_anchor2(attach);
|
||||
impulse_joints.insert(ground, handle, joint, true);
|
||||
}
|
||||
|
||||
@@ -41,5 +41,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -20,24 +20,24 @@ impl PhysicsHooks for OneWayPlatformHook {
|
||||
// - If context.collider2 == self.platform1 then the allowed normal is -y.
|
||||
// - If context.collider1 == self.platform2 then its allowed normal +y needs to be flipped to -y.
|
||||
// - If context.collider2 == self.platform2 then the allowed normal -y needs to be flipped to +y.
|
||||
let mut allowed_local_n1 = Vector::zeros();
|
||||
let mut allowed_local_n1 = Vector::ZERO;
|
||||
|
||||
if context.collider1 == self.platform1 {
|
||||
allowed_local_n1 = Vector::y();
|
||||
allowed_local_n1 = Vector::Y;
|
||||
} else if context.collider2 == self.platform1 {
|
||||
// Flip the allowed direction.
|
||||
allowed_local_n1 = -Vector::y();
|
||||
allowed_local_n1 = -Vector::Y;
|
||||
}
|
||||
|
||||
if context.collider1 == self.platform2 {
|
||||
allowed_local_n1 = -Vector::y();
|
||||
allowed_local_n1 = -Vector::Y;
|
||||
} else if context.collider2 == self.platform2 {
|
||||
// Flip the allowed direction.
|
||||
allowed_local_n1 = Vector::y();
|
||||
allowed_local_n1 = Vector::Y;
|
||||
}
|
||||
|
||||
// Call the helper function that simulates one-way platforms.
|
||||
context.update_as_oneway_platform(&allowed_local_n1, 0.1);
|
||||
context.update_as_oneway_platform(allowed_local_n1, 0.1);
|
||||
|
||||
// Set the surface velocity of the accepted contacts.
|
||||
let tangent_velocity =
|
||||
@@ -69,11 +69,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0)
|
||||
.translation(vector![0.0, 2.0, 30.0])
|
||||
.translation(Vector::new(0.0, 2.0, 30.0))
|
||||
.active_hooks(ActiveHooks::MODIFY_SOLVER_CONTACTS);
|
||||
let platform1 = colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
let collider = ColliderBuilder::cuboid(9.0, 0.5, 25.0)
|
||||
.translation(vector![0.0, -2.0, -30.0])
|
||||
.translation(Vector::new(0.0, -2.0, -30.0))
|
||||
.active_hooks(ActiveHooks::MODIFY_SOLVER_CONTACTS);
|
||||
let platform2 = colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
@@ -93,7 +93,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
if run_state.timestep_id % 200 == 0 && physics.bodies.len() <= 7 {
|
||||
// Spawn a new cube.
|
||||
let collider = ColliderBuilder::cuboid(1.0, 2.0, 1.5);
|
||||
let body = RigidBodyBuilder::dynamic().translation(vector![0.0, 6.0, 20.0]);
|
||||
let body = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 6.0, 20.0));
|
||||
let handle = physics.bodies.insert(body);
|
||||
physics
|
||||
.colliders
|
||||
@@ -122,8 +122,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
colliders,
|
||||
impulse_joints,
|
||||
multibody_joints,
|
||||
vector![0.0, -9.81, 0.0],
|
||||
Vector::new(0.0, -9.81, 0.0),
|
||||
physics_hooks,
|
||||
);
|
||||
testbed.look_at(point![-100.0, 0.0, 0.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 0.0, 0.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 10.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -40,7 +40,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -52,7 +52,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Setup a velocity-based kinematic rigid body.
|
||||
*/
|
||||
let platform_body =
|
||||
RigidBodyBuilder::kinematic_velocity_based().translation(vector![0.0, 1.5 + 0.8, 0.0]);
|
||||
RigidBodyBuilder::kinematic_velocity_based().translation(Vector::new(0.0, 1.5 + 0.8, 0.0));
|
||||
let velocity_based_platform_handle = bodies.insert(platform_body);
|
||||
let collider = ColliderBuilder::cuboid(rad * 10.0, rad, rad * 10.0);
|
||||
colliders.insert_with_parent(collider, velocity_based_platform_handle, &mut bodies);
|
||||
@@ -60,11 +60,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Setup a position-based kinematic rigid body.
|
||||
*/
|
||||
let platform_body = RigidBodyBuilder::kinematic_position_based().translation(vector![
|
||||
let platform_body = RigidBodyBuilder::kinematic_position_based().translation(Vector::new(
|
||||
0.0,
|
||||
3.0 + 1.5 + 0.8,
|
||||
0.0
|
||||
]);
|
||||
0.0,
|
||||
));
|
||||
let position_based_platform_handle = bodies.insert(platform_body);
|
||||
let collider = ColliderBuilder::cuboid(rad * 10.0, rad, rad * 10.0);
|
||||
colliders.insert_with_parent(collider, position_based_platform_handle, &mut bodies);
|
||||
@@ -73,25 +73,24 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Setup a callback to control the platform.
|
||||
*/
|
||||
testbed.add_callback(move |_, physics, _, run_state| {
|
||||
let velocity = vector![
|
||||
let velocity = Vector::new(
|
||||
0.0,
|
||||
(run_state.time * 2.0).cos(),
|
||||
run_state.time.sin() * 2.0
|
||||
];
|
||||
run_state.time.sin() * 2.0,
|
||||
);
|
||||
|
||||
// Update the velocity-based kinematic body by setting its velocity.
|
||||
if let Some(platform) = physics.bodies.get_mut(velocity_based_platform_handle) {
|
||||
platform.set_linvel(velocity, true);
|
||||
platform.set_angvel(vector![0.0, 1.0, 0.0], true);
|
||||
platform.set_angvel(Vector::new(0.0, 1.0, 0.0), true);
|
||||
}
|
||||
|
||||
// Update the position-based kinematic body by setting its next position.
|
||||
if let Some(platform) = physics.bodies.get_mut(position_based_platform_handle) {
|
||||
let mut next_tra = *platform.translation();
|
||||
let mut next_rot = *platform.rotation();
|
||||
next_tra += -velocity * physics.integration_parameters.dt;
|
||||
next_rot = Rotation::new(vector![0.0, -0.5 * physics.integration_parameters.dt, 0.0])
|
||||
* next_rot;
|
||||
let next_tra = platform.translation() + (-velocity * physics.integration_parameters.dt);
|
||||
let next_rot = platform.rotation();
|
||||
let delta_rot = Rotation::from_rotation_y(-0.5 * physics.integration_parameters.dt);
|
||||
let next_rot = delta_rot * next_rot;
|
||||
platform.set_next_kinematic_translation(next_tra);
|
||||
platform.set_next_kinematic_rotation(next_rot);
|
||||
}
|
||||
@@ -101,5 +100,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Run the simulation.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![-10.0, 5.0, -10.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 5.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 100.1;
|
||||
let ground_height = 2.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -44,7 +44,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shiftz - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = match j % 5 {
|
||||
@@ -68,5 +68,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 20.;
|
||||
let ground_height = 1.0;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, 2.0).restitution(1.0);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -27,11 +27,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
for j in 0..2 {
|
||||
for i in 0..=num {
|
||||
let x = (i as f32) - num as f32 / 2.0;
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(
|
||||
x * 2.0,
|
||||
10.0 * (j as f32 + 1.0),
|
||||
0.0
|
||||
]);
|
||||
0.0,
|
||||
));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).restitution((i as f32) / (num as f32));
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -42,5 +42,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![0.0, 3.0, 30.0], point![0.0, 3.0, 0.0]);
|
||||
testbed.look_at(Vec3::new(0.0, 3.0, 30.0), Vec3::new(0.0, 3.0, 0.0));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::utils::character::{self, CharacterControlMode};
|
||||
use kiss3d::color::Color;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::control::{KinematicCharacterController, PidController};
|
||||
use rapier3d::prelude::*;
|
||||
@@ -18,43 +19,43 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 0.75;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(
|
||||
-ground_size - ground_height,
|
||||
ground_height,
|
||||
0.0
|
||||
]);
|
||||
0.0,
|
||||
));
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_height, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(
|
||||
ground_size + ground_height,
|
||||
ground_height,
|
||||
0.0
|
||||
]);
|
||||
0.0,
|
||||
));
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_height, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(
|
||||
0.0,
|
||||
ground_height,
|
||||
-ground_size - ground_height
|
||||
]);
|
||||
-ground_size - ground_height,
|
||||
));
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_height);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(
|
||||
0.0,
|
||||
ground_height,
|
||||
ground_size + ground_height
|
||||
]);
|
||||
ground_size + ground_height,
|
||||
));
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_height);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
@@ -64,12 +65,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::kinematic_position_based().translation(vector![0.0, 0.3, 0.0]);
|
||||
RigidBodyBuilder::kinematic_position_based().translation(Vector::new(0.0, 0.3, 0.0));
|
||||
let character_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(0.15, 0.3, 0.15);
|
||||
colliders.insert_with_parent(collider, character_handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_body_color(character_handle, [1., 131. / 255., 244.0 / 255.]);
|
||||
testbed.set_initial_body_color(
|
||||
character_handle,
|
||||
Color::new(1., 131. / 255., 244.0 / 255., 1.0),
|
||||
);
|
||||
|
||||
/*
|
||||
* Tethered Ball
|
||||
@@ -77,7 +81,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let rad = 0.04;
|
||||
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::new(RigidBodyType::Dynamic).translation(vector![1.0, 1.0, 0.0]);
|
||||
RigidBodyBuilder::new(RigidBodyType::Dynamic).translation(Vector::new(1.0, 1.0, 0.0));
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad);
|
||||
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||
@@ -109,5 +113,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![10.0, 10.0, 10.0], point![0.0, 0.0, 0.0]);
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::new(0.0, 0.0, 0.0));
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use kiss3d::color::Color;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
@@ -13,10 +14,10 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Ground.
|
||||
*/
|
||||
let ground_size = 200.1;
|
||||
let ground_size = 10.1;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
@@ -38,12 +39,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_body_color(handle, [0.5, 0.5, 1.0]);
|
||||
testbed.set_initial_body_color(handle, Color::new(0.5, 0.5, 1.0, 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +53,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
|
||||
// Rigid body so that the sensor can move.
|
||||
let sensor = RigidBodyBuilder::dynamic().translation(vector![0.0, 5.0, 0.0]);
|
||||
let sensor = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 5.0, 0.0));
|
||||
let sensor_handle = bodies.insert(sensor);
|
||||
|
||||
// Solid cube attached to the sensor which
|
||||
@@ -68,15 +69,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
.active_events(ActiveEvents::COLLISION_EVENTS);
|
||||
colliders.insert_with_parent(sensor_collider, sensor_handle, &mut bodies);
|
||||
|
||||
testbed.set_initial_body_color(sensor_handle, [0.5, 1.0, 1.0]);
|
||||
testbed.set_initial_body_color(sensor_handle, Color::new(0.5, 1.0, 1.0, 1.0));
|
||||
|
||||
// Callback that will be executed on the main loop to handle proximities.
|
||||
testbed.add_callback(move |mut graphics, physics, events, _| {
|
||||
while let Ok(prox) = events.collision_events.try_recv() {
|
||||
let color = if prox.started() {
|
||||
[1.0, 1.0, 0.0]
|
||||
Color::new(1.0, 1.0, 0.0, 1.0)
|
||||
} else {
|
||||
[0.5, 0.5, 1.0]
|
||||
Color::new(0.5, 0.5, 1.0, 1.0)
|
||||
};
|
||||
|
||||
let parent_handle1 = physics.colliders[prox.collider1()].parent().unwrap();
|
||||
@@ -84,10 +85,10 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
if let Some(graphics) = &mut graphics {
|
||||
if parent_handle1 != ground_handle && parent_handle1 != sensor_handle {
|
||||
graphics.set_body_color(parent_handle1, color);
|
||||
graphics.set_body_color(parent_handle1, color, false);
|
||||
}
|
||||
if parent_handle2 != ground_handle && parent_handle2 != sensor_handle {
|
||||
graphics.set_body_color(parent_handle2, color);
|
||||
graphics.set_body_color(parent_handle2, color, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,5 +98,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![-6.0, 4.0, -6.0], point![0.0, 1.0, 0.0]);
|
||||
testbed.look_at(Vec3::new(6.0, 4.0, 6.0), Vec3::new(0.0, 1.0, 0.0));
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let critical_damping = 2.0 * (stiffness * mass).sqrt();
|
||||
for i in 0..=num {
|
||||
let x_pos = -6.0 + 1.5 * i as f32;
|
||||
let ball_pos = point![x_pos, 4.5, 0.0];
|
||||
let ball_pos = Vector::new(x_pos, 4.5, 0.0);
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(ball_pos.coords)
|
||||
.translation(ball_pos)
|
||||
.can_sleep(false);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(radius);
|
||||
@@ -38,12 +38,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let damping_ratio = i as f32 / (num as f32 / 2.0);
|
||||
let damping = damping_ratio * critical_damping;
|
||||
let joint = SpringJointBuilder::new(0.0, stiffness, damping)
|
||||
.local_anchor1(ball_pos - Vector::y() * 3.0);
|
||||
.local_anchor1(ball_pos - Vector::Y * 3.0);
|
||||
impulse_joints.insert(ground_handle, handle, joint, true);
|
||||
|
||||
// Box that will fall on to of the springed balls, makes the simulation funier to watch.
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::dynamic().translation(ball_pos.coords + Vector::y() * 5.0);
|
||||
// Box that will fall on to of the springed balls, makes the simulation funnier to watch.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(ball_pos + Vector::Y * 5.0);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(radius, radius, radius).density(100.0);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -57,8 +56,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
colliders,
|
||||
impulse_joints,
|
||||
multibody_joints,
|
||||
vector![0.0, -9.81, 0.0],
|
||||
Vector::new(0.0, -9.81, 0.0),
|
||||
(),
|
||||
);
|
||||
testbed.look_at(point![15.0, 5.0, 42.0], point![13.0, 1.0, 1.0]);
|
||||
testbed.look_at(Vec3::new(15.0, 5.0, 42.0), Vec3::new(13.0, 1.0, 1.0));
|
||||
}
|
||||
|
||||
53
examples3d/stress_tests/balls3.rs
Normal file
53
examples3d/stress_tests/balls3.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use glam::Vec3;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Create the balls
|
||||
*/
|
||||
let num = 20;
|
||||
let rad = 1.0;
|
||||
|
||||
let shift = rad * 2.0 + 1.0;
|
||||
let centerx = shift * (num as f32) / 2.0;
|
||||
let centery = shift / 2.0;
|
||||
let centerz = shift * (num as f32) / 2.0;
|
||||
|
||||
for i in 0..num {
|
||||
for j in 0usize..num {
|
||||
for k in 0..num {
|
||||
let x = i as f32 * shift - centerx;
|
||||
let y = j as f32 * shift + centery;
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
let status = if j == 0 {
|
||||
RigidBodyType::Fixed
|
||||
} else {
|
||||
RigidBodyType::Dynamic
|
||||
};
|
||||
let density = 0.477;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(Vec3::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).density(density);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
60
examples3d/stress_tests/boxes3.rs
Normal file
60
examples3d/stress_tests/boxes3.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 200.1;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vec3::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let num = 10;
|
||||
let rad = 1.0;
|
||||
|
||||
let shift = rad * 2.0;
|
||||
let centerx = shift * (num / 2) as f32;
|
||||
let centery = shift / 2.0;
|
||||
let centerz = shift * (num / 2) as f32;
|
||||
|
||||
let mut offset = -(num as f32) * (rad * 2.0) * 0.5;
|
||||
|
||||
for j in 0usize..num {
|
||||
for i in 0..num {
|
||||
for k in 0usize..num {
|
||||
let x = i as f32 * shift - centerx + offset;
|
||||
let y = j as f32 * shift + centery;
|
||||
let z = k as f32 * shift - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
offset -= 0.05 * rad * (num as f32 - 1.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
61
examples3d/stress_tests/capsules3.rs
Normal file
61
examples3d/stress_tests/capsules3.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 200.1;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vec3::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let num = 8;
|
||||
let rad = 1.0;
|
||||
|
||||
let shift = rad * 2.0 + rad;
|
||||
let shifty = rad * 4.0;
|
||||
let centerx = shift * (num / 2) as f32;
|
||||
let centery = shift / 2.0;
|
||||
let centerz = shift * (num / 2) as f32;
|
||||
|
||||
let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5;
|
||||
|
||||
for j in 0usize..47 {
|
||||
for i in 0..num {
|
||||
for k in 0usize..num {
|
||||
let x = i as f32 * shift - centerx + offset;
|
||||
let y = j as f32 * shifty + centery + 3.0;
|
||||
let z = k as f32 * shift - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::capsule_y(rad, rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
offset -= 0.05 * rad * (num as f32 - 1.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
76
examples3d/stress_tests/ccd3.rs
Normal file
76
examples3d/stress_tests/ccd3.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 100.1;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vec3::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let num = 4;
|
||||
let numj = 20;
|
||||
let rad = 1.0;
|
||||
|
||||
let shiftx = rad * 2.0 + rad;
|
||||
let shifty = rad * 2.0 + rad;
|
||||
let shiftz = rad * 2.0 + rad;
|
||||
let centerx = shiftx * (num / 2) as f32;
|
||||
let centery = shifty / 2.0;
|
||||
let centerz = shiftz * (num / 2) as f32;
|
||||
|
||||
let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5;
|
||||
|
||||
for j in 0usize..numj {
|
||||
for i in 0..num {
|
||||
for k in 0usize..num {
|
||||
let x = i as f32 * shiftx - centerx + offset;
|
||||
let y = j as f32 * shifty + centery + 3.0;
|
||||
let z = k as f32 * shiftz - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic()
|
||||
.translation(Vec3::new(x, y, z))
|
||||
.linvel(Vec3::new(0.0, -1000.0, 0.0))
|
||||
.ccd_enabled(true);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = match j % 5 {
|
||||
0 => ColliderBuilder::cuboid(rad, rad, rad),
|
||||
1 => ColliderBuilder::ball(rad),
|
||||
// Rounded cylinders are much more efficient that cylinder, even if the
|
||||
// rounding margin is small.
|
||||
2 => ColliderBuilder::round_cylinder(rad, rad, rad / 10.0),
|
||||
3 => ColliderBuilder::cone(rad, rad),
|
||||
_ => ColliderBuilder::capsule_y(rad, rad),
|
||||
};
|
||||
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
offset -= 0.05 * rad * (num as f32 - 1.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
66
examples3d/stress_tests/compound3.rs
Normal file
66
examples3d/stress_tests/compound3.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 200.1;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vec3::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let num = 8;
|
||||
let rad = 0.2;
|
||||
|
||||
let shift = rad * 4.0 + rad;
|
||||
let centerx = shift * (num / 2) as f32;
|
||||
let centery = shift / 2.0;
|
||||
let centerz = shift * (num / 2) as f32;
|
||||
|
||||
let mut offset = -(num as f32) * (rad * 2.0 + rad) * 0.5;
|
||||
|
||||
for j in 0usize..25 {
|
||||
for i in 0..num {
|
||||
for k in 0usize..num {
|
||||
let x = i as f32 * shift * 5.0 - centerx + offset;
|
||||
let y = j as f32 * (shift * 5.0) + centery + 3.0;
|
||||
let z = k as f32 * shift * 2.0 - centerz + offset;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider1 = ColliderBuilder::cuboid(rad * 10.0, rad, rad);
|
||||
let collider2 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
||||
.translation(Vec3::new(rad * 10.0, rad * 10.0, 0.0));
|
||||
let collider3 = ColliderBuilder::cuboid(rad, rad * 10.0, rad)
|
||||
.translation(Vec3::new(-rad * 10.0, rad * 10.0, 0.0));
|
||||
colliders.insert_with_parent(collider1, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider2, handle, &mut bodies);
|
||||
colliders.insert_with_parent(collider3, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
offset -= 0.05 * rad * (num as f32 - 1.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
73
examples3d/stress_tests/convex_polyhedron3.rs
Normal file
73
examples3d/stress_tests/convex_polyhedron3.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
use rand::distr::{Distribution, StandardUniform};
|
||||
use rand::{SeedableRng, rngs::StdRng};
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 200.1;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vec3::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let num = 8;
|
||||
let scale = 2.0;
|
||||
let rad = 1.0;
|
||||
let border_rad = 0.1;
|
||||
|
||||
let shift = border_rad * 2.0 + scale;
|
||||
let centerx = shift * (num / 2) as f32;
|
||||
let centery = shift / 2.0;
|
||||
let centerz = shift * (num / 2) as f32;
|
||||
|
||||
let mut offset = -(num as f32) * shift * 0.5;
|
||||
|
||||
let mut rng = StdRng::seed_from_u64(0);
|
||||
let distribution = StandardUniform;
|
||||
|
||||
for j in 0usize..47 {
|
||||
for i in 0..num {
|
||||
for k in 0usize..num {
|
||||
let x = i as f32 * shift - centerx + offset;
|
||||
let y = j as f32 * shift + centery + 3.0;
|
||||
let z = k as f32 * shift - centerz + offset;
|
||||
|
||||
let mut points = Vec::new();
|
||||
for _ in 0..10 {
|
||||
let pt: [f32; 3] = distribution.sample(&mut rng);
|
||||
points.push(Vec3::from(pt) * scale);
|
||||
}
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::round_convex_hull(&points, border_rad).unwrap();
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
|
||||
offset -= 0.05 * rad * (num as f32 - 1.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
77
examples3d/stress_tests/heightfield3.rs
Normal file
77
examples3d/stress_tests/heightfield3.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::na::ComplexField;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = Vec3::new(200.0, 1.0, 200.0);
|
||||
let nsubdivs = 20;
|
||||
|
||||
let heights = Array2::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);
|
||||
|
||||
// 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)
|
||||
}
|
||||
});
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::heightfield(heights, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let num = 8;
|
||||
let rad = 1.0;
|
||||
|
||||
let shift = rad * 2.0 + rad;
|
||||
let centerx = shift * (num / 2) as f32;
|
||||
let centery = shift / 2.0;
|
||||
let centerz = shift * (num / 2) as f32;
|
||||
|
||||
for j in 0usize..47 {
|
||||
for i in 0..num {
|
||||
for k in 0usize..num {
|
||||
let x = i as f32 * shift - centerx;
|
||||
let y = j as f32 * shift + centery + 3.0;
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
if j % 2 == 0 {
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
} else {
|
||||
let collider = ColliderBuilder::ball(rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
63
examples3d/stress_tests/joint_ball3.rs
Normal file
63
examples3d/stress_tests/joint_ball3.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let mut impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
let rad = 0.4;
|
||||
let num = 100;
|
||||
let shift = 1.0;
|
||||
|
||||
let mut body_handles = Vec::new();
|
||||
|
||||
for k in 0..num {
|
||||
for i in 0..num {
|
||||
let fk = k as f32;
|
||||
let fi = i as f32;
|
||||
|
||||
let status = if i == 0 && (k % 4 == 0 || k == num - 1) {
|
||||
RigidBodyType::Fixed
|
||||
} else {
|
||||
RigidBodyType::Dynamic
|
||||
};
|
||||
|
||||
let rigid_body =
|
||||
RigidBodyBuilder::new(status).translation(Vec3::new(fk * shift, 0.0, fi * shift));
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad);
|
||||
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||
|
||||
// Vertical joint.
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint = SphericalJointBuilder::new().local_anchor2(Vec3::new(0.0, 0.0, -shift));
|
||||
impulse_joints.insert(parent_handle, child_handle, joint, true);
|
||||
}
|
||||
|
||||
// Horizontal joint.
|
||||
if k > 0 {
|
||||
let parent_index = body_handles.len() - num;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint = SphericalJointBuilder::new().local_anchor2(Vec3::new(-shift, 0.0, 0.0));
|
||||
impulse_joints.insert(parent_handle, child_handle, joint, true);
|
||||
}
|
||||
|
||||
body_handles.push(child_handle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(
|
||||
Vec3::new(-110.0, -46.0, 170.0),
|
||||
Vec3::new(54.0, -38.0, 29.0),
|
||||
);
|
||||
}
|
||||
81
examples3d/stress_tests/joint_fixed3.rs
Normal file
81
examples3d/stress_tests/joint_fixed3.rs
Normal file
@@ -0,0 +1,81 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let mut impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
let rad = 0.4;
|
||||
let num = 5;
|
||||
let shift = 1.0;
|
||||
|
||||
let mut body_handles = Vec::new();
|
||||
|
||||
for m in 0..10 {
|
||||
let z = m as f32 * shift * (num as f32 + 2.0);
|
||||
|
||||
for l in 0..10 {
|
||||
let y = l as f32 * shift * 3.0;
|
||||
|
||||
for j in 0..5 {
|
||||
let x = j as f32 * shift * (num as f32) * 2.0;
|
||||
|
||||
for k in 0..num {
|
||||
for i in 0..num {
|
||||
let fk = k as f32;
|
||||
let fi = i as f32;
|
||||
|
||||
// NOTE: the num - 2 test is to avoid two consecutive
|
||||
// fixed bodies. Because physx will crash if we add
|
||||
// a joint between these.
|
||||
|
||||
let status = if i == 0 && (k % 4 == 0 && k != num - 2 || k == num - 1) {
|
||||
RigidBodyType::Fixed
|
||||
} else {
|
||||
RigidBodyType::Dynamic
|
||||
};
|
||||
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(Vec3::new(
|
||||
x + fk * shift,
|
||||
y,
|
||||
z + fi * shift,
|
||||
));
|
||||
let child_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad);
|
||||
colliders.insert_with_parent(collider, child_handle, &mut bodies);
|
||||
|
||||
// Vertical joint.
|
||||
if i > 0 {
|
||||
let parent_handle = *body_handles.last().unwrap();
|
||||
let joint =
|
||||
FixedJointBuilder::new().local_anchor2(Vec3::new(0.0, 0.0, -shift));
|
||||
impulse_joints.insert(parent_handle, child_handle, joint, true);
|
||||
}
|
||||
|
||||
// Horizontal joint.
|
||||
if k > 0 {
|
||||
let parent_index = body_handles.len() - num;
|
||||
let parent_handle = body_handles[parent_index];
|
||||
let joint =
|
||||
FixedJointBuilder::new().local_anchor2(Vec3::new(-shift, 0.0, 0.0));
|
||||
impulse_joints.insert(parent_handle, child_handle, joint, true);
|
||||
}
|
||||
|
||||
body_handles.push(child_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(-38.0, 14.0, 108.0), Vec3::new(46.0, 12.0, 23.0));
|
||||
}
|
||||
61
examples3d/stress_tests/joint_prismatic3.rs
Normal file
61
examples3d/stress_tests/joint_prismatic3.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let mut impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
let rad = 0.4;
|
||||
let num = 5;
|
||||
let shift = 1.0;
|
||||
|
||||
for m in 0..8 {
|
||||
let z = m as f32 * shift * (num as f32 + 2.0);
|
||||
|
||||
for l in 0..8 {
|
||||
let y = l as f32 * shift * (num as f32) * 2.0;
|
||||
|
||||
for j in 0..50 {
|
||||
let x = j as f32 * shift * 4.0;
|
||||
|
||||
let ground = RigidBodyBuilder::fixed().translation(Vec3::new(x, y, z));
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, curr_parent, &mut bodies);
|
||||
|
||||
for i in 0..num {
|
||||
let z = z + (i + 1) as f32 * shift;
|
||||
let density = 1.0;
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, z));
|
||||
let curr_child = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).density(density);
|
||||
colliders.insert_with_parent(collider, curr_child, &mut bodies);
|
||||
|
||||
let axis = if i % 2 == 0 {
|
||||
Vec3::new(1.0, 1.0, 0.0).normalize()
|
||||
} else {
|
||||
Vec3::new(-1.0, 1.0, 0.0).normalize()
|
||||
};
|
||||
|
||||
let prism = PrismaticJointBuilder::new(axis)
|
||||
.local_anchor2(Vec3::new(0.0, 0.0, -shift))
|
||||
.limits([-2.0, 0.0]);
|
||||
impulse_joints.insert(curr_parent, curr_child, prism, true);
|
||||
|
||||
curr_parent = curr_child;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(262.0, 63.0, 124.0), Vec3::new(101.0, 4.0, -3.0));
|
||||
}
|
||||
76
examples3d/stress_tests/joint_revolute3.rs
Normal file
76
examples3d/stress_tests/joint_revolute3.rs
Normal file
@@ -0,0 +1,76 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let mut impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
let rad = 0.4;
|
||||
let num = 10;
|
||||
let shift = 2.0;
|
||||
|
||||
for l in 0..4 {
|
||||
let y = l as f32 * shift * (num as f32) * 3.0;
|
||||
|
||||
for j in 0..50 {
|
||||
let x = j as f32 * shift * 4.0;
|
||||
|
||||
let ground = RigidBodyBuilder::fixed().translation(Vec3::new(x, y, 0.0));
|
||||
let mut curr_parent = bodies.insert(ground);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, curr_parent, &mut bodies);
|
||||
|
||||
for i in 0..num {
|
||||
// Create four bodies.
|
||||
let z = i as f32 * shift * 2.0 + shift;
|
||||
let positions = [
|
||||
Pose3::translation(x, y, z),
|
||||
Pose3::translation(x + shift, y, z),
|
||||
Pose3::translation(x + shift, y, z + shift),
|
||||
Pose3::translation(x, y, z + shift),
|
||||
];
|
||||
|
||||
let mut handles = [curr_parent; 4];
|
||||
for k in 0..4 {
|
||||
let density = 1.0;
|
||||
let rigid_body = RigidBodyBuilder::dynamic().pose(positions[k]);
|
||||
handles[k] = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad).density(density);
|
||||
colliders.insert_with_parent(collider, handles[k], &mut bodies);
|
||||
}
|
||||
|
||||
// Setup four impulse_joints.
|
||||
let x = Vec3::X;
|
||||
let z = Vec3::Z;
|
||||
|
||||
let revs = [
|
||||
RevoluteJointBuilder::new(z).local_anchor2(Vec3::new(0.0, 0.0, -shift)),
|
||||
RevoluteJointBuilder::new(x).local_anchor2(Vec3::new(-shift, 0.0, 0.0)),
|
||||
RevoluteJointBuilder::new(z).local_anchor2(Vec3::new(0.0, 0.0, -shift)),
|
||||
RevoluteJointBuilder::new(x).local_anchor2(Vec3::new(shift, 0.0, 0.0)),
|
||||
];
|
||||
|
||||
impulse_joints.insert(curr_parent, handles[0], revs[0], true);
|
||||
impulse_joints.insert(handles[0], handles[1], revs[1], true);
|
||||
impulse_joints.insert(handles[1], handles[2], revs[2], true);
|
||||
impulse_joints.insert(handles[2], handles[3], revs[3], true);
|
||||
|
||||
curr_parent = handles[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(
|
||||
Vec3::new(478.0, 83.0, 228.0),
|
||||
Vec3::new(134.0, 83.0, -116.0),
|
||||
);
|
||||
}
|
||||
126
examples3d/stress_tests/keva3.rs
Normal file
126
examples3d/stress_tests/keva3.rs
Normal file
@@ -0,0 +1,126 @@
|
||||
use kiss3d::color::Color;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::glamx::Vec3Swizzles;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn build_block(
|
||||
testbed: &mut Testbed,
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
half_extents: Vec3,
|
||||
shift: Vec3,
|
||||
(mut numx, numy, mut numz): (usize, usize, usize),
|
||||
) {
|
||||
let dimensions = [half_extents.xyz(), half_extents.zyx()];
|
||||
let block_width = 2.0 * half_extents.z * numx as f32;
|
||||
let block_height = 2.0 * half_extents.y * numy as f32;
|
||||
let spacing = (half_extents.z * numx as f32 - half_extents.x) / (numz as f32 - 1.0);
|
||||
let mut color0 = Color::new(0.7, 0.5, 0.9, 1.0);
|
||||
let mut color1 = Color::new(0.6, 1.0, 0.6, 1.0);
|
||||
|
||||
for i in 0..numy {
|
||||
std::mem::swap(&mut numx, &mut numz);
|
||||
let dim = dimensions[i % 2];
|
||||
let y = dim.y * i as f32 * 2.0;
|
||||
|
||||
for j in 0..numx {
|
||||
let x = if i % 2 == 0 {
|
||||
spacing * j as f32 * 2.0
|
||||
} else {
|
||||
dim.x * j as f32 * 2.0
|
||||
};
|
||||
|
||||
for k in 0..numz {
|
||||
let z = if i % 2 == 0 {
|
||||
dim.z * k as f32 * 2.0
|
||||
} else {
|
||||
spacing * k as f32 * 2.0
|
||||
};
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(
|
||||
x + dim.x + shift.x,
|
||||
y + dim.y + shift.y,
|
||||
z + dim.z + shift.z,
|
||||
));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
|
||||
testbed.set_initial_body_color(handle, color0);
|
||||
std::mem::swap(&mut color0, &mut color1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close the top.
|
||||
let dim = half_extents.zxy();
|
||||
|
||||
for i in 0..(block_width / (dim.x * 2.0)) as usize {
|
||||
for j in 0..(block_width / (dim.z * 2.0)) as usize {
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(
|
||||
i as f32 * dim.x * 2.0 + dim.x + shift.x,
|
||||
dim.y + shift.y + block_height,
|
||||
j as f32 * dim.z * 2.0 + dim.z + shift.z,
|
||||
));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(dim.x, dim.y, dim.z);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
testbed.set_initial_body_color(handle, color0);
|
||||
std::mem::swap(&mut color0, &mut color1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 50.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vec3::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let half_extents = Vec3::new(0.02, 0.1, 0.4) / 2.0 * 10.0;
|
||||
let mut block_height = 0.0;
|
||||
// These should only be set to odd values otherwise
|
||||
// the blocks won't align in the nicest way.
|
||||
let numy = [0, 9, 13, 17, 21, 41];
|
||||
|
||||
for i in (1..=5).rev() {
|
||||
let numx = i;
|
||||
let numy = numy[i];
|
||||
let numz = numx * 3 + 1;
|
||||
let block_width = numx as f32 * half_extents.z * 2.0;
|
||||
build_block(
|
||||
testbed,
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
half_extents,
|
||||
Vec3::new(-block_width / 2.0, block_height, -block_width / 2.0),
|
||||
(numx, numy, numz),
|
||||
);
|
||||
block_height += numy as f32 * half_extents.y * 2.0 + half_extents.x * 2.0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
68
examples3d/stress_tests/many_kinematics3.rs
Normal file
68
examples3d/stress_tests/many_kinematics3.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Create the balls
|
||||
*/
|
||||
let num = 30;
|
||||
let rad = 1.0;
|
||||
|
||||
let shift = rad * 6.0 + 1.0;
|
||||
let centerx = shift * (num as f32) / 2.0;
|
||||
let centery = shift * (num as f32) / 2.0;
|
||||
let centerz = shift * (num as f32) / 2.0;
|
||||
|
||||
for i in 0..num {
|
||||
for j in 0usize..num {
|
||||
for k in 0..num {
|
||||
let x = i as f32 * shift - centerx;
|
||||
let y = j as f32 * shift - centery;
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let velocity = Vec3::new(
|
||||
rand::random::<f32>() - 0.5,
|
||||
rand::random::<f32>() - 0.5,
|
||||
rand::random::<f32>() - 0.5,
|
||||
) * 30.0;
|
||||
let rigid_body = RigidBodyBuilder::new(RigidBodyType::KinematicVelocityBased)
|
||||
.translation(Vec3::new(x, y, z))
|
||||
.linvel(velocity);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testbed.add_callback(move |_, physics, _, _| {
|
||||
for (_, rb) in physics.bodies.iter_mut() {
|
||||
let mut linvel = rb.linvel();
|
||||
|
||||
for dim in 0..3 {
|
||||
if (linvel[dim] > 0.0 && rb.translation()[dim] > (shift * num as f32) / 2.0)
|
||||
|| (linvel[dim] < 0.0 && rb.translation()[dim] < -(shift * num as f32) / 2.0)
|
||||
{
|
||||
linvel[dim] = -linvel[dim];
|
||||
}
|
||||
}
|
||||
|
||||
rb.set_linvel(linvel, false);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
80
examples3d/stress_tests/many_pyramids3.rs
Normal file
80
examples3d/stress_tests/many_pyramids3.rs
Normal file
@@ -0,0 +1,80 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
fn create_pyramid(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vec3,
|
||||
stack_height: usize,
|
||||
rad: f32,
|
||||
) {
|
||||
let shift = rad * 2.0;
|
||||
|
||||
for i in 0usize..stack_height {
|
||||
for j in i..stack_height {
|
||||
let fj = j as f32;
|
||||
let fi = i as f32;
|
||||
let x = (fi * shift / 2.0) + (fj - fi) * shift;
|
||||
let y = fi * shift;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, 0.0) + offset);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
let rad = 0.5;
|
||||
let pyramid_count = 40;
|
||||
let spacing = 4.0;
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 50.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vec3::new(0.0, -ground_height, 0.0));
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(
|
||||
ground_size,
|
||||
ground_height,
|
||||
pyramid_count as f32 * spacing / 2.0 + ground_size,
|
||||
);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
for pyramid_index in 0..pyramid_count {
|
||||
let bottomy = rad;
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vec3::new(
|
||||
0.0,
|
||||
bottomy,
|
||||
(pyramid_index as f32 - pyramid_count as f32 / 2.0) * spacing,
|
||||
),
|
||||
20,
|
||||
rad,
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
54
examples3d/stress_tests/many_sleep3.rs
Normal file
54
examples3d/stress_tests/many_sleep3.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Create the balls
|
||||
*/
|
||||
let num = 50;
|
||||
let rad = 1.0;
|
||||
|
||||
let shift = rad * 2.0 + 1.0;
|
||||
let centerx = shift * (num as f32) / 2.0;
|
||||
let centery = shift / 2.0;
|
||||
let centerz = shift * (num as f32) / 2.0;
|
||||
|
||||
for i in 0..num {
|
||||
for j in 0usize..num {
|
||||
for k in 0..num {
|
||||
let x = i as f32 * shift - centerx;
|
||||
let y = j as f32 * shift + centery;
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
let status = if j == 0 {
|
||||
RigidBodyType::Fixed
|
||||
} else {
|
||||
RigidBodyType::Dynamic
|
||||
};
|
||||
let density = 0.477;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new(status)
|
||||
.translation(Vec3::new(x, y, z))
|
||||
.sleeping(true); // j < num - 1);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).density(density);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
52
examples3d/stress_tests/many_static3.rs
Normal file
52
examples3d/stress_tests/many_static3.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Create the balls
|
||||
*/
|
||||
let num = 50;
|
||||
let rad = 1.0;
|
||||
|
||||
let shift = rad * 2.0 + 1.0;
|
||||
let centerx = shift * (num as f32) / 2.0;
|
||||
let centery = shift / 2.0;
|
||||
let centerz = shift * (num as f32) / 2.0;
|
||||
|
||||
for i in 0..num {
|
||||
for j in 0usize..num {
|
||||
for k in 0..num {
|
||||
let x = i as f32 * shift - centerx;
|
||||
let y = j as f32 * shift + centery;
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
let status = if j < num - 1 {
|
||||
RigidBodyType::Fixed
|
||||
} else {
|
||||
RigidBodyType::Dynamic
|
||||
};
|
||||
let density = 0.477;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::new(status).translation(Vec3::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::ball(rad).density(density);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
53
examples3d/stress_tests/mod.rs
Normal file
53
examples3d/stress_tests/mod.rs
Normal file
@@ -0,0 +1,53 @@
|
||||
use rapier_testbed3d::Example;
|
||||
|
||||
mod balls3;
|
||||
mod boxes3;
|
||||
mod capsules3;
|
||||
mod ccd3;
|
||||
mod compound3;
|
||||
mod convex_polyhedron3;
|
||||
mod heightfield3;
|
||||
mod joint_ball3;
|
||||
mod joint_fixed3;
|
||||
mod joint_prismatic3;
|
||||
mod joint_revolute3;
|
||||
mod keva3;
|
||||
mod many_kinematics3;
|
||||
mod many_pyramids3;
|
||||
mod many_sleep3;
|
||||
mod many_static3;
|
||||
mod pyramid3;
|
||||
mod ray_cast3;
|
||||
mod stacks3;
|
||||
mod trimesh3;
|
||||
|
||||
pub fn builders() -> Vec<Example> {
|
||||
const STRESS: &str = "Stress Tests";
|
||||
|
||||
vec![
|
||||
Example::new(STRESS, "Balls", balls3::init_world),
|
||||
Example::new(STRESS, "Boxes", boxes3::init_world),
|
||||
Example::new(STRESS, "Capsules", capsules3::init_world),
|
||||
Example::new(STRESS, "CCD", ccd3::init_world),
|
||||
Example::new(STRESS, "Compound", compound3::init_world),
|
||||
Example::new(STRESS, "Convex polyhedron", convex_polyhedron3::init_world),
|
||||
Example::new(STRESS, "Many kinematics", many_kinematics3::init_world),
|
||||
Example::new(STRESS, "Many static", many_static3::init_world),
|
||||
Example::new(STRESS, "Many sleep", many_sleep3::init_world),
|
||||
Example::new(STRESS, "Heightfield", heightfield3::init_world),
|
||||
Example::new(STRESS, "Stacks", stacks3::init_world),
|
||||
Example::new(STRESS, "Pyramid", pyramid3::init_world),
|
||||
Example::new(STRESS, "Trimesh", trimesh3::init_world),
|
||||
Example::new(STRESS, "ImpulseJoint ball", joint_ball3::init_world),
|
||||
Example::new(STRESS, "ImpulseJoint fixed", joint_fixed3::init_world),
|
||||
Example::new(STRESS, "ImpulseJoint revolute", joint_revolute3::init_world),
|
||||
Example::new(
|
||||
STRESS,
|
||||
"ImpulseJoint prismatic",
|
||||
joint_prismatic3::init_world,
|
||||
),
|
||||
Example::new(STRESS, "Many pyramids", many_pyramids3::init_world),
|
||||
Example::new(STRESS, "Keva tower", keva3::init_world),
|
||||
Example::new(STRESS, "Ray cast", ray_cast3::init_world),
|
||||
]
|
||||
}
|
||||
75
examples3d/stress_tests/pyramid3.rs
Normal file
75
examples3d/stress_tests/pyramid3.rs
Normal file
@@ -0,0 +1,75 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
fn create_pyramid(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vec3,
|
||||
stack_height: usize,
|
||||
half_extents: Vec3,
|
||||
) {
|
||||
let shift = half_extents * 2.5;
|
||||
for i in 0usize..stack_height {
|
||||
for j in i..stack_height {
|
||||
for k in i..stack_height {
|
||||
let fi = i as f32;
|
||||
let fj = j as f32;
|
||||
let fk = k as f32;
|
||||
let x = (fi * shift.x / 2.0) + (fk - fi) * shift.x + offset.x
|
||||
- stack_height as f32 * half_extents.x;
|
||||
let y = fi * shift.y + offset.y;
|
||||
let z = (fi * shift.z / 2.0) + (fj - fi) * shift.z + offset.z
|
||||
- stack_height as f32 * half_extents.z;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, z));
|
||||
let rigid_body_handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider =
|
||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z);
|
||||
colliders.insert_with_parent(collider, rigid_body_handle, bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 50.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vec3::new(0.0, -ground_height, 0.0));
|
||||
let ground_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let cube_size = 1.0;
|
||||
let hext = Vec3::splat(cube_size);
|
||||
let bottomy = cube_size;
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vec3::new(0.0, bottomy, 0.0),
|
||||
24,
|
||||
hext,
|
||||
);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
82
examples3d/stress_tests/ray_cast3.rs
Normal file
82
examples3d/stress_tests/ray_cast3.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
use crate::{Example, stress_tests};
|
||||
use kiss3d::prelude::*;
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
let settings = testbed.example_settings_mut();
|
||||
|
||||
// NOTE: this demo is a bit special. It takes as a setting the builder of another demo,
|
||||
// builds it, and add a ton of rays into it. This gives us an easy way to check
|
||||
// ray-casting in a wide variety of situations.
|
||||
let demos: Vec<Example> = stress_tests::builders()
|
||||
.into_iter()
|
||||
.filter(|demo| !std::ptr::fn_addr_eq(demo.builder, self::init_world as fn(&mut Testbed)))
|
||||
.collect();
|
||||
let demo_names: Vec<_> = demos.iter().map(|demo| demo.name.to_string()).collect();
|
||||
let selected = settings.get_or_set_string("Scene", 0, demo_names);
|
||||
(demos[selected].builder)(testbed);
|
||||
|
||||
/*
|
||||
* Cast rays at each frame.
|
||||
*/
|
||||
let ray_ball_radius = 100.0;
|
||||
let ray_ball = Ball::new(ray_ball_radius);
|
||||
let (ray_origins, _) = ray_ball.to_trimesh(100, 100);
|
||||
let rays: Vec<_> = ray_origins
|
||||
.into_iter()
|
||||
.map(|pt| Ray::new(pt, -pt.normalize()))
|
||||
.collect();
|
||||
let mut centered_rays = rays.clone();
|
||||
|
||||
testbed.add_callback(move |graphics, physics, _, _| {
|
||||
let Some(graphics) = graphics else {
|
||||
return;
|
||||
};
|
||||
|
||||
// Re-center the ray relative to the current position of all objects.
|
||||
// This ensures demos with falling objects don’t end up with a boring situation
|
||||
// where all the rays point into the void.
|
||||
let mut center = Vec3::ZERO;
|
||||
for (_, b) in physics.bodies.iter() {
|
||||
center += b.translation();
|
||||
}
|
||||
center /= physics.bodies.len() as Real;
|
||||
|
||||
for (centered, ray) in centered_rays.iter_mut().zip(rays.iter()) {
|
||||
centered.origin = center + ray.origin;
|
||||
}
|
||||
|
||||
// Cast the rays.
|
||||
let t1 = std::time::Instant::now();
|
||||
let max_toi = ray_ball_radius - 1.0;
|
||||
|
||||
let query_pipeline = physics.broad_phase.as_query_pipeline(
|
||||
physics.narrow_phase.query_dispatcher(),
|
||||
&physics.bodies,
|
||||
&physics.colliders,
|
||||
Default::default(),
|
||||
);
|
||||
|
||||
for ray in ¢ered_rays {
|
||||
if let Some((_, toi)) = query_pipeline.cast_ray(ray, max_toi, true) {
|
||||
let a = ray.origin;
|
||||
let b = ray.point_at(toi);
|
||||
graphics.window.draw_line(a, b, GREEN, 100.0, true);
|
||||
} else {
|
||||
let a = ray.origin;
|
||||
let b = ray.point_at(max_toi);
|
||||
graphics.window.draw_line(a, b, RED, 100.0, true);
|
||||
}
|
||||
}
|
||||
let main_check_time = t1.elapsed().as_secs_f32();
|
||||
|
||||
if let Some(settings) = &mut graphics.settings {
|
||||
settings.set_label("Ray count:", format!("{}", rays.len()));
|
||||
settings.set_label(
|
||||
"Ray-cast time",
|
||||
format!("{:.2}ms", main_check_time * 1000.0,),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
180
examples3d/stress_tests/stacks3.rs
Normal file
180
examples3d/stress_tests/stacks3.rs
Normal file
@@ -0,0 +1,180 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
fn create_tower_circle(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vec3,
|
||||
stack_height: usize,
|
||||
nsubdivs: usize,
|
||||
half_extents: Vec3,
|
||||
) {
|
||||
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 shift = half_extents * 2.0;
|
||||
for i in 0usize..stack_height {
|
||||
for j in 0..nsubdivs {
|
||||
let fj = j as f32;
|
||||
let fi = i as f32;
|
||||
let y = fi * shift.y;
|
||||
let pos = Pose3::new(offset, Vec3::Y * (fi / 2.0 + fj) * ang_step)
|
||||
.prepend_translation(Vec3::new(0.0, y, radius));
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().pose(pos);
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_wall(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vec3,
|
||||
stack_height: usize,
|
||||
half_extents: Vec3,
|
||||
) {
|
||||
let shift = half_extents * 2.0;
|
||||
for i in 0usize..stack_height {
|
||||
for j in i..stack_height {
|
||||
let fj = j as f32;
|
||||
let fi = i as f32;
|
||||
let x = offset.x;
|
||||
let y = fi * shift.y + offset.y;
|
||||
let z = (fi * shift.z / 2.0) + (fj - fi) * shift.z + offset.z
|
||||
- stack_height as f32 * half_extents.z;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_pyramid(
|
||||
bodies: &mut RigidBodySet,
|
||||
colliders: &mut ColliderSet,
|
||||
offset: Vec3,
|
||||
stack_height: usize,
|
||||
half_extents: Vec3,
|
||||
) {
|
||||
let shift = half_extents * 2.0;
|
||||
|
||||
for i in 0usize..stack_height {
|
||||
for j in i..stack_height {
|
||||
for k in i..stack_height {
|
||||
let fi = i as f32;
|
||||
let fj = j as f32;
|
||||
let fk = k as f32;
|
||||
let x = (fi * shift.x / 2.0) + (fk - fi) * shift.x + offset.x
|
||||
- stack_height as f32 * half_extents.x;
|
||||
let y = fi * shift.y + offset.y;
|
||||
let z = (fi * shift.z / 2.0) + (fj - fi) * shift.z + offset.z
|
||||
- stack_height as f32 * half_extents.z;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider =
|
||||
ColliderBuilder::cuboid(half_extents.x, half_extents.y, half_extents.z);
|
||||
colliders.insert_with_parent(collider, handle, bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = 200.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vec3::new(0.0, -ground_height, 0.0));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let cube_size = 1.0;
|
||||
let hext = Vec3::splat(cube_size);
|
||||
let bottomy = cube_size * 50.0;
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vec3::new(-110.0, bottomy, 0.0),
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vec3::new(-80.0, bottomy, 0.0),
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vec3::new(-50.0, bottomy, 0.0),
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_pyramid(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vec3::new(-20.0, bottomy, 0.0),
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_wall(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vec3::new(-2.0, bottomy, 0.0),
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_wall(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vec3::new(4.0, bottomy, 0.0),
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_wall(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vec3::new(10.0, bottomy, 0.0),
|
||||
12,
|
||||
hext,
|
||||
);
|
||||
create_tower_circle(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
Vec3::new(25.0, bottomy, 0.0),
|
||||
8,
|
||||
24,
|
||||
hext,
|
||||
);
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
82
examples3d/stress_tests/trimesh3.rs
Normal file
82
examples3d/stress_tests/trimesh3.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
use rapier_testbed3d::Testbed;
|
||||
use rapier3d::na::ComplexField;
|
||||
use rapier3d::prelude::*;
|
||||
|
||||
pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* World
|
||||
*/
|
||||
let mut bodies = RigidBodySet::new();
|
||||
let mut colliders = ColliderSet::new();
|
||||
let impulse_joints = ImpulseJointSet::new();
|
||||
let multibody_joints = MultibodyJointSet::new();
|
||||
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = Vec3::new(200.0, 1.0, 200.0);
|
||||
let nsubdivs = 20;
|
||||
|
||||
let heights = Array2::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);
|
||||
|
||||
// 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::fixed();
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::trimesh(vertices, indices).unwrap();
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* Create the cubes
|
||||
*/
|
||||
let num = 8;
|
||||
let rad = 1.0;
|
||||
|
||||
let shift = rad * 2.0 + rad;
|
||||
let centerx = shift * (num / 2) as f32;
|
||||
let centery = shift / 2.0;
|
||||
let centerz = shift * (num / 2) as f32;
|
||||
|
||||
for j in 0usize..47 {
|
||||
for i in 0..num {
|
||||
for k in 0usize..num {
|
||||
let x = i as f32 * shift - centerx;
|
||||
let y = j as f32 * shift + centery + 3.0;
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec3::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
if j % 2 == 0 {
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
} else {
|
||||
let collider = ColliderBuilder::ball(rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
@@ -14,10 +14,10 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Ground
|
||||
*/
|
||||
let ground_size = vector![100.0, 1.0, 100.0];
|
||||
let ground_size = Vector::new(100.0, 1.0, 100.0);
|
||||
let nsubdivs = 20;
|
||||
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
let heights = Array2::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
if i == 0 || i == nsubdivs || j == 0 || j == nsubdivs {
|
||||
10.0
|
||||
} else {
|
||||
@@ -65,7 +65,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let z = k as f32 * shift - centerz;
|
||||
|
||||
// Build the rigid body.
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
|
||||
let collider = match j % 6 {
|
||||
@@ -79,15 +79,15 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
_ => {
|
||||
let shapes = vec![
|
||||
(
|
||||
Isometry::identity(),
|
||||
Pose::IDENTITY,
|
||||
SharedShape::cuboid(rad, rad / 2.0, rad / 2.0),
|
||||
),
|
||||
(
|
||||
Isometry::translation(rad, 0.0, 0.0),
|
||||
Pose::from_translation(Vector::new(rad, 0.0, 0.0)),
|
||||
SharedShape::cuboid(rad / 2.0, rad, rad / 2.0),
|
||||
),
|
||||
(
|
||||
Isometry::translation(-rad, 0.0, 0.0),
|
||||
Pose::from_translation(Vector::new(-rad, 0.0, 0.0)),
|
||||
SharedShape::cuboid(rad / 2.0, rad, rad / 2.0),
|
||||
),
|
||||
];
|
||||
@@ -105,5 +105,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
create_colliders_from_collision_shapes: false,
|
||||
make_roots_fixed: true,
|
||||
// Z-up to Y-up.
|
||||
shift: Isometry::rotation(Vector::x() * std::f32::consts::FRAC_PI_2),
|
||||
shift: Pose::rotation(Vector::X * std::f32::consts::FRAC_PI_2),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@@ -32,7 +32,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
.clone()
|
||||
.insert_using_impulse_joints(&mut bodies, &mut colliders, &mut impulse_joints);
|
||||
// Insert the robot a second time, but using multibody joints this time.
|
||||
robot.append_transform(&Isometry::translation(10.0, 0.0, 0.0));
|
||||
robot.append_transform(&Pose::translation(10.0, 0.0, 0.0));
|
||||
robot.insert_using_multibody_joints(
|
||||
&mut bodies,
|
||||
&mut colliders,
|
||||
@@ -44,5 +44,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![20.0, 20.0, 20.0], point![5.0, 0.0, 0.0]);
|
||||
testbed.look_at(Vec3::new(20.0, 20.0, 20.0), Vec3::new(5.0, 0.0, 0.0));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
use kiss3d::color::Color;
|
||||
use rapier_testbed3d::{
|
||||
KeyCode, PhysicsState, TestbedGraphics,
|
||||
ui::egui::{Align2, ComboBox, Slider, Ui, Window},
|
||||
egui::{Align2, ComboBox, Slider, Ui, Window},
|
||||
};
|
||||
use rapier3d::{
|
||||
control::{CharacterLength, KinematicCharacterController, PidController},
|
||||
math::Vector,
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
@@ -50,36 +52,38 @@ fn character_movement_from_inputs(
|
||||
gfx: &TestbedGraphics,
|
||||
mut speed: Real,
|
||||
artificial_gravity: bool,
|
||||
) -> Vector<Real> {
|
||||
let mut desired_movement = Vector::zeros();
|
||||
) -> Vector {
|
||||
let mut desired_movement = Vector::ZERO;
|
||||
|
||||
let rot = gfx.camera_rotation();
|
||||
let mut rot_x = rot * Vector::x();
|
||||
let mut rot_z = rot * Vector::z();
|
||||
rot_x.y = 0.0;
|
||||
rot_z.y = 0.0;
|
||||
let mut rot_x_na = rot * SimdVector::x();
|
||||
let mut rot_z_na = rot * SimdVector::z();
|
||||
rot_x_na.y = 0.0;
|
||||
rot_z_na.y = 0.0;
|
||||
let rot_x = Vector::new(rot_x_na.x, rot_x_na.y, rot_x_na.z);
|
||||
let rot_z = Vector::new(rot_z_na.x, rot_z_na.y, rot_z_na.z);
|
||||
|
||||
for key in gfx.keys().get_pressed() {
|
||||
match *key {
|
||||
KeyCode::ArrowRight => {
|
||||
KeyCode::Right => {
|
||||
desired_movement += rot_x;
|
||||
}
|
||||
KeyCode::ArrowLeft => {
|
||||
KeyCode::Left => {
|
||||
desired_movement -= rot_x;
|
||||
}
|
||||
KeyCode::ArrowUp => {
|
||||
KeyCode::Up => {
|
||||
desired_movement -= rot_z;
|
||||
}
|
||||
KeyCode::ArrowDown => {
|
||||
KeyCode::Down => {
|
||||
desired_movement += rot_z;
|
||||
}
|
||||
KeyCode::Space => {
|
||||
desired_movement += Vector::y() * 2.0;
|
||||
desired_movement += Vector::Y * 2.0;
|
||||
}
|
||||
KeyCode::ControlRight => {
|
||||
desired_movement -= Vector::y();
|
||||
KeyCode::RControl => {
|
||||
desired_movement -= Vector::Y;
|
||||
}
|
||||
KeyCode::ShiftLeft => {
|
||||
KeyCode::LShift => {
|
||||
speed /= 10.0;
|
||||
}
|
||||
_ => {}
|
||||
@@ -89,7 +93,7 @@ fn character_movement_from_inputs(
|
||||
desired_movement *= speed;
|
||||
|
||||
if artificial_gravity {
|
||||
desired_movement -= Vector::y() * speed;
|
||||
desired_movement -= Vector::Y * speed;
|
||||
}
|
||||
|
||||
desired_movement
|
||||
@@ -107,11 +111,11 @@ fn update_pid_controller(
|
||||
|
||||
// Adjust the controlled axis depending on the keys pressed by the user.
|
||||
// - If the user is jumping, enable control over Y.
|
||||
// - If the user isn’t pressing any key, disable all linear controls to let
|
||||
// - If the user isn't pressing any key, disable all linear controls to let
|
||||
// gravity/collision do their thing freely.
|
||||
let mut axes = AxesMask::ANG_X | AxesMask::ANG_Y | AxesMask::ANG_Z;
|
||||
|
||||
if desired_movement.norm() != 0.0 {
|
||||
if desired_movement.length() != 0.0 {
|
||||
axes |= if desired_movement.y == 0.0 {
|
||||
AxesMask::LIN_X | AxesMask::LIN_Z
|
||||
} else {
|
||||
@@ -121,10 +125,12 @@ fn update_pid_controller(
|
||||
|
||||
pid.set_axes(axes);
|
||||
|
||||
let target_translation = character_body.translation() + desired_movement;
|
||||
let target_pose = Pose::from_parts(target_translation, *character_body.rotation());
|
||||
let corrective_vel = pid.rigid_body_correction(
|
||||
phx.integration_parameters.dt,
|
||||
character_body,
|
||||
(character_body.translation() + desired_movement).into(),
|
||||
target_pose,
|
||||
RigidBodyVelocity::zero(),
|
||||
);
|
||||
let new_vel = *character_body.vels() + corrective_vel;
|
||||
@@ -160,14 +166,14 @@ fn update_kinematic_controller(
|
||||
&query_pipeline.as_ref(),
|
||||
&*character_shape,
|
||||
&character_pose,
|
||||
desired_movement.cast::<Real>(),
|
||||
desired_movement,
|
||||
|c| collisions.push(c),
|
||||
);
|
||||
|
||||
if mvt.grounded {
|
||||
gfx.set_body_color(character_handle, [0.1, 0.8, 0.1]);
|
||||
gfx.set_body_color(character_handle, Color::new(0.1, 0.8, 0.1, 1.0), true);
|
||||
} else {
|
||||
gfx.set_body_color(character_handle, [0.8, 0.1, 0.1]);
|
||||
gfx.set_body_color(character_handle, Color::new(0.8, 0.1, 0.1, 1.0), true);
|
||||
}
|
||||
|
||||
controller.solve_character_collision_impulses(
|
||||
@@ -180,7 +186,7 @@ fn update_kinematic_controller(
|
||||
|
||||
let character_body = &mut phx.bodies[character_handle];
|
||||
let pose = character_body.position();
|
||||
character_body.set_next_kinematic_translation(pose.translation.vector + mvt.translation);
|
||||
character_body.set_next_kinematic_translation(pose.translation + mvt.translation);
|
||||
}
|
||||
|
||||
fn character_control_ui(
|
||||
@@ -191,7 +197,7 @@ fn character_control_ui(
|
||||
) {
|
||||
Window::new("Character Control")
|
||||
.anchor(Align2::RIGHT_TOP, [-15.0, 15.0])
|
||||
.show(gfx.ui_context_mut().ctx_mut(), |ui| {
|
||||
.show(gfx.egui_context(), |ui| {
|
||||
ComboBox::from_label("control mode")
|
||||
.selected_text(format!("{:?}", *control_mode))
|
||||
.show_ui(ui, |ui| {
|
||||
@@ -230,12 +236,12 @@ fn pid_control_ui(ui: &mut Ui, pid_controller: &mut PidController, speed: &mut R
|
||||
ui.add(Slider::new(&mut ang_ki, 0.0..=10.0).text("angular Ki"));
|
||||
ui.add(Slider::new(&mut ang_kd, 0.0..=1.0).text("angular Kd"));
|
||||
|
||||
pid_controller.pd.lin_kp.fill(lin_kp);
|
||||
pid_controller.lin_ki.fill(lin_ki);
|
||||
pid_controller.pd.lin_kd.fill(lin_kd);
|
||||
pid_controller.pd.ang_kp.fill(ang_kp);
|
||||
pid_controller.ang_ki.fill(ang_ki);
|
||||
pid_controller.pd.ang_kd.fill(ang_kd);
|
||||
pid_controller.pd.lin_kp = Vector::splat(lin_kp);
|
||||
pid_controller.lin_ki = Vector::splat(lin_ki);
|
||||
pid_controller.pd.lin_kd = Vector::splat(lin_kd);
|
||||
pid_controller.pd.ang_kp = Vector::splat(ang_kp);
|
||||
pid_controller.ang_ki = Vector::splat(ang_ki);
|
||||
pid_controller.pd.ang_kd = Vector::splat(ang_kd);
|
||||
}
|
||||
|
||||
fn kinematic_control_ui(
|
||||
@@ -250,12 +256,12 @@ fn kinematic_control_ui(
|
||||
#[allow(clippy::useless_conversion)]
|
||||
{
|
||||
ui.add(Slider::new(&mut character_controller.max_slope_climb_angle, 0.0..=std::f32::consts::TAU.into()).text("max_slope_climb_angle"))
|
||||
.on_hover_text("The maximum angle (radians) between the floor’s normal and the `up` vector that the character is able to climb.");
|
||||
.on_hover_text("The maximum angle (radians) between the floor's normal and the `up` vector that the character is able to climb.");
|
||||
ui.add(Slider::new(&mut character_controller.min_slope_slide_angle, 0.0..=std::f32::consts::FRAC_PI_2.into()).text("min_slope_slide_angle"))
|
||||
.on_hover_text("The minimum angle (radians) between the floor’s normal and the `up` vector before the character starts to slide down automatically.");
|
||||
.on_hover_text("The minimum angle (radians) between the floor's normal and the `up` vector before the character starts to slide down automatically.");
|
||||
}
|
||||
let mut is_snapped = character_controller.snap_to_ground.is_some();
|
||||
if ui.checkbox(&mut is_snapped, "snap_to_ground").changed {
|
||||
if ui.checkbox(&mut is_snapped, "snap_to_ground").changed() {
|
||||
match is_snapped {
|
||||
true => {
|
||||
character_controller.snap_to_ground = Some(CharacterLength::Relative(0.1));
|
||||
|
||||
@@ -17,7 +17,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = 5.0;
|
||||
let ground_height = 0.1;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height, 0.0));
|
||||
let floor_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
|
||||
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
|
||||
@@ -27,7 +27,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
*/
|
||||
let hw = 0.3;
|
||||
let hh = 0.15;
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, 1.0, 0.0]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 1.0, 0.0));
|
||||
let vehicle_handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(hw * 2.0, hh, hw).density(100.0);
|
||||
colliders.insert_with_parent(collider, vehicle_handle, &mut bodies);
|
||||
@@ -39,14 +39,14 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
};
|
||||
let mut vehicle = DynamicRayCastVehicleController::new(vehicle_handle);
|
||||
let wheel_positions = [
|
||||
point![hw * 1.5, -hh, hw],
|
||||
point![hw * 1.5, -hh, -hw],
|
||||
point![-hw * 1.5, -hh, hw],
|
||||
point![-hw * 1.5, -hh, -hw],
|
||||
Vector::new(hw * 1.5, -hh, hw),
|
||||
Vector::new(hw * 1.5, -hh, -hw),
|
||||
Vector::new(-hw * 1.5, -hh, hw),
|
||||
Vector::new(-hw * 1.5, -hh, -hw),
|
||||
];
|
||||
|
||||
for pos in wheel_positions {
|
||||
vehicle.add_wheel(pos, -Vector::y(), Vector::z(), hh, hh / 4.0, &tuning);
|
||||
vehicle.add_wheel(pos, -Vector::Y, Vector::Z, hh, hh / 4.0, &tuning);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -66,7 +66,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = j as f32 * shift + centery;
|
||||
let z = k as f32 * shift + centerx;
|
||||
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(rigid_body);
|
||||
let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -80,8 +80,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let slope_angle = 0.2;
|
||||
let slope_size = 2.0;
|
||||
let collider = ColliderBuilder::cuboid(slope_size, ground_height, ground_size)
|
||||
.translation(vector![ground_size + slope_size, -ground_height + 0.4, 0.0])
|
||||
.rotation(Vector::z() * slope_angle);
|
||||
.translation(Vector::new(
|
||||
ground_size + slope_size,
|
||||
-ground_height + 0.4,
|
||||
0.0,
|
||||
))
|
||||
.rotation(Vector::Z * slope_angle);
|
||||
colliders.insert(collider);
|
||||
|
||||
/*
|
||||
@@ -90,73 +94,33 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let impossible_slope_angle = 0.9;
|
||||
let impossible_slope_size = 2.0;
|
||||
let collider = ColliderBuilder::cuboid(slope_size, ground_height, ground_size)
|
||||
.translation(vector![
|
||||
.translation(Vector::new(
|
||||
ground_size + slope_size * 2.0 + impossible_slope_size - 0.9,
|
||||
-ground_height + 2.3,
|
||||
0.0
|
||||
])
|
||||
.rotation(Vector::z() * impossible_slope_angle);
|
||||
0.0,
|
||||
))
|
||||
.rotation(Vector::Z * impossible_slope_angle);
|
||||
colliders.insert(collider);
|
||||
|
||||
// /*
|
||||
// * Create a moving platform.
|
||||
// */
|
||||
// let body = RigidBodyBuilder::kinematic_velocity_based().translation(vector![-8.0, 1.5, 0.0]);
|
||||
// // .rotation(-0.3);
|
||||
// let platform_handle = bodies.insert(body);
|
||||
// let collider = ColliderBuilder::cuboid(2.0, ground_height, 2.0);
|
||||
// colliders.insert_with_parent(collider, platform_handle, &mut bodies);
|
||||
|
||||
/*
|
||||
* More complex ground.
|
||||
*/
|
||||
let ground_size = Vector::new(10.0, 0.4, 10.0);
|
||||
let nsubdivs = 20;
|
||||
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
let heights = Array2::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
-(i as f32 * ground_size.x / (nsubdivs as f32) / 2.0).cos()
|
||||
- (j as f32 * ground_size.z / (nsubdivs as f32) / 2.0).cos()
|
||||
});
|
||||
|
||||
let collider =
|
||||
ColliderBuilder::heightfield(heights, ground_size).translation(vector![-7.0, 0.0, 0.0]);
|
||||
ColliderBuilder::heightfield(heights, ground_size).translation(Vector::new(-7.0, 0.0, 0.0));
|
||||
colliders.insert(collider);
|
||||
|
||||
// /*
|
||||
// * A tilting dynamic body with a limited joint.
|
||||
// */
|
||||
// let ground = RigidBodyBuilder::fixed().translation(vector![0.0, 5.0, 0.0]);
|
||||
// let ground_handle = bodies.insert(ground);
|
||||
// let body = RigidBodyBuilder::dynamic().translation(vector![0.0, 5.0, 0.0]);
|
||||
// let handle = bodies.insert(body);
|
||||
// let collider = ColliderBuilder::cuboid(1.0, 0.1, 2.0);
|
||||
// colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
// let joint = RevoluteJointBuilder::new(Vector::z_axis()).limits([-0.3, 0.3]);
|
||||
// impulse_joints.insert(ground_handle, handle, joint, true);
|
||||
|
||||
// /*
|
||||
// * Setup a callback to move the platform.
|
||||
// */
|
||||
// testbed.add_callback(move |_, physics, _, run_state| {
|
||||
// let linvel = vector![
|
||||
// (run_state.time * 2.0).sin() * 2.0,
|
||||
// (run_state.time * 5.0).sin() * 1.5,
|
||||
// 0.0
|
||||
// ];
|
||||
// // let angvel = run_state.time.sin() * 0.5;
|
||||
//
|
||||
// // Update the velocity-based kinematic body by setting its velocity.
|
||||
// if let Some(platform) = physics.bodies.get_mut(platform_handle) {
|
||||
// platform.set_linvel(linvel, true);
|
||||
// // NOTE: interaction with rotating platforms isn’t handled very well yet.
|
||||
// // platform.set_angvel(angvel, true);
|
||||
// }
|
||||
// });
|
||||
|
||||
/*
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.set_vehicle_controller(vehicle);
|
||||
testbed.look_at(point!(10.0, 10.0, 10.0), Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let ground_size = Vector::new(60.0, 0.4, 60.0);
|
||||
let nsubdivs = 100;
|
||||
|
||||
let heights = DMatrix::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
let heights = Array2::from_fn(nsubdivs + 1, nsubdivs + 1, |i, j| {
|
||||
-(i as f32 * ground_size.x / (nsubdivs as f32) / 2.0).cos()
|
||||
- (j as f32 * ground_size.z / (nsubdivs as f32) / 2.0).cos()
|
||||
});
|
||||
|
||||
let collider = ColliderBuilder::heightfield(heights, ground_size)
|
||||
.translation(vector![-7.0, 0.0, 0.0])
|
||||
.translation(Vector::new(-7.0, 0.0, 0.0))
|
||||
.friction(1.0);
|
||||
colliders.insert(collider);
|
||||
|
||||
@@ -33,10 +33,10 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
const CAR_GROUP: Group = Group::GROUP_1;
|
||||
|
||||
let wheel_params = [
|
||||
vector![0.6874, 0.2783, -0.7802],
|
||||
vector![-0.6874, 0.2783, -0.7802],
|
||||
vector![0.64, 0.2783, 1.0254],
|
||||
vector![-0.64, 0.2783, 1.0254],
|
||||
Vector::new(0.6874, 0.2783, -0.7802),
|
||||
Vector::new(-0.6874, 0.2783, -0.7802),
|
||||
Vector::new(0.64, 0.2783, 1.0254),
|
||||
Vector::new(-0.64, 0.2783, 1.0254),
|
||||
];
|
||||
// TODO: lower center of mass?
|
||||
// let mut center_of_mass = wheel_params.iter().sum().unwrap() / 4.0;
|
||||
@@ -46,8 +46,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let max_steering_angle = 35.0f32.to_radians();
|
||||
let drive_strength = 1.0;
|
||||
let wheel_radius = 0.28;
|
||||
let car_position = point![0.0, wheel_radius + suspension_height, 0.0];
|
||||
let body_position_in_car_space = vector![0.0, 0.4739, 0.0];
|
||||
let car_position = Vector::new(0.0, wheel_radius + suspension_height, 0.0);
|
||||
let body_position_in_car_space = Vector::new(0.0, 0.4739, 0.0);
|
||||
|
||||
let body_position = car_position + body_position_in_car_space;
|
||||
|
||||
@@ -59,7 +59,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
InteractionTestMode::And,
|
||||
));
|
||||
let body_rb = RigidBodyBuilder::dynamic()
|
||||
.pose(body_position.into())
|
||||
.translation(body_position)
|
||||
.build();
|
||||
let body_handle = bodies.insert(body_rb);
|
||||
colliders.insert_with_parent(body_co, body_handle, &mut bodies);
|
||||
@@ -69,18 +69,18 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
for (wheel_id, wheel_pos_in_car_space) in wheel_params.into_iter().enumerate() {
|
||||
let is_front = wheel_id >= 2;
|
||||
let wheel_center = car_position + wheel_pos_in_car_space;
|
||||
let wheel_center: Vector = car_position + wheel_pos_in_car_space;
|
||||
|
||||
let axle_mass_props = MassProperties::from_ball(100.0, wheel_radius);
|
||||
let axle_rb = RigidBodyBuilder::dynamic()
|
||||
.pose(wheel_center.into())
|
||||
.translation(wheel_center)
|
||||
.additional_mass_properties(axle_mass_props);
|
||||
let axle_handle = bodies.insert(axle_rb);
|
||||
|
||||
// This is a fake cylinder collider that we add only because our testbed can
|
||||
// only render colliders. Setting it as sensor makes it show up as wireframe.
|
||||
let wheel_fake_co = ColliderBuilder::cylinder(wheel_radius / 2.0, wheel_radius)
|
||||
.rotation(Vector::z() * std::f32::consts::FRAC_PI_2)
|
||||
.rotation(Vector::Z * std::f32::consts::FRAC_PI_2)
|
||||
.sensor(true)
|
||||
.density(0.0)
|
||||
.collision_groups(InteractionGroups::none());
|
||||
@@ -95,7 +95,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
InteractionTestMode::And,
|
||||
))
|
||||
.friction(1.0);
|
||||
let wheel_rb = RigidBodyBuilder::dynamic().pose(wheel_center.into());
|
||||
let wheel_rb = RigidBodyBuilder::dynamic().translation(wheel_center);
|
||||
let wheel_handle = bodies.insert(wheel_rb);
|
||||
colliders.insert_with_parent(wheel_co, wheel_handle, &mut bodies);
|
||||
colliders.insert_with_parent(wheel_fake_co, wheel_handle, &mut bodies);
|
||||
@@ -115,7 +115,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let mut suspension_joint = GenericJointBuilder::new(locked_axes)
|
||||
.limits(JointAxis::LinY, [0.0, suspension_height])
|
||||
.motor_position(JointAxis::LinY, 0.0, 1.0e4, 1.0e3)
|
||||
.local_anchor1(suspension_attachment_in_body_space.into());
|
||||
.local_anchor1(suspension_attachment_in_body_space);
|
||||
|
||||
if is_front {
|
||||
suspension_joint =
|
||||
@@ -126,7 +126,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
impulse_joints.insert(body_handle, axle_handle, suspension_joint, true);
|
||||
|
||||
// Joint between the axle and the wheel.
|
||||
let wheel_joint = RevoluteJointBuilder::new(Vector::x_axis());
|
||||
let wheel_joint = RevoluteJointBuilder::new(Vector::X);
|
||||
let wheel_joint_handle =
|
||||
impulse_joints.insert(axle_handle, wheel_handle, wheel_joint, true);
|
||||
|
||||
@@ -148,19 +148,19 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
|
||||
for key in gfx.keys().get_pressed() {
|
||||
match *key {
|
||||
KeyCode::ArrowRight => {
|
||||
KeyCode::Right => {
|
||||
steering = -1.0;
|
||||
}
|
||||
KeyCode::ArrowLeft => {
|
||||
KeyCode::Left => {
|
||||
steering = 1.0;
|
||||
}
|
||||
KeyCode::ArrowUp => {
|
||||
KeyCode::Up => {
|
||||
thrust = -drive_strength;
|
||||
}
|
||||
KeyCode::ArrowDown => {
|
||||
KeyCode::Down => {
|
||||
thrust = drive_strength;
|
||||
}
|
||||
KeyCode::ShiftRight => {
|
||||
KeyCode::RShift => {
|
||||
boost = 1.5;
|
||||
}
|
||||
_ => {}
|
||||
@@ -227,7 +227,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
// let y = j as f32 * shift + centery;
|
||||
// let z = k as f32 * shift + centerx;
|
||||
//
|
||||
// let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y, z]);
|
||||
// let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y, z));
|
||||
// let handle = bodies.insert(rigid_body);
|
||||
// let collider = ColliderBuilder::cuboid(rad, rad, rad);
|
||||
// colliders.insert_with_parent(collider, handle, &mut bodies);
|
||||
@@ -239,5 +239,5 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point!(10.0, 10.0, 10.0), Point::origin());
|
||||
testbed.look_at(Vec3::new(10.0, 10.0, 10.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use kiss3d::color::Color;
|
||||
use obj::raw::object::Polygon;
|
||||
use rapier_testbed3d::KeyCode;
|
||||
use rapier_testbed3d::Testbed;
|
||||
@@ -57,7 +58,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let shift = 7.0f32;
|
||||
|
||||
for (igeom, obj_path) in geoms.into_iter().enumerate() {
|
||||
let deltas = Isometry::identity();
|
||||
let deltas = Pose::IDENTITY;
|
||||
|
||||
let mut shapes = Vec::new();
|
||||
println!("Parsing and decomposing: {obj_path}");
|
||||
@@ -65,10 +66,10 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let input = BufReader::new(File::open(obj_path).unwrap());
|
||||
|
||||
if let Ok(model) = obj::raw::parse_obj(input) {
|
||||
let mut vertices: Vec<_> = model
|
||||
let mut vertices: Vec<Vector> = model
|
||||
.positions
|
||||
.iter()
|
||||
.map(|v| point![v.0, v.1, v.2])
|
||||
.map(|v| Vector::new(v.0, v.1, v.2))
|
||||
.collect();
|
||||
let indices: Vec<_> = model
|
||||
.polygons
|
||||
@@ -91,11 +92,12 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let aabb =
|
||||
bounding_volume::details::point_cloud_aabb(&deltas, vertices.iter().copied());
|
||||
let center = aabb.center();
|
||||
let diag = (aabb.maxs - aabb.mins).norm();
|
||||
let center_v = Vector::new(center.x, center.y, center.z);
|
||||
let diag = (aabb.maxs - aabb.mins).length();
|
||||
|
||||
vertices
|
||||
.iter_mut()
|
||||
.for_each(|p| *p = (*p - center.coords) * 6.0 / diag);
|
||||
.for_each(|p| *p = (*p - center_v) * 6.0 / diag);
|
||||
|
||||
let indices: Vec<_> = indices
|
||||
.chunks(3)
|
||||
@@ -112,7 +114,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let y = (igeom / width) as f32 * shift + 4.0;
|
||||
let z = k as f32 * shift - 3.0;
|
||||
|
||||
let body = RigidBodyBuilder::fixed().translation(vector![x, y, z]);
|
||||
let body = RigidBodyBuilder::fixed().translation(Vector::new(x, y, z));
|
||||
let handle = bodies.insert(body);
|
||||
|
||||
for shape in &shapes {
|
||||
@@ -127,7 +129,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
/*
|
||||
* Create a voxelized wavy floor.
|
||||
*/
|
||||
let mut samples = vec![];
|
||||
let mut samples: Vec<Vector> = vec![];
|
||||
let n = 200;
|
||||
for i in 0..n {
|
||||
for j in 0..n {
|
||||
@@ -135,12 +137,16 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* (j as f32 / n as f32 * 10.0).cos().clamp(-0.8, 0.8)
|
||||
* 16.0;
|
||||
|
||||
samples.push(point![i as f32, y * voxel_size_y, j as f32]);
|
||||
samples.push(Vector::new(i as f32, y * voxel_size_y, j as f32));
|
||||
|
||||
if i == 0 || i == n - 1 || j == 0 || j == n - 1 {
|
||||
// Create walls so the object at the edge don’t fall into the infinite void.
|
||||
// Create walls so the object at the edge don't fall into the infinite void.
|
||||
for k in 0..4 {
|
||||
samples.push(point![i as f32, (y + k as f32) * voxel_size_y, j as f32]);
|
||||
samples.push(Vector::new(
|
||||
i as f32,
|
||||
(y + k as f32) * voxel_size_y,
|
||||
j as f32,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,13 +165,13 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
for i in 0..nik {
|
||||
for j in 0..5 {
|
||||
for k in 0..nik {
|
||||
let mut rb = RigidBodyBuilder::dynamic().translation(vector![
|
||||
let mut rb = RigidBodyBuilder::dynamic().translation(Vector::new(
|
||||
floor_aabb.mins.x + margin.x + i as f32 * extents.x / nik as f32,
|
||||
floor_aabb.maxs.y + j as f32 * 2.0,
|
||||
floor_aabb.mins.z + margin.z + k as f32 * extents.z / nik as f32,
|
||||
]);
|
||||
));
|
||||
if test_ccd {
|
||||
rb = rb.linvel(vector![0.0, -1000.0, 0.0]).ccd_enabled(true);
|
||||
rb = rb.linvel(Vector::new(0.0, -1000.0, 0.0)).ccd_enabled(true);
|
||||
}
|
||||
let rb_handle = bodies.insert(rb);
|
||||
|
||||
@@ -197,8 +203,8 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let hit_highlight_handle = colliders.insert(
|
||||
ColliderBuilder::cuboid(0.51, 0.51, 0.51).collision_groups(InteractionGroups::none()),
|
||||
);
|
||||
testbed.set_initial_collider_color(hit_indicator_handle, [0.5, 0.5, 0.1]);
|
||||
testbed.set_initial_collider_color(hit_highlight_handle, [0.1, 0.5, 0.1]);
|
||||
testbed.set_initial_collider_color(hit_indicator_handle, Color::new(0.5, 0.5, 0.1, 1.0));
|
||||
testbed.set_initial_collider_color(hit_highlight_handle, Color::new(0.1, 0.5, 0.1, 1.0));
|
||||
|
||||
testbed.add_callback(move |graphics, physics, _, _| {
|
||||
let Some(graphics) = graphics else { return };
|
||||
@@ -206,7 +212,10 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
return;
|
||||
};
|
||||
|
||||
let ray = Ray::new(mouse_orig, mouse_dir);
|
||||
let ray = Ray::new(
|
||||
Vector::new(mouse_orig.x, mouse_orig.y, mouse_orig.z),
|
||||
Vector::new(mouse_dir.x, mouse_dir.y, mouse_dir.z),
|
||||
);
|
||||
let filter = QueryFilter {
|
||||
predicate: Some(&|_, co: &Collider| co.shape().as_voxels().is_some()),
|
||||
..Default::default()
|
||||
@@ -221,35 +230,35 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
if let Some((handle, hit)) = query_pipeline.cast_ray_and_get_normal(&ray, Real::MAX, true) {
|
||||
// Highlight the voxel.
|
||||
let hit_collider = &physics.colliders[handle];
|
||||
let hit_local_normal = hit_collider
|
||||
.position()
|
||||
.inverse_transform_vector(&hit.normal);
|
||||
let hit_pos = hit_collider.position();
|
||||
let hit_local_normal = hit_pos.rotation.inverse() * hit.normal;
|
||||
let voxels = hit_collider.shape().as_voxels().unwrap();
|
||||
let FeatureId::Face(id) = hit.feature else {
|
||||
unreachable!()
|
||||
};
|
||||
let voxel_key = voxels.voxel_at_flat_id(id).unwrap();
|
||||
let voxel_center = hit_collider.position() * voxels.voxel_center(voxel_key);
|
||||
let voxel_center_local = voxels.voxel_center(voxel_key);
|
||||
let voxel_center = hit_pos.rotation * voxel_center_local + hit_pos.translation;
|
||||
let voxel_size = voxels.voxel_size();
|
||||
let hit_highlight = physics.colliders.get_mut(hit_highlight_handle).unwrap();
|
||||
hit_highlight.set_translation(voxel_center.coords);
|
||||
hit_highlight.set_translation(voxel_center);
|
||||
hit_highlight
|
||||
.shape_mut()
|
||||
.as_cuboid_mut()
|
||||
.unwrap()
|
||||
.half_extents = voxel_size / 2.0 + Vector::repeat(0.001);
|
||||
.half_extents = voxel_size / 2.0 + Vector::splat(0.001);
|
||||
graphics.update_collider(hit_highlight_handle, &physics.colliders);
|
||||
|
||||
// Show the hit point.
|
||||
let hit_pt = ray.point_at(hit.time_of_impact);
|
||||
let hit_indicator = physics.colliders.get_mut(hit_indicator_handle).unwrap();
|
||||
hit_indicator.set_translation(hit_pt.coords);
|
||||
hit_indicator.shape_mut().as_ball_mut().unwrap().radius = voxel_size.norm() / 3.5;
|
||||
hit_indicator.set_translation(hit_pt);
|
||||
hit_indicator.shape_mut().as_ball_mut().unwrap().radius = voxel_size.length() / 3.5;
|
||||
graphics.update_collider(hit_indicator_handle, &physics.colliders);
|
||||
|
||||
// If a relevant key was pressed, edit the shape.
|
||||
if graphics.keys().pressed(KeyCode::Space) {
|
||||
let removal_mode = graphics.keys().pressed(KeyCode::ShiftLeft);
|
||||
let removal_mode = graphics.keys().pressed(KeyCode::LShift);
|
||||
let voxels = physics
|
||||
.colliders
|
||||
.get_mut(handle)
|
||||
@@ -260,8 +269,17 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
let mut affected_key = voxel_key;
|
||||
|
||||
if !removal_mode {
|
||||
let imax = hit_local_normal.iamax();
|
||||
if hit_local_normal[imax] >= 0.0 {
|
||||
// Find index of max absolute value component
|
||||
let abs_normal = hit_local_normal.abs();
|
||||
let imax = if abs_normal.x >= abs_normal.y && abs_normal.x >= abs_normal.z {
|
||||
0
|
||||
} else if abs_normal.y >= abs_normal.z {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
};
|
||||
let normal_arr = [hit_local_normal.x, hit_local_normal.y, hit_local_normal.z];
|
||||
if normal_arr[imax] >= 0.0 {
|
||||
affected_key[imax] += 1;
|
||||
} else {
|
||||
affected_key[imax] -= 1;
|
||||
@@ -274,10 +292,11 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
} else {
|
||||
// When there is no hit, move the indicators behind the camera.
|
||||
let behind_camera = mouse_orig - mouse_dir * 1000.0;
|
||||
let behind_camera_vect = Vector::new(behind_camera.x, behind_camera.y, behind_camera.z);
|
||||
let hit_indicator = physics.colliders.get_mut(hit_indicator_handle).unwrap();
|
||||
hit_indicator.set_translation(behind_camera.coords);
|
||||
hit_indicator.set_translation(behind_camera_vect);
|
||||
let hit_highlight = physics.colliders.get_mut(hit_highlight_handle).unwrap();
|
||||
hit_highlight.set_translation(behind_camera.coords);
|
||||
hit_highlight.set_translation(behind_camera_vect);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -285,7 +304,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
||||
* Set up the testbed.
|
||||
*/
|
||||
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
|
||||
testbed.look_at(point![100.0, 100.0, 100.0], Point::origin());
|
||||
testbed.look_at(Vec3::new(100.0, 100.0, 100.0), Vec3::ZERO);
|
||||
}
|
||||
|
||||
fn models() -> Vec<String> {
|
||||
|
||||
Reference in New Issue
Block a user