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:
Sébastien Crozet
2026-01-09 17:26:36 +01:00
committed by GitHub
parent 48de83817e
commit 0b7c3b34ec
265 changed files with 8501 additions and 8575 deletions

View File

@@ -15,12 +15,15 @@ enhanced-determinism = ["rapier2d/enhanced-determinism"]
[dependencies]
rand = "0.9"
lyon = "0.17"
usvg = "0.14"
dot_vox = "5"
kiss3d = { version = "0.40.0", features = ["egui", "parry", "serde"] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
usvg = "0.14"
[dependencies.rapier_testbed2d]
path = "../crates/rapier_testbed2d"
features = ["profiler_ui"]
#features = ["profiler_ui"]
[dependencies.rapier2d]
path = "../crates/rapier2d"

View File

@@ -1,5 +1,5 @@
use rapier_testbed2d::Testbed;
use rapier2d::{na::UnitComplex, prelude::*};
use rapier2d::prelude::*;
pub fn init_world(testbed: &mut Testbed) {
let mut bodies = RigidBodySet::new();
@@ -9,7 +9,7 @@ pub fn init_world(testbed: &mut Testbed) {
let rad = 0.5;
let positions = [vector![5.0, -1.0], vector![-5.0, -1.0]];
let positions = [Vector::new(5.0, -1.0), Vector::new(-5.0, -1.0)];
let platform_handles = positions
.into_iter()
@@ -27,13 +27,13 @@ pub fn init_world(testbed: &mut Testbed) {
let rot = -state.time;
for rb_handle in &platform_handles {
let rb = physics.bodies.get_mut(*rb_handle).unwrap();
rb.set_next_kinematic_rotation(UnitComplex::new(rot));
rb.set_next_kinematic_rotation(Rotation::new(rot));
}
if state.timestep_id % 10 == 0 {
let x = rand::random::<f32>() * 10.0 - 5.0;
let y = rand::random::<f32>() * 10.0 + 10.0;
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = physics.bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
physics
@@ -48,7 +48,7 @@ pub fn init_world(testbed: &mut Testbed) {
let to_remove: Vec<_> = physics
.bodies
.iter()
.filter(|(_, b)| b.position().translation.vector.y < -10.0)
.filter(|(_, b)| b.position().translation.y < -10.0)
.map(|e| e.0)
.collect();
for handle in to_remove {
@@ -71,5 +71,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.0], 20.0);
testbed.look_at(Vec2::ZERO, 20.0);
}

View File

@@ -1,11 +1,7 @@
#![allow(dead_code)]
#![allow(clippy::type_complexity)]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
use rapier_testbed2d::{Testbed, TestbedApp};
use std::cmp::Ordering;
use rapier_testbed2d::{Example, TestbedApp};
mod add_remove2;
mod ccd2;
@@ -44,66 +40,94 @@ mod s2d_high_mass_ratio_3;
mod s2d_joint_grid;
mod s2d_pyramid;
mod sensor2;
mod stress_tests;
#[cfg(not(target_arch = "wasm32"))]
mod trimesh2;
mod voxels2;
mod utils;
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub fn main() {
let mut builders: Vec<(_, fn(&mut Testbed))> = vec![
("Add remove", add_remove2::init_world),
("CCD", ccd2::init_world),
("Character controller", character_controller2::init_world),
("Collision groups", collision_groups2::init_world),
("Convex polygons", convex_polygons2::init_world),
("Damping", damping2::init_world),
("Drum", drum2::init_world),
("Heightfield", heightfield2::init_world),
("Inverse kinematics", inverse_kinematics2::init_world),
("Inv pyramid", inv_pyramid2::init_world),
("Joints", joints2::init_world),
("Locked rotations", locked_rotations2::init_world),
("One-way platforms", one_way_platforms2::init_world),
("Platform", platform2::init_world),
("Polyline", polyline2::init_world),
("Pin Slot Joint", pin_slot_joint2::init_world),
("Pyramid", pyramid2::init_world),
("Restitution", restitution2::init_world),
("Rope Joints", rope_joints2::init_world),
("Sensor", sensor2::init_world),
("Trimesh", trimesh2::init_world),
("Voxels", voxels2::init_world),
("Joint motor position", joint_motor_position2::init_world),
("(Debug) box ball", debug_box_ball2::init_world),
("(Debug) compression", debug_compression2::init_world),
("(Debug) intersection", debug_intersection2::init_world),
("(Debug) total overlap", debug_total_overlap2::init_world),
(
"(Debug) vertical column",
debug_vertical_column2::init_world,
),
("(s2d) high mass ratio 1", s2d_high_mass_ratio_1::init_world),
("(s2d) high mass ratio 2", s2d_high_mass_ratio_2::init_world),
("(s2d) high mass ratio 3", s2d_high_mass_ratio_3::init_world),
("(s2d) confined", s2d_confined::init_world),
("(s2d) pyramid", s2d_pyramid::init_world),
("(s2d) card house", s2d_card_house::init_world),
("(s2d) arch", s2d_arch::init_world),
("(s2d) bridge", s2d_bridge::init_world),
("(s2d) ball and chain", s2d_ball_and_chain::init_world),
("(s2d) joint grid", s2d_joint_grid::init_world),
("(s2d) far pyramid", s2d_far_pyramid::init_world),
];
#[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 S2D: &str = "Inspired by Solver 2D";
// 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 builders: Vec<Example> = vec![
// ── Demos ──────────────────────────────────────────────────────────
Example::new(COLLISIONS, "Add remove", add_remove2::init_world),
Example::new(COLLISIONS, "Drum", drum2::init_world),
Example::new(COLLISIONS, "Inv pyramid", inv_pyramid2::init_world),
Example::new(COLLISIONS, "Platform", platform2::init_world),
Example::new(COLLISIONS, "Pyramid", pyramid2::init_world),
Example::new(COLLISIONS, "Sensor", sensor2::init_world),
Example::new(COLLISIONS, "Convex polygons", convex_polygons2::init_world),
Example::new(COLLISIONS, "Heightfield", heightfield2::init_world),
Example::new(COLLISIONS, "Polyline", polyline2::init_world),
#[cfg(not(target_arch = "wasm32"))]
Example::new(COLLISIONS, "Trimesh", trimesh2::init_world),
Example::new(COLLISIONS, "Voxels", voxels2::init_world),
Example::new(
COLLISIONS,
"Collision groups",
collision_groups2::init_world,
),
Example::new(
COLLISIONS,
"One-way platforms",
one_way_platforms2::init_world,
),
// ── Dynamics ──────────────────────────────────────────────────────────
Example::new(DYNAMICS, "Locked rotations", locked_rotations2::init_world),
Example::new(DYNAMICS, "Restitution", restitution2::init_world),
Example::new(DYNAMICS, "Damping", damping2::init_world),
Example::new(DYNAMICS, "CCD", ccd2::init_world),
// ── Joints ─────────────────────────────────────────────────────────
Example::new(JOINTS, "Joints", joints2::init_world),
Example::new(JOINTS, "Rope Joints", rope_joints2::init_world),
Example::new(JOINTS, "Pin Slot Joint", pin_slot_joint2::init_world),
Example::new(
JOINTS,
"Joint motor position",
joint_motor_position2::init_world,
),
Example::new(
JOINTS,
"Inverse kinematics",
inverse_kinematics2::init_world,
),
// ── Characters ─────────────────────────────────────────────────────
Example::new(
CONTROLS,
"Character controller",
character_controller2::init_world,
),
// ── Debug ──────────────────────────────────────────────────────────
Example::new(DEBUG, "Box ball", debug_box_ball2::init_world),
Example::new(DEBUG, "Compression", debug_compression2::init_world),
Example::new(DEBUG, "Intersection", debug_intersection2::init_world),
Example::new(DEBUG, "Total overlap", debug_total_overlap2::init_world),
Example::new(DEBUG, "Vertical column", debug_vertical_column2::init_world),
// ── Demos inspired by Solver2D ───────────────────────────────────────────────────
Example::new(S2D, "High mass ratio 1", s2d_high_mass_ratio_1::init_world),
Example::new(S2D, "High mass ratio 2", s2d_high_mass_ratio_2::init_world),
Example::new(S2D, "High mass ratio 3", s2d_high_mass_ratio_3::init_world),
Example::new(S2D, "Confined", s2d_confined::init_world),
Example::new(S2D, "Pyramid", s2d_pyramid::init_world),
Example::new(S2D, "Card house", s2d_card_house::init_world),
Example::new(S2D, "Arch", s2d_arch::init_world),
Example::new(S2D, "Bridge", s2d_bridge::init_world),
Example::new(S2D, "Ball and chain", s2d_ball_and_chain::init_world),
Example::new(S2D, "Joint grid", s2d_joint_grid::init_world),
Example::new(S2D, "Far pyramid", s2d_far_pyramid::init_world),
];
let mut benches = stress_tests::builders();
builders.append(&mut benches);
let testbed = TestbedApp::from_builders(builders);
testbed.run()
testbed.run().await
}

View File

@@ -1,3 +1,4 @@
use kiss3d::color::Color;
use rapier_testbed2d::Testbed;
use rapier2d::prelude::*;
@@ -23,15 +24,15 @@ pub fn init_world(testbed: &mut Testbed) {
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
let collider =
ColliderBuilder::cuboid(ground_thickness, ground_size).translation(vector![-3.0, 0.0]);
ColliderBuilder::cuboid(ground_thickness, ground_size).translation(Vector::new(-3.0, 0.0));
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
let collider =
ColliderBuilder::cuboid(ground_thickness, ground_size).translation(vector![6.0, 0.0]);
ColliderBuilder::cuboid(ground_thickness, ground_size).translation(Vector::new(6.0, 0.0));
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
let collider = ColliderBuilder::cuboid(ground_thickness, ground_size)
.translation(vector![2.5, 0.0])
.translation(Vector::new(2.5, 0.0))
.sensor(true)
.active_events(ActiveEvents::COLLISION_EVENTS);
let sensor_handle = colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -42,9 +43,9 @@ pub fn init_world(testbed: &mut Testbed) {
let radx = 0.4;
let rady = 0.05;
let delta1 = Isometry::translation(0.0, radx - rady);
let delta2 = Isometry::translation(-radx + rady, 0.0);
let delta3 = Isometry::translation(radx - rady, 0.0);
let delta1 = Pose::from_translation(Vector::new(0.0, radx - rady));
let delta2 = Pose::from_translation(Vector::new(-radx + rady, 0.0));
let delta3 = Pose::from_translation(Vector::new(radx - rady, 0.0));
let mut compound_parts = Vec::new();
let vertical = SharedShape::cuboid(rady, radx);
@@ -67,8 +68,8 @@ pub fn init_world(testbed: &mut Testbed) {
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![x, y])
.linvel(vector![100.0, -10.0])
.translation(Vector::new(x, y))
.linvel(Vector::new(100.0, -10.0))
.ccd_enabled(true);
let handle = bodies.insert(rigid_body);
@@ -89,9 +90,9 @@ pub fn init_world(testbed: &mut Testbed) {
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
@@ -108,11 +109,11 @@ pub fn init_world(testbed: &mut Testbed) {
.unwrap();
if let Some(graphics) = &mut graphics {
if parent_handle1 != ground_handle && prox.collider1() != sensor_handle {
graphics.set_body_color(parent_handle1, color);
graphics.set_body_color(parent_handle1, color, false);
}
if parent_handle2 != ground_handle && prox.collider2() != sensor_handle {
graphics.set_body_color(parent_handle2, color);
graphics.set_body_color(parent_handle2, color, false);
}
}
}
@@ -122,5 +123,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, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -1,5 +1,6 @@
use crate::utils::character;
use crate::utils::character::CharacterControlMode;
use kiss3d::color::Color;
use rapier_testbed2d::Testbed;
use rapier2d::control::{KinematicCharacterController, PidController};
use rapier2d::prelude::*;
@@ -20,7 +21,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]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height));
let floor_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height);
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
@@ -29,7 +30,7 @@ pub fn init_world(testbed: &mut Testbed) {
* Character we will control manually.
*/
let rigid_body = RigidBodyBuilder::kinematic_position_based()
.translation(vector![-3.0, 5.0])
.translation(Vector::new(-3.0, 5.0))
// The two config below makes the character
// nicer to control with the PID control enabled.
.gravity_scale(10.0)
@@ -37,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) {
let character_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::capsule_y(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
@@ -54,7 +55,7 @@ pub fn init_world(testbed: &mut Testbed) {
let x = i as f32 * shift - centerx;
let y = j as f32 * shift + centery;
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -71,7 +72,7 @@ pub fn init_world(testbed: &mut Testbed) {
let y = i as f32 * stair_height * 1.5 + 3.0;
let collider = ColliderBuilder::cuboid(stair_width / 2.0, stair_height / 2.0)
.translation(vector![x, y]);
.translation(Vector::new(x, y));
colliders.insert(collider);
}
@@ -81,32 +82,32 @@ 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)
.translation(vector![ground_size + slope_size, -ground_height + 0.4])
.translation(Vector::new(ground_size + slope_size, -ground_height + 0.4))
.rotation(slope_angle);
colliders.insert(collider);
/*
* Create a slope we cant climb.
* Create a slope we can't climb.
*/
let impossible_slope_angle = 0.9;
let impossible_slope_size = 2.0;
let collider = ColliderBuilder::cuboid(slope_size, ground_height)
.translation(vector![
.translation(Vector::new(
ground_size + slope_size * 2.0 + impossible_slope_size - 0.9,
-ground_height + 2.3
])
-ground_height + 2.3,
))
.rotation(impossible_slope_angle);
colliders.insert(collider);
/*
* Create a wall we cant climb.
* Create a wall we can't climb.
*/
let wall_angle = PI / 2.;
let wall_size = 2.0;
let wall_pos = vector![
let wall_pos = Vector::new(
ground_size + slope_size * 2.0 + impossible_slope_size + 0.35,
-ground_height + 2.5 * 2.3
];
-ground_height + 2.5 * 2.3,
);
let collider = ColliderBuilder::cuboid(wall_size, ground_height)
.translation(wall_pos)
.rotation(wall_angle);
@@ -118,7 +119,7 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Create a moving platform.
*/
let body = RigidBodyBuilder::kinematic_velocity_based().translation(vector![-8.0, 0.0]);
let body = RigidBodyBuilder::kinematic_velocity_based().translation(Vector::new(-8.0, 0.0));
// .rotation(-0.3);
let platform_handle = bodies.insert(body);
let collider = ColliderBuilder::cuboid(2.0, ground_height);
@@ -130,20 +131,20 @@ pub fn init_world(testbed: &mut Testbed) {
let ground_size = Vector::new(10.0, 1.0);
let nsubdivs = 20;
let heights = DVector::from_fn(nsubdivs + 1, |i, _| {
(i as f32 * ground_size.x / (nsubdivs as f32) / 2.0).cos() * 1.5
});
let heights = (0..nsubdivs + 1)
.map(|i| (i as f32 * ground_size.x / (nsubdivs as f32) / 2.0).cos() * 1.5)
.collect();
let collider =
ColliderBuilder::heightfield(heights, ground_size).translation(vector![-8.0, 5.0]);
ColliderBuilder::heightfield(heights, ground_size).translation(Vector::new(-8.0, 5.0));
colliders.insert(collider);
/*
* A tilting dynamic body with a limited joint.
*/
let ground = RigidBodyBuilder::fixed().translation(vector![0.0, 5.0]);
let ground = RigidBodyBuilder::fixed().translation(Vector::new(0.0, 5.0));
let ground_handle = bodies.insert(ground);
let body = RigidBodyBuilder::dynamic().translation(vector![0.0, 5.0]);
let body = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 5.0));
let handle = bodies.insert(body);
let collider = ColliderBuilder::cuboid(1.0, 0.1);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -154,16 +155,16 @@ pub fn init_world(testbed: &mut Testbed) {
* 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
];
(run_state.time * 5.0).sin() * 1.5,
);
// 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 isnt handled very well yet.
// NOTE: interaction with rotating platforms isn't handled very well yet.
// platform.set_angvel(angvel, true);
}
});
@@ -197,5 +198,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, 1.0], 100.0);
testbed.look_at(Vec2::new(0.0, 1.0), 100.0);
}

View File

@@ -1,3 +1,4 @@
use kiss3d::color::{BLUE, GREEN};
use rapier_testbed2d::Testbed;
use rapier2d::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]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height));
let floor_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height);
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)
.translation(vector![0.0, 1.0])
.translation(Vector::new(0.0, 1.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, GREEN);
/*
* A blue floor that will collide with the BLUE group only.
*/
let blue_floor = ColliderBuilder::cuboid(1.0, 0.1)
.translation(vector![0.0, 2.0])
.translation(Vector::new(0.0, 2.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, BLUE);
/*
* Create the cubes
@@ -67,12 +68,12 @@ pub fn init_world(testbed: &mut Testbed) {
// Alternate between the green and blue groups.
let (group, color) = if i % 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]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad).collision_groups(group);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -85,5 +86,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, 1.0], 100.0);
testbed.look_at(Vec2::new(0.0, 1.0), 100.0);
}

View File

@@ -24,14 +24,14 @@ pub fn init_world(testbed: &mut Testbed) {
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(vector![ground_size, ground_size * 2.0]);
.translation(Vector::new(ground_size, ground_size * 2.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(vector![-ground_size, ground_size * 2.0]);
.translation(Vector::new(-ground_size, ground_size * 2.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -55,14 +55,14 @@ pub fn init_world(testbed: &mut Testbed) {
let x = i as f32 * shift - centerx;
let y = j as f32 * shift * 2.0 + centery + 2.0;
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = bodies.insert(rigid_body);
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) * scale);
}
let collider = ColliderBuilder::convex_hull(&points).unwrap();
@@ -74,5 +74,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, 50.0], 10.0);
testbed.look_at(Vec2::new(0.0, 50.0), 10.0);
}

View File

@@ -23,8 +23,8 @@ pub fn init_world(testbed: &mut Testbed) {
// Build the rigid body.
let rb = RigidBodyBuilder::dynamic()
.translation(vector![x, y])
.linvel(vector![x * 10.0, y * 10.0])
.translation(Vector::new(x, y))
.linvel(Vector::new(x * 10.0, y * 10.0))
.angvel(100.0)
.linear_damping((i + 1) as f32 * subdiv * 10.0)
.angular_damping((num - i) as f32 * subdiv * 10.0);
@@ -43,8 +43,8 @@ pub fn init_world(testbed: &mut Testbed) {
colliders,
impulse_joints,
multibody_joints,
Vector::zeros(),
Vector::ZERO,
(),
);
testbed.look_at(point![3.0, 2.0], 50.0);
testbed.look_at(Vec2::new(3.0, 2.0), 50.0);
}

View File

@@ -15,7 +15,7 @@ pub fn init_world(testbed: &mut Testbed) {
*/
let rad = 1.0;
let rigid_body = RigidBodyBuilder::fixed()
.translation(vector![0.0, -rad])
.translation(Vector::new(0.0, -rad))
.rotation(std::f32::consts::PI / 4.0);
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
@@ -23,7 +23,7 @@ pub fn init_world(testbed: &mut Testbed) {
// Build the dynamic box rigid body.
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![0.0, 3.0 * rad])
.translation(Vector::new(0.0, 3.0 * rad))
.can_sleep(false);
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad);
@@ -33,5 +33,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.0], 50.0);
testbed.look_at(Vec2::ZERO, 50.0);
}

View File

@@ -18,7 +18,7 @@ pub fn init_world(testbed: &mut Testbed) {
let ys = [-30.0 - thickness, 30.0 + thickness];
for y in ys {
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, y]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(width, thickness);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -30,7 +30,7 @@ pub fn init_world(testbed: &mut Testbed) {
let mut handles = [RigidBodyHandle::invalid(); 2];
for i in 0..2 {
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![xs[i], 0.0]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(xs[i], 0.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(thickness, half_height);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -44,14 +44,14 @@ pub fn init_world(testbed: &mut Testbed) {
for j in 0..num {
let x = i as f32 * rad * 2.0 - num as f32 * rad;
let y = j as f32 * rad * 2.0 - num as f32 * rad + rad;
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
let mut force = vector![0.0, 0.0];
let mut force = Vector::new(0.0, 0.0);
testbed.add_callback(move |_, physics, _, _| {
let left_plank = &mut physics.bodies[handles[0]];
@@ -71,5 +71,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.0], 50.0);
testbed.look_at(Vec2::ZERO, 50.0);
}

View File

@@ -1,3 +1,4 @@
use kiss3d::color::{Color, GREY, RED};
use rapier_testbed2d::Testbed;
use rapier2d::prelude::*;
@@ -16,19 +17,20 @@ pub fn init_world(testbed: &mut Testbed) {
let count = 100;
for x in 0..count {
for y in 0..count {
let rigid_body = RigidBodyBuilder::fixed().translation(vector![
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(
(x as f32 - count as f32 / 2.0) * rad * 3.0,
(y as f32 - count as f32 / 2.0) * rad * 3.0
]);
(y as f32 - count as f32 / 2.0) * rad * 3.0,
));
let handle = bodies.insert(rigid_body);
colliders.insert_with_parent(collider.clone(), handle, &mut bodies);
testbed.set_initial_body_color(
handle,
[
Color::new(
x as f32 / count as f32,
(count - y) as f32 / count as f32,
0.5,
],
1.0,
),
);
}
}
@@ -37,7 +39,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![0.0, 0.0], 50.0);
testbed.look_at(Vec2::ZERO, 50.0);
testbed.add_callback(move |mut graphics, physics, _, run| {
let slow_time = run.timestep_id as f32 / 3.0;
@@ -50,18 +52,18 @@ pub fn init_world(testbed: &mut Testbed) {
);
for intersection in query_pipeline.intersect_shape(
Isometry::translation(slow_time.cos() * 10.0, slow_time.sin() * 10.0),
Pose::from_translation(Vector::new(slow_time.cos() * 10.0, slow_time.sin() * 10.0)),
&Ball::new(rad / 2.0),
) {
if let Some(graphics) = graphics.as_deref_mut() {
for (handle, _) in physics.bodies.iter() {
graphics.set_body_color(handle, [0.5, 0.5, 0.5]);
graphics.set_body_color(handle, GREY, false);
}
let collider = physics.colliders.get(intersection.0).unwrap();
let body_handle = collider.parent().unwrap();
graphics.set_body_color(body_handle, [1.0, 0.0, 0.0]);
graphics.set_body_color(body_handle, RED, false);
}
}
});

View File

@@ -24,5 +24,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.0], 50.0);
testbed.look_at(Vec2::ZERO, 50.0);
}

View File

@@ -32,7 +32,7 @@ pub fn init_world(testbed: &mut Testbed) {
let y = i as f32 * rad * 2.0 + ground_thickness + rad;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad).friction(0.3);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -43,5 +43,5 @@ pub fn init_world(testbed: &mut Testbed) {
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
// testbed.harness_mut().physics.gravity.y = -981.0;
testbed.look_at(point![0.0, 2.5], 5.0);
testbed.look_at(Vec2::new(0.0, 2.5), 5.0);
}

View File

@@ -26,7 +26,7 @@ pub fn init_world(testbed: &mut Testbed) {
let y = j as f32 * shift - centery;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -40,16 +40,16 @@ pub fn init_world(testbed: &mut Testbed) {
let velocity_based_platform_handle = bodies.insert(platform_body);
let sides = [
(10.0, 0.25, vector![0.0, 10.0]),
(10.0, 0.25, vector![0.0, -10.0]),
(0.25, 10.0, vector![10.0, 0.0]),
(0.25, 10.0, vector![-10.0, 0.0]),
(10.0, 0.25, Vector::new(0.0, 10.0)),
(10.0, 0.25, Vector::new(0.0, -10.0)),
(0.25, 10.0, Vector::new(10.0, 0.0)),
(0.25, 10.0, Vector::new(-10.0, 0.0)),
];
let balls = [
(1.25, vector![6.0, 6.0]),
(1.25, vector![-6.0, 6.0]),
(1.25, vector![6.0, -6.0]),
(1.25, vector![-6.0, -6.0]),
(1.25, Vector::new(6.0, 6.0)),
(1.25, Vector::new(-6.0, 6.0)),
(1.25, Vector::new(6.0, -6.0)),
(1.25, Vector::new(-6.0, -6.0)),
];
for (hx, hy, pos) in sides {
@@ -75,5 +75,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Run the simulation.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(point![0.0, 1.0], 40.0);
testbed.look_at(Vec2::new(0.0, 1.0), 40.0);
}

View File

@@ -1,5 +1,4 @@
use rapier_testbed2d::Testbed;
use rapier2d::na::DVector;
use rapier2d::prelude::*;
pub fn init_world(testbed: &mut Testbed) {
@@ -17,13 +16,15 @@ pub fn init_world(testbed: &mut Testbed) {
let ground_size = Vector::new(50.0, 1.0);
let nsubdivs = 2000;
let heights = DVector::from_fn(nsubdivs + 1, |i, _| {
if i == 0 || i == nsubdivs {
8.0
} else {
(i as f32 * ground_size.x / (nsubdivs as f32)).cos() * 2.0
}
});
let heights = (0..nsubdivs + 1)
.map(|i| {
if i == 0 || i == nsubdivs {
8.0
} else {
(i as f32 * ground_size.x / (nsubdivs as f32)).cos() * 2.0
}
})
.collect();
let rigid_body = RigidBodyBuilder::fixed();
let handle = bodies.insert(rigid_body);
@@ -46,7 +47,7 @@ pub fn init_world(testbed: &mut Testbed) {
let y = j as f32 * shift + centery + 3.0;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = bodies.insert(rigid_body);
if j % 2 == 0 {
@@ -63,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![0.0, 0.0], 10.0);
testbed.look_at(Vec2::ZERO, 10.0);
}

View File

@@ -31,7 +31,7 @@ pub fn init_world(testbed: &mut Testbed) {
for _ in 0usize..num {
// Build the rigid body.
let rigid_body =
RigidBodyBuilder::dynamic().translation(vector![0.0, y + ground_thickness]);
RigidBodyBuilder::dynamic().translation(Vector::new(0.0, y + ground_thickness));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -43,5 +43,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, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
let ground_size = 1.0;
let ground_height = 0.01;
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height));
let floor_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height);
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 = RevoluteJointBuilder::new()
.local_anchor1(point![0.0, size / 2.0 * (i != 0) as usize as f32])
.local_anchor2(point![0.0, -size / 2.0])
.local_anchor1(Vector::new(0.0, size / 2.0 * (i != 0) as usize as f32))
.local_anchor2(Vector::new(0.0, -size / 2.0))
.build()
.data;
@@ -70,7 +70,7 @@ pub fn init_world(testbed: &mut Testbed) {
};
// We will have the endpoint track the mouse position.
let target_point = mouse_point.coords;
let target_point = Vector::new(mouse_point.x, mouse_point.y);
let options = InverseKinematicsOption {
constrained_axes: JointAxesMask::LIN_AXES,
@@ -81,7 +81,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,
);
@@ -93,5 +93,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.0], 300.0);
testbed.look_at(Vec2::ZERO, 300.0);
}

View File

@@ -22,15 +22,15 @@ 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])
.translation(Vector::new(x_pos, 2.0))
.can_sleep(false);
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(0.1, 0.5);
colliders.insert_with_parent(collider, handle, &mut bodies);
let joint = RevoluteJointBuilder::new()
.local_anchor1(point![x_pos, 1.5])
.local_anchor2(point![0.0, -0.5])
.local_anchor1(Vector::new(x_pos, 1.5))
.local_anchor2(Vector::new(0.0, -0.5))
.motor_position(
-std::f32::consts::PI + std::f32::consts::PI / 4.0 * num as f32,
1000.0,
@@ -45,7 +45,7 @@ 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])
.translation(Vector::new(x_pos, 4.5))
.rotation(std::f32::consts::PI)
.can_sleep(false);
let handle = bodies.insert(rigid_body);
@@ -53,8 +53,8 @@ pub fn init_world(testbed: &mut Testbed) {
colliders.insert_with_parent(collider, handle, &mut bodies);
let joint = RevoluteJointBuilder::new()
.local_anchor1(point![x_pos, 5.0])
.local_anchor2(point![0.0, -0.5])
.local_anchor1(Vector::new(x_pos, 5.0))
.local_anchor2(Vector::new(0.0, -0.5))
.motor_velocity(1.5, 30.0)
.motor_max_force(100.0)
.limits([
@@ -72,8 +72,8 @@ pub fn init_world(testbed: &mut Testbed) {
colliders,
impulse_joints,
multibody_joints,
vector![0.0, 0.0],
Vector::new(0.0, 0.0),
(),
);
testbed.look_at(point![0.0, 0.0], 40.0);
testbed.look_at(Vec2::ZERO, 40.0);
}

View File

@@ -42,7 +42,7 @@ pub fn init_world(testbed: &mut Testbed) {
};
let rigid_body =
RigidBodyBuilder::new(status).translation(vector![fk * shift, -fi * shift]);
RigidBodyBuilder::new(status).translation(Vector::new(fk * shift, -fi * shift));
let child_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad);
colliders.insert_with_parent(collider, child_handle, &mut bodies);
@@ -61,7 +61,7 @@ pub fn init_world(testbed: &mut Testbed) {
if i > 0 {
let parent_handle = *body_handles.last().unwrap();
let joint = RevoluteJointBuilder::new()
.local_anchor2(point![0.0, shift])
.local_anchor2(Vector::new(0.0, shift))
.softness(softness);
impulse_joints.insert(parent_handle, child_handle, joint, true);
}
@@ -71,7 +71,7 @@ pub fn init_world(testbed: &mut Testbed) {
let parent_index = body_handles.len() - numi;
let parent_handle = body_handles[parent_index];
let joint = RevoluteJointBuilder::new()
.local_anchor2(point![-shift, 0.0])
.local_anchor2(Vector::new(-shift, 0.0))
.softness(softness);
impulse_joints.insert(parent_handle, child_handle, joint, true);
}
@@ -84,5 +84,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![numk as f32 * rad, numi as f32 * -rad], 20.0);
testbed.look_at(Vec2::new(numk as f32 * rad, numi as f32 * -rad), 20.0);
}

View File

@@ -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]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -28,7 +28,7 @@ pub fn init_world(testbed: &mut Testbed) {
* A rectangle that only rotate.
*/
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![0.0, 3.0])
.translation(Vector::new(0.0, 3.0))
.lock_translations();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(2.0, 0.6);
@@ -38,7 +38,7 @@ pub fn init_world(testbed: &mut Testbed) {
* A tilted capsule that cannot rotate.
*/
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![0.0, 5.0])
.translation(Vector::new(0.0, 5.0))
.rotation(1.0)
.lock_rotations();
let handle = bodies.insert(rigid_body);
@@ -49,5 +49,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.0], 40.0);
testbed.look_at(Vec2::ZERO, 40.0);
}

View File

@@ -20,24 +20,24 @@ impl PhysicsHooks for OneWayPlatformHook {
// - If context.collider_handle2 == self.platform1 then the allowed normal is -y.
// - If context.collider_handle1 == self.platform2 then its allowed normal +y needs to be flipped to -y.
// - If context.collider_handle2 == self.platform2 then the allowed normal -y needs to be flipped to +y.
let mut allowed_local_n1 = 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(25.0, 0.5)
.translation(vector![30.0, 2.0])
.translation(Vector::new(30.0, 2.0))
.active_hooks(ActiveHooks::MODIFY_SOLVER_CONTACTS);
let platform1 = colliders.insert_with_parent(collider, handle, &mut bodies);
let collider = ColliderBuilder::cuboid(25.0, 0.5)
.translation(vector![-30.0, -2.0])
.translation(Vector::new(-30.0, -2.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.5, 2.0);
let body = RigidBodyBuilder::dynamic().translation(vector![20.0, 10.0]);
let body = RigidBodyBuilder::dynamic().translation(Vector::new(20.0, 10.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],
Vector::new(0.0, -9.81),
physics_hooks,
);
testbed.look_at(point![0.0, 0.0], 20.0);
testbed.look_at(Vec2::ZERO, 20.0);
}

View File

@@ -19,7 +19,7 @@ pub fn init_world(testbed: &mut Testbed) {
let ground_size = 3.0;
let ground_height = 0.1;
let rigid_body_floor = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height]);
let rigid_body_floor = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height));
let floor_handle = bodies.insert(rigid_body_floor);
let floor_collider = ColliderBuilder::cuboid(ground_size, ground_height);
colliders.insert_with_parent(floor_collider, floor_handle, &mut bodies);
@@ -28,7 +28,7 @@ pub fn init_world(testbed: &mut Testbed) {
* Character we will control manually.
*/
let rigid_body_character =
RigidBodyBuilder::kinematic_position_based().translation(vector![0.0, 0.3]);
RigidBodyBuilder::kinematic_position_based().translation(Vector::new(0.0, 0.3));
let character_handle = bodies.insert(rigid_body_character);
let character_collider = ColliderBuilder::cuboid(0.15, 0.3);
colliders.insert_with_parent(character_collider, character_handle, &mut bodies);
@@ -39,16 +39,16 @@ pub fn init_world(testbed: &mut Testbed) {
let rad = 0.4;
let rigid_body_cube =
RigidBodyBuilder::new(RigidBodyType::Dynamic).translation(vector![1.0, 1.0]);
RigidBodyBuilder::new(RigidBodyType::Dynamic).translation(Vector::new(1.0, 1.0));
let cube_handle = bodies.insert(rigid_body_cube);
let cube_collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(cube_collider, cube_handle, &mut bodies);
/*
* Rotation axis indicator ball.
* SimdRotation axis indicator ball.
*/
let rigid_body_ball =
RigidBodyBuilder::new(RigidBodyType::Dynamic).translation(vector![1.0, 1.0]);
RigidBodyBuilder::new(RigidBodyType::Dynamic).translation(Vector::new(1.0, 1.0));
let ball_handle = bodies.insert(rigid_body_ball);
let ball_collider = ColliderBuilder::ball(0.1);
colliders.insert_with_parent(ball_collider, ball_handle, &mut bodies);
@@ -57,25 +57,18 @@ pub fn init_world(testbed: &mut Testbed) {
* Fixed joint between rotation axis indicator and cube.
*/
let fixed_joint = FixedJointBuilder::new()
.local_anchor1(point![0.0, 0.0])
.local_anchor2(point![0.0, -0.4])
.local_anchor1(Vector::new(0.0, 0.0))
.local_anchor2(Vector::new(0.0, -0.4))
.build();
impulse_joints.insert(cube_handle, ball_handle, fixed_joint, true);
/*
* Pin slot joint between cube and ground.
*/
let axis: nalgebra::Unit<
nalgebra::Matrix<
f32,
nalgebra::Const<2>,
nalgebra::Const<1>,
nalgebra::ArrayStorage<f32, 2, 1>,
>,
> = UnitVector::new_normalize(vector![1.0, 1.0]);
let axis = Vector::new(1.0, 1.0).normalize();
let pin_slot_joint = PinSlotJointBuilder::new(axis)
.local_anchor1(point![2.0, 2.0])
.local_anchor2(point![0.0, 0.4])
.local_anchor1(Vector::new(2.0, 2.0))
.local_anchor2(Vector::new(0.0, 0.4))
.limits([-1.0, f32::INFINITY]) // Set the limits for the pin slot joint
.build();
impulse_joints.insert(character_handle, cube_handle, pin_slot_joint, true);
@@ -104,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![0.0, 1.0], 100.0);
testbed.look_at(Vec2::new(0.0, 1.0), 100.0);
}

View File

@@ -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]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -37,7 +37,7 @@ pub fn init_world(testbed: &mut Testbed) {
let y = j as f32 * shift + centery;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -47,8 +47,8 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Setup a position-based kinematic rigid body.
*/
let platform_body =
RigidBodyBuilder::kinematic_velocity_based().translation(vector![-10.0 * rad, 1.5 + 0.8]);
let platform_body = RigidBodyBuilder::kinematic_velocity_based()
.translation(Vector::new(-10.0 * rad, 1.5 + 0.8));
let velocity_based_platform_handle = bodies.insert(platform_body);
let collider = ColliderBuilder::cuboid(rad * 10.0, rad);
colliders.insert_with_parent(collider, velocity_based_platform_handle, &mut bodies);
@@ -57,7 +57,7 @@ pub fn init_world(testbed: &mut Testbed) {
* Setup a velocity-based kinematic rigid body.
*/
let platform_body = RigidBodyBuilder::kinematic_position_based()
.translation(vector![-10.0 * rad, 2.0 + 1.5 + 0.8]);
.translation(Vector::new(-10.0 * rad, 2.0 + 1.5 + 0.8));
let position_based_platform_handle = bodies.insert(platform_body);
let collider = ColliderBuilder::cuboid(rad * 10.0, rad);
colliders.insert_with_parent(collider, position_based_platform_handle, &mut bodies);
@@ -66,7 +66,7 @@ pub fn init_world(testbed: &mut Testbed) {
* Setup a callback to control the platform.
*/
testbed.add_callback(move |_, physics, _, run_state| {
let velocity = vector![run_state.time.sin() * 5.0, (run_state.time * 5.0).sin()];
let velocity = Vector::new(run_state.time.sin() * 5.0, (run_state.time * 5.0).sin());
// Update the velocity-based kinematic body by setting its velocity.
if let Some(platform) = physics.bodies.get_mut(velocity_based_platform_handle) {
@@ -75,7 +75,7 @@ pub fn init_world(testbed: &mut Testbed) {
// 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_tra = platform.translation();
next_tra += velocity * physics.integration_parameters.dt;
platform.set_next_kinematic_translation(next_tra);
}
@@ -85,5 +85,5 @@ pub fn init_world(testbed: &mut Testbed) {
* Run the simulation.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(point![0.0, 1.0], 40.0);
testbed.look_at(Vec2::new(0.0, 1.0), 40.0);
}

View File

@@ -19,13 +19,13 @@ pub fn init_world(testbed: &mut Testbed) {
let step_size = ground_size / (nsubdivs as f32);
let mut points = Vec::new();
points.push(point![-ground_size / 2.0, 40.0]);
points.push(Vector::new(-ground_size / 2.0, 40.0));
for i in 1..nsubdivs - 1 {
let x = -ground_size / 2.0 + i as f32 * step_size;
let y = ComplexField::cos(i as f32 * step_size) * 2.0;
points.push(point![x, y]);
points.push(Vector::new(x, y));
}
points.push(point![ground_size / 2.0, 40.0]);
points.push(Vector::new(ground_size / 2.0, 40.0));
let rigid_body = RigidBodyBuilder::fixed();
let handle = bodies.insert(rigid_body);
@@ -48,7 +48,7 @@ pub fn init_world(testbed: &mut Testbed) {
let y = j as f32 * shift + centery + 3.0;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = bodies.insert(rigid_body);
if j % 2 == 0 {
@@ -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![0.0, 0.0], 10.0);
testbed.look_at(Vec2::ZERO, 10.0);
}

View File

@@ -39,7 +39,7 @@ pub fn init_world(testbed: &mut Testbed) {
let y = fi * shift + centery;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -50,5 +50,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, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -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]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height).restitution(1.0);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -27,8 +27,8 @@ 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![x * 2.0, 10.0 * (j as f32 + 1.0)]);
let rigid_body = RigidBodyBuilder::dynamic()
.translation(Vector::new(x * 2.0, 10.0 * (j as f32 + 1.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);
@@ -39,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![0.0, 1.0], 25.0);
testbed.look_at(Vec2::new(0.0, 1.0), 25.0);
}

View File

@@ -19,19 +19,19 @@ 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]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height));
let floor_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height);
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
let rigid_body =
RigidBodyBuilder::fixed().translation(vector![-ground_size - ground_height, ground_size]);
let rigid_body = RigidBodyBuilder::fixed()
.translation(Vector::new(-ground_size - ground_height, ground_size));
let floor_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_height, ground_size);
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
let rigid_body =
RigidBodyBuilder::fixed().translation(vector![ground_size + ground_height, ground_size]);
let rigid_body = RigidBodyBuilder::fixed()
.translation(Vector::new(ground_size + ground_height, ground_size));
let floor_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_height, ground_size);
colliders.insert_with_parent(collider, floor_handle, &mut bodies);
@@ -39,7 +39,8 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Character we will control manually.
*/
let rigid_body = RigidBodyBuilder::kinematic_position_based().translation(vector![0.0, 0.3]);
let rigid_body =
RigidBodyBuilder::kinematic_position_based().translation(Vector::new(0.0, 0.3));
let character_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(0.15, 0.3);
colliders.insert_with_parent(collider, character_handle, &mut bodies);
@@ -49,12 +50,13 @@ pub fn init_world(testbed: &mut Testbed) {
*/
let rad = 0.04;
let rigid_body = RigidBodyBuilder::new(RigidBodyType::Dynamic).translation(vector![1.0, 1.0]);
let rigid_body =
RigidBodyBuilder::new(RigidBodyType::Dynamic).translation(Vector::new(1.0, 1.0));
let child_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad);
colliders.insert_with_parent(collider, child_handle, &mut bodies);
let joint = RopeJointBuilder::new(2.0).local_anchor2(point![0.0, 0.0]);
let joint = RopeJointBuilder::new(2.0).local_anchor2(Vector::new(0.0, 0.0));
impulse_joints.insert(character_handle, child_handle, joint, true);
/*
@@ -81,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![0.0, 1.0], 100.0);
testbed.look_at(Vec2::new(0.0, 1.0), 100.0);
}

View File

@@ -12,28 +12,28 @@ pub fn init_world(testbed: &mut Testbed) {
#[allow(clippy::excessive_precision)]
let mut ps1 = [
Point::new(16.0, 0.0),
Point::new(14.93803712795643, 5.133601056842984),
Point::new(13.79871746027416, 10.24928069555078),
Point::new(12.56252963284711, 15.34107019122473),
Point::new(11.20040987372525, 20.39856541571217),
Point::new(9.66521217819836, 25.40369899225096),
Point::new(7.87179930638133, 30.3179337000085),
Point::new(5.635199558196225, 35.03820717801641),
Point::new(2.405937953536585, 39.09554102558315),
Vector::new(16.0, 0.0),
Vector::new(14.93803712795643, 5.133601056842984),
Vector::new(13.79871746027416, 10.24928069555078),
Vector::new(12.56252963284711, 15.34107019122473),
Vector::new(11.20040987372525, 20.39856541571217),
Vector::new(9.66521217819836, 25.40369899225096),
Vector::new(7.87179930638133, 30.3179337000085),
Vector::new(5.635199558196225, 35.03820717801641),
Vector::new(2.405937953536585, 39.09554102558315),
];
#[allow(clippy::excessive_precision)]
let mut ps2 = [
Point::new(24.0, 0.0),
Point::new(22.33619528222415, 6.02299846205841),
Point::new(20.54936888969905, 12.00964361211476),
Point::new(18.60854610798073, 17.9470321677465),
Point::new(16.46769273811807, 23.81367936585418),
Point::new(14.05325025774858, 29.57079353071012),
Point::new(11.23551045834022, 35.13775818285372),
Point::new(7.752568160730571, 40.30450679009583),
Point::new(3.016931552701656, 44.28891593799322),
Vector::new(24.0, 0.0),
Vector::new(22.33619528222415, 6.02299846205841),
Vector::new(20.54936888969905, 12.00964361211476),
Vector::new(18.60854610798073, 17.9470321677465),
Vector::new(16.46769273811807, 23.81367936585418),
Vector::new(14.05325025774858, 29.57079353071012),
Vector::new(11.23551045834022, 35.13775818285372),
Vector::new(7.752568160730571, 40.30450679009583),
Vector::new(3.016931552701656, 44.28891593799322),
];
let scale = 0.25;
@@ -47,7 +47,8 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Ground
*/
let collider = ColliderBuilder::segment(point![-100.0, 0.0], point![100.0, 0.0]).friction(0.6);
let collider =
ColliderBuilder::segment(Vector::new(-100.0, 0.0), Vector::new(100.0, 0.0)).friction(0.6);
colliders.insert(collider);
/*
@@ -65,10 +66,10 @@ pub fn init_world(testbed: &mut Testbed) {
for i in 0..8 {
let ps = [
point![-ps2[i].x, ps2[i].y],
point![-ps1[i].x, ps1[i].y],
point![-ps1[i + 1].x, ps1[i + 1].y],
point![-ps2[i + 1].x, ps2[i + 1].y],
Vector::new(-ps2[i].x, ps2[i].y),
Vector::new(-ps1[i].x, ps1[i].y),
Vector::new(-ps1[i + 1].x, ps1[i + 1].y),
Vector::new(-ps2[i + 1].x, ps2[i + 1].y),
];
let rigid_body = RigidBodyBuilder::dynamic();
let ground_handle = bodies.insert(rigid_body);
@@ -82,8 +83,8 @@ pub fn init_world(testbed: &mut Testbed) {
let ps = [
ps1[8],
ps2[8],
point![-ps1[8].x, ps1[8].y],
point![-ps2[8].x, ps2[8].y],
Vector::new(-ps1[8].x, ps1[8].y),
Vector::new(-ps2[8].x, ps2[8].y),
];
let rigid_body = RigidBodyBuilder::dynamic();
let ground_handle = bodies.insert(rigid_body);
@@ -94,8 +95,8 @@ pub fn init_world(testbed: &mut Testbed) {
}
for i in 0..4 {
let rigid_body =
RigidBodyBuilder::dynamic().translation(vector![0.0, 0.5 + ps2[8].y + 1.0 * i as f32]);
let rigid_body = RigidBodyBuilder::dynamic()
.translation(Vector::new(0.0, 0.5 + ps2[8].y + 1.0 * i as f32));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(2.0, 0.5).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -105,5 +106,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, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -31,14 +31,14 @@ pub fn init_world(testbed: &mut Testbed) {
let rigid_body = RigidBodyBuilder::dynamic()
.linear_damping(0.1)
.angular_damping(0.1)
.translation(vector![(1.0 + 2.0 * i as f32) * hx, count as f32 * hx]);
.translation(Vector::new((1.0 + 2.0 * i as f32) * hx, count as f32 * hx));
let handle = bodies.insert(rigid_body);
colliders.insert_with_parent(capsule.clone(), handle, &mut bodies);
let pivot = point![(2.0 * i as f32) * hx, count as f32 * hx];
let pivot = Vector::new((2.0 * i as f32) * hx, count as f32 * hx);
let joint = RevoluteJointBuilder::new()
.local_anchor1(bodies[prev].position().inverse_transform_point(&pivot))
.local_anchor2(bodies[handle].position().inverse_transform_point(&pivot))
.local_anchor1(bodies[prev].position().inverse_transform_point(pivot))
.local_anchor2(bodies[handle].position().inverse_transform_point(pivot))
.contacts_enabled(false);
impulse_joints.insert(prev, handle, joint, true);
prev = handle;
@@ -48,20 +48,20 @@ pub fn init_world(testbed: &mut Testbed) {
let rigid_body = RigidBodyBuilder::dynamic()
.linear_damping(0.1)
.angular_damping(0.1)
.translation(vector![
.translation(Vector::new(
(1.0 + 2.0 * count as f32) * hx + radius - hx,
count as f32 * hx
]);
count as f32 * hx,
));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(radius)
.friction(friction)
.density(density);
colliders.insert_with_parent(collider, handle, &mut bodies);
let pivot = point![(2.0 * count as f32) * hx, count as f32 * hx];
let pivot = Vector::new((2.0 * count as f32) * hx, count as f32 * hx);
let joint = RevoluteJointBuilder::new()
.local_anchor1(bodies[prev].position().inverse_transform_point(&pivot))
.local_anchor2(bodies[handle].position().inverse_transform_point(&pivot))
.local_anchor1(bodies[prev].position().inverse_transform_point(pivot))
.local_anchor2(bodies[handle].position().inverse_transform_point(pivot))
.contacts_enabled(false);
impulse_joints.insert(prev, handle, joint, true);
@@ -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![0.0, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -27,24 +27,24 @@ pub fn init_world(testbed: &mut Testbed) {
let rigid_body = RigidBodyBuilder::dynamic()
.linear_damping(0.1)
.angular_damping(0.1)
.translation(vector![x_base + 0.5 + 1.0 * i as f32, 20.0]);
.translation(Vector::new(x_base + 0.5 + 1.0 * i as f32, 20.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(0.5, 0.125).density(density);
colliders.insert_with_parent(collider, handle, &mut bodies);
let pivot = point![x_base + 1.0 * i as f32, 20.0];
let pivot = Vector::new(x_base + 1.0 * i as f32, 20.0);
let joint = RevoluteJointBuilder::new()
.local_anchor1(bodies[prev].position().inverse_transform_point(&pivot))
.local_anchor2(bodies[handle].position().inverse_transform_point(&pivot))
.local_anchor1(bodies[prev].position().inverse_transform_point(pivot))
.local_anchor2(bodies[handle].position().inverse_transform_point(pivot))
.contacts_enabled(false);
impulse_joints.insert(prev, handle, joint, true);
prev = handle;
}
let pivot = point![x_base + 1.0 * count as f32, 20.0];
let pivot = Vector::new(x_base + 1.0 * count as f32, 20.0);
let joint = RevoluteJointBuilder::new()
.local_anchor1(bodies[prev].position().inverse_transform_point(&pivot))
.local_anchor2(bodies[ground].position().inverse_transform_point(&pivot))
.local_anchor1(bodies[prev].position().inverse_transform_point(pivot))
.local_anchor2(bodies[ground].position().inverse_transform_point(pivot))
.contacts_enabled(false);
impulse_joints.insert(prev, ground, joint, true);
@@ -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![0.0, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -15,7 +15,7 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Ground
*/
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -2.0]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -2.0));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(40.0, 2.0).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -42,14 +42,17 @@ pub fn init_world(testbed: &mut Testbed) {
for i in 0..nb {
if i != nb - 1 {
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![z + 0.25 * scale, y + card_height - 0.015 * scale])
.translation(Vector::new(
z + 0.25 * scale,
y + card_height - 0.015 * scale,
))
.rotation(angle2);
let ground_handle = bodies.insert(rigid_body);
colliders.insert_with_parent(card_box.clone(), ground_handle, &mut bodies);
}
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![z, y])
.translation(Vector::new(z, y))
.rotation(angle1);
let ground_handle = bodies.insert(rigid_body);
colliders.insert_with_parent(card_box.clone(), ground_handle, &mut bodies);
@@ -57,7 +60,7 @@ pub fn init_world(testbed: &mut Testbed) {
z += 0.175 * scale;
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![z, y])
.translation(Vector::new(z, y))
.rotation(angle0);
let ground_handle = bodies.insert(rigid_body);
colliders.insert_with_parent(card_box.clone(), ground_handle, &mut bodies);
@@ -74,5 +77,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, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -18,21 +18,33 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Ground
*/
let collider =
ColliderBuilder::capsule_from_endpoints(point![-10.5, 0.0], point![10.5, 0.0], radius)
.friction(friction);
let collider = ColliderBuilder::capsule_from_endpoints(
Vector::new(-10.5, 0.0),
Vector::new(10.5, 0.0),
radius,
)
.friction(friction);
colliders.insert(collider);
let collider =
ColliderBuilder::capsule_from_endpoints(point![-10.5, 0.0], point![-10.5, 20.5], radius)
.friction(friction);
let collider = ColliderBuilder::capsule_from_endpoints(
Vector::new(-10.5, 0.0),
Vector::new(-10.5, 20.5),
radius,
)
.friction(friction);
colliders.insert(collider);
let collider =
ColliderBuilder::capsule_from_endpoints(point![10.5, 0.0], point![10.5, 20.5], radius)
.friction(friction);
let collider = ColliderBuilder::capsule_from_endpoints(
Vector::new(10.5, 0.0),
Vector::new(10.5, 20.5),
radius,
)
.friction(friction);
colliders.insert(collider);
let collider =
ColliderBuilder::capsule_from_endpoints(point![-10.5, 20.5], point![10.5, 20.5], radius)
.friction(friction);
let collider = ColliderBuilder::capsule_from_endpoints(
Vector::new(-10.5, 20.5),
Vector::new(10.5, 20.5),
radius,
)
.friction(friction);
colliders.insert(collider);
/*
@@ -48,7 +60,7 @@ pub fn init_world(testbed: &mut Testbed) {
let x = -8.75 + column as f32 * 18.0 / (grid_count as f32);
let y = 1.5 + row as f32 * 18.0 / (grid_count as f32);
let body = RigidBodyBuilder::dynamic()
.translation(vector![x, y])
.translation(Vector::new(x, y))
.gravity_scale(0.0);
let body_handle = bodies.insert(body);
let ball = ColliderBuilder::ball(radius).friction(friction);
@@ -65,5 +77,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, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -10,13 +10,13 @@ pub fn init_world(testbed: &mut Testbed) {
let impulse_joints = ImpulseJointSet::new();
let multibody_joints = MultibodyJointSet::new();
let origin = vector![100_000.0, -80_000.0];
let origin = Vector::new(100_000.0, -80_000.0);
let friction = 0.6;
/*
* Ground
*/
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -1.0] + origin);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -1.0) + origin);
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(100.0, 1.0).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -35,7 +35,7 @@ pub fn init_world(testbed: &mut Testbed) {
for j in i..base_count {
let x = (i as f32 + 1.0) * shift + 2.0 * (j as f32 - i as f32) * shift
- h * base_count as f32;
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y] + origin);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y) + origin);
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(h, h).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -46,5 +46,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, 2.5] + origin, 20.0);
testbed.look_at(Vec2::new(origin.x + 0.0, origin.y + 2.5), 20.0);
}

View File

@@ -21,8 +21,8 @@ pub fn init_world(testbed: &mut Testbed) {
let rigid_body = RigidBodyBuilder::fixed();
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::segment(
point![-0.5 * 2.0 * ground_width, 0.0],
point![0.5 * 2.0 * ground_width, 0.0],
Vector::new(-0.5 * 2.0 * ground_width, 0.0),
Vector::new(0.5 * 2.0 * ground_width, 0.0),
)
.friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -40,7 +40,7 @@ pub fn init_world(testbed: &mut Testbed) {
for i in 0..count {
let coeff = i as f32 - 0.5 * count as f32;
let yy = if count == 1 { y + 2.0 } else { y };
let position = vector![2.0 * coeff * extent + offset, yy];
let position = Vector::new(2.0 * coeff * extent + offset, yy);
let rigid_body = RigidBodyBuilder::dynamic().translation(position);
let parent = bodies.insert(rigid_body);
@@ -62,5 +62,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, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -21,8 +21,8 @@ pub fn init_world(testbed: &mut Testbed) {
let rigid_body = RigidBodyBuilder::fixed();
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::segment(
point![-0.5 * 2.0 * ground_width, 0.0],
point![0.5 * 2.0 * ground_width, 0.0],
Vector::new(-0.5 * 2.0 * ground_width, 0.0),
Vector::new(0.5 * 2.0 * ground_width, 0.0),
)
.friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -30,17 +30,20 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Create the cubes
*/
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![-9.0 * extent, 0.5 * extent]);
let rigid_body =
RigidBodyBuilder::dynamic().translation(Vector::new(-9.0 * extent, 0.5 * extent));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(0.5 * extent, 0.5 * extent).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![9.0 * extent, 0.5 * extent]);
let rigid_body =
RigidBodyBuilder::dynamic().translation(Vector::new(9.0 * extent, 0.5 * extent));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(0.5 * extent, 0.5 * extent).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, (10.0 + 16.0) * extent]);
let rigid_body =
RigidBodyBuilder::dynamic().translation(Vector::new(0.0, (10.0 + 16.0) * extent));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(10.0 * extent, 10.0 * extent).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -49,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![0.0, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -16,7 +16,7 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Ground
*/
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -2.0]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -2.0));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(40.0, 2.0).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -24,17 +24,20 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Create the cubes
*/
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![-9.0 * extent, 0.5 * extent]);
let rigid_body =
RigidBodyBuilder::dynamic().translation(Vector::new(-9.0 * extent, 0.5 * extent));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(0.5 * extent, 0.5 * extent).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![9.0 * extent, 0.5 * extent]);
let rigid_body =
RigidBodyBuilder::dynamic().translation(Vector::new(9.0 * extent, 0.5 * extent));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(0.5 * extent, 0.5 * extent).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, (10.0 + 16.0) * extent]);
let rigid_body =
RigidBodyBuilder::dynamic().translation(Vector::new(0.0, (10.0 + 16.0) * extent));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(10.0 * extent, 10.0 * extent).friction(friction);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -43,5 +46,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, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -29,23 +29,23 @@ pub fn init_world(testbed: &mut Testbed) {
};
let rigid_body = RigidBodyBuilder::new(body_type)
.translation(vector![k as f32 * shift, -(i as f32) * shift]);
.translation(Vector::new(k as f32 * shift, -(i as f32) * shift));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::ball(rad);
colliders.insert_with_parent(collider, handle, &mut bodies);
if i > 0 {
let joint = RevoluteJointBuilder::new()
.local_anchor1(point![0.0, -0.5 * shift])
.local_anchor2(point![0.0, 0.5 * shift])
.local_anchor1(Vector::new(0.0, -0.5 * shift))
.local_anchor2(Vector::new(0.0, 0.5 * shift))
.contacts_enabled(false);
impulse_joints.insert(handles[index - 1], handle, joint, true);
}
if k > 0 {
let joint = RevoluteJointBuilder::new()
.local_anchor1(point![0.5 * shift, 0.0])
.local_anchor2(point![-0.5 * shift, 0.0])
.local_anchor1(Vector::new(0.5 * shift, 0.0))
.local_anchor2(Vector::new(-0.5 * shift, 0.0))
.contacts_enabled(false);
impulse_joints.insert(handles[index - numi], handle, joint, true);
}
@@ -59,5 +59,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, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -13,7 +13,7 @@ pub fn init_world(testbed: &mut Testbed) {
/*
* Ground
*/
let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -1.0]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -1.0));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(100.0, 1.0).friction(0.6);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -34,7 +34,7 @@ pub fn init_world(testbed: &mut Testbed) {
for j in i..base_count {
let x = (i as f32 + 1.0) * shift + 2.0 * (j as f32 - i as f32) * shift
- h * base_count as f32;
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(h, h).friction(0.6);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -45,5 +45,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, 2.5], 20.0);
testbed.look_at(Vec2::new(0.0, 2.5), 20.0);
}

View File

@@ -1,3 +1,4 @@
use kiss3d::color::Color;
use rapier_testbed2d::Testbed;
use rapier2d::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]);
let rigid_body = RigidBodyBuilder::fixed().translation(Vector::new(0.0, -ground_height));
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_height);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
@@ -35,12 +36,12 @@ pub fn init_world(testbed: &mut Testbed) {
let y = 3.0;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![x, y]);
let rigid_body = RigidBodyBuilder::dynamic().translation(Vector::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(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));
}
/*
@@ -48,7 +49,7 @@ pub fn init_world(testbed: &mut Testbed) {
*/
// Rigid body so that the sensor can move.
let sensor = RigidBodyBuilder::dynamic().translation(vector![0.0, 10.0]);
let sensor = RigidBodyBuilder::dynamic().translation(Vector::new(0.0, 10.0));
let sensor_handle = bodies.insert(sensor);
// Solid cube attached to the sensor which
@@ -64,15 +65,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();
@@ -80,10 +81,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);
}
}
}
@@ -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![0.0, 1.0], 100.0);
testbed.look_at(Vec2::new(0.0, 1.0), 100.0);
}

View File

@@ -0,0 +1,63 @@
use rapier_testbed2d::Testbed;
use rapier2d::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 = 25.0;
/*
let ground_shape = ShapeHandle::new(Cuboid::new(Vector2::new(ground_size, 1.0)));
let ground_handle = bodies.insert(Ground::new());
let co = ColliderDesc::new(ground_shape)
.translation(-Vector2::y())
.build(BodyPartHandle(ground_handle, 0));
colliders.insert_with_parent(co);
*/
/*
* Create the balls
*/
let num = 50;
let rad = 1.0;
let shiftx = rad * 2.5;
let shifty = rad * 2.0;
let centerx = shiftx * (num as f32) / 2.0;
let centery = shifty / 2.0;
for i in 0..num {
for j in 0usize..num * 5 {
let x = i as f32 * shiftx - centerx;
let y = j as f32 * shifty + centery;
let status = if j == 0 {
RigidBodyType::Fixed
} else {
RigidBodyType::Dynamic
};
// Build the rigid body.
let rigid_body = RigidBodyBuilder::new(status).translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
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(Vec2::new(0.0, 2.5), 5.0);
}

View File

@@ -0,0 +1,65 @@
use rapier_testbed2d::Testbed;
use rapier2d::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 = 25.0;
let rigid_body = RigidBodyBuilder::fixed();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(ground_size, ground_size * 2.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(-ground_size, ground_size * 2.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the cubes
*/
let num = 26;
let rad = 0.5;
let shift = rad * 2.0;
let centerx = shift * (num as f32) / 2.0;
let centery = shift / 2.0;
for i in 0..num {
for j in 0usize..num * 5 {
let x = i as f32 * shift - centerx;
let y = j as f32 * shift + centery + 2.0;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, 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(Vec2::new(0.0, 50.0), 10.0);
}

View File

@@ -0,0 +1,67 @@
use rapier_testbed2d::Testbed;
use rapier2d::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 = 25.0;
let rigid_body = RigidBodyBuilder::fixed();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(ground_size, ground_size * 4.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 4.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(-ground_size, ground_size * 4.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 4.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the cubes
*/
let num = 26;
let numy = num * 5;
let rad = 0.5;
let shift = rad * 2.0;
let shifty = rad * 5.0;
let centerx = shift * (num as f32) / 2.0;
let centery = shift / 2.0;
for i in 0..num {
for j in 0usize..numy {
let x = i as f32 * shift - centerx;
let y = j as f32 * shifty + centery + 3.0;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::capsule_y(rad * 1.5, 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(Vec2::new(0.0, 50.0), 10.0);
}

View File

@@ -0,0 +1,78 @@
use rand::distr::{Distribution, StandardUniform};
use rand::{SeedableRng, rngs::StdRng};
use rapier_testbed2d::Testbed;
use rapier2d::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 = 30.0;
let rigid_body = RigidBodyBuilder::fixed();
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(ground_size, ground_size * 2.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(Vec2::new(-ground_size, ground_size * 2.0));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size * 2.0, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
/*
* Create the convex polygons
*/
let num = 26;
let scale = 2.0;
let border_rad = 0.0;
let shift = border_rad * 2.0 + scale;
let centerx = shift * (num as f32) / 2.0;
let centery = shift / 2.0;
let mut rng = StdRng::seed_from_u64(0);
let distribution = StandardUniform;
for i in 0..num {
for j in 0usize..num * 5 {
let x = i as f32 * shift - centerx;
let y = j as f32 * shift * 2.0 + centery + 2.0;
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let mut points = Vec::new();
for _ in 0..10 {
let pt: [f32; 2] = distribution.sample(&mut rng);
points.push(Vec2::from(pt) * scale);
}
let collider = ColliderBuilder::convex_hull(&points).unwrap();
colliders.insert_with_parent(collider, handle, &mut bodies);
}
}
/*
* Set up the testbed.
*/
testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(Vec2::new(0.0, 50.0), 10.0);
}

View File

@@ -0,0 +1,68 @@
use rapier_testbed2d::Testbed;
use rapier2d::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 = Vec2::new(50.0, 1.0);
let nsubdivs = 2000;
let heights = (0..nsubdivs + 1)
.map(|i| {
if i == 0 || i == nsubdivs {
80.0
} else {
(i as f32 * ground_size.x / (nsubdivs as f32)).cos() * 2.0
}
})
.collect();
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 = 26;
let rad = 0.5;
let shift = rad * 2.0;
let centerx = shift * (num / 2) as f32;
let centery = shift / 2.0;
for i in 0..num {
for j in 0usize..num * 5 {
let x = i as f32 * shift - centerx;
let y = j as f32 * shift + centery + 3.0;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
if j % 2 == 0 {
let collider = ColliderBuilder::cuboid(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(Vec2::new(0.0, 50.0), 10.0);
}

View File

@@ -0,0 +1,65 @@
use rapier_testbed2d::Testbed;
use rapier2d::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();
/*
* Create the balls
*/
// Build the rigid body.
let rad = 0.4;
let numi = 100; // Num vertical nodes.
let numk = 100; // Num horizontal nodes.
let shift = 1.0;
let mut body_handles = Vec::new();
for k in 0..numk {
for i in 0..numi {
let fk = k as f32;
let fi = i as f32;
let status = if k >= numk / 2 - 3 && k <= numk / 2 + 3 && i == 0 {
RigidBodyType::Fixed
} else {
RigidBodyType::Dynamic
};
let rigid_body =
RigidBodyBuilder::new(status).translation(Vec2::new(fk * shift, -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 = RevoluteJointBuilder::new().local_anchor2(Vec2::new(0.0, shift));
impulse_joints.insert(parent_handle, child_handle, joint, true);
}
// Horizontal joint.
if k > 0 {
let parent_index = body_handles.len() - numi;
let parent_handle = body_handles[parent_index];
let joint = RevoluteJointBuilder::new().local_anchor2(Vec2::new(-shift, 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(Vec2::new(numk as f32 * rad, numi as f32 * -rad), 5.0);
}

View File

@@ -0,0 +1,74 @@
use rapier_testbed2d::Testbed;
use rapier2d::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();
/*
* Create the balls
*/
// Build the rigid body.
let rad = 0.4;
let num = 30; // Num vertical nodes.
let shift = 1.0;
let mut body_handles = Vec::new();
for xx in 0..4 {
let x = xx as f32 * shift * (num as f32 + 2.0);
for yy in 0..4 {
let y = yy as f32 * shift * (num as f32 + 4.0);
for k in 0..num {
for i in 0..num {
let fk = k as f32;
let fi = i as f32;
let status = if k == 0 {
RigidBodyType::Fixed
} else {
RigidBodyType::Dynamic
};
let rigid_body = RigidBodyBuilder::new(status)
.translation(Vec2::new(x + fk * shift, y - 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_frame2(Pose2::translation(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_frame2(Pose2::translation(-shift, 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(Vec2::new(50.0, 50.0), 5.0);
}

View File

@@ -0,0 +1,61 @@
use rapier_testbed2d::Testbed;
use rapier2d::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();
/*
* Create the balls
*/
// Build the rigid body.
let rad = 0.4;
let num = 10;
let shift = 1.0;
for l in 0..25 {
let y = l as f32 * shift * (num as f32 + 2.0) * 2.0;
for j in 0..50 {
let x = j as f32 * shift * 4.0;
let ground = RigidBodyBuilder::fixed().translation(Vec2::new(x, y));
let mut curr_parent = bodies.insert(ground);
let collider = ColliderBuilder::cuboid(rad, rad);
colliders.insert_with_parent(collider, curr_parent, &mut bodies);
for i in 0..num {
let y = y - (i + 1) as f32 * shift;
let density = 1.0;
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let curr_child = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, rad).density(density);
colliders.insert_with_parent(collider, curr_child, &mut bodies);
let axis = if i % 2 == 0 {
Vec2::new(1.0, 1.0).normalize()
} else {
Vec2::new(-1.0, 1.0).normalize()
};
let prism = PrismaticJointBuilder::new(axis)
.local_anchor2(Vec2::new(0.0, shift))
.limits([-1.5, 1.5]);
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(Vec2::new(80.0, 80.0), 15.0);
}

View File

@@ -0,0 +1,37 @@
use rapier_testbed2d::Example;
mod balls2;
mod boxes2;
mod capsules2;
mod convex_polygons2;
mod heightfield2;
mod joint_ball2;
mod joint_fixed2;
mod joint_prismatic2;
mod pyramid2;
mod vertical_stacks2;
pub fn builders() -> Vec<Example> {
const STRESS: &str = "Stress Tests";
vec![
Example::new(STRESS, "Balls", balls2::init_world),
Example::new(STRESS, "Boxes", boxes2::init_world),
Example::new(STRESS, "Capsules", capsules2::init_world),
Example::new(STRESS, "Convex polygons", convex_polygons2::init_world),
Example::new(STRESS, "Heightfield", heightfield2::init_world),
Example::new(STRESS, "Pyramid", pyramid2::init_world),
Example::new(STRESS, "Verticals stacks", vertical_stacks2::init_world),
Example::new(STRESS, "(Stress test) joint ball", joint_ball2::init_world),
Example::new(
STRESS,
"(Stress test) joint fixed",
joint_fixed2::init_world,
),
Example::new(
STRESS,
"(Stress test) joint prismatic",
joint_prismatic2::init_world,
),
]
}

View File

@@ -0,0 +1,54 @@
use rapier_testbed2d::Testbed;
use rapier2d::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.0;
let ground_thickness = 1.0;
let rigid_body = RigidBodyBuilder::fixed();
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_thickness);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
/*
* Create the cubes
*/
let num = 100;
let rad = 0.5;
let shift = rad * 2.0;
let centerx = shift * (num as f32) / 2.0;
let centery = shift / 2.0 + ground_thickness + rad * 1.5;
for i in 0usize..num {
for j in i..num {
let fj = j as f32;
let fi = i as f32;
let x = (fi * shift / 2.0) + (fj - fi) * shift - centerx;
let y = fi * shift + centery;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, 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(Vec2::new(0.0, 2.5), 5.0);
}

View File

@@ -0,0 +1,61 @@
use rapier_testbed2d::Testbed;
use rapier2d::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();
let num = 80;
let rad = 0.5;
/*
* Ground
*/
let ground_size = num as f32 * rad * 10.0;
let ground_thickness = 1.0;
let rigid_body = RigidBodyBuilder::fixed();
let ground_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, ground_thickness);
colliders.insert_with_parent(collider, ground_handle, &mut bodies);
/*
* Create the cubes
*/
let shiftx_centerx = [
(rad * 2.0 + 0.0002, -(num as f32) * rad * 2.0 * 1.5),
(rad * 2.0 + rad, num as f32 * rad * 2.0 * 1.5),
];
for (shiftx, centerx) in shiftx_centerx {
let shifty = rad * 2.0;
let centery = shifty / 2.0 + ground_thickness;
for i in 0..num {
for j in 0usize..1 + i * 2 {
let fj = j as f32;
let fi = i as f32;
let x = (fj - fi) * shiftx + centerx;
let y = (num as f32 - fi - 1.0) * shifty + centery;
// Build the rigid body.
let rigid_body = RigidBodyBuilder::dynamic().translation(Vec2::new(x, y));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(rad, 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(Vec2::new(0.0, 2.5), 5.0);
}

View File

@@ -22,14 +22,14 @@ pub fn init_world(testbed: &mut Testbed) {
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(vector![ground_size, ground_size]);
.translation(Vector::new(ground_size, ground_size));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
let rigid_body = RigidBodyBuilder::fixed()
.rotation(std::f32::consts::FRAC_PI_2)
.translation(vector![-ground_size, ground_size]);
.translation(Vector::new(-ground_size, ground_size));
let handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(ground_size, 1.2);
colliders.insert_with_parent(collider, handle, &mut bodies);
@@ -45,7 +45,7 @@ pub fn init_world(testbed: &mut Testbed) {
.unwrap()
.contact_skin(0.2);
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![ith as f32 * 8.0 - 20.0, 20.0 + k as f32 * 11.0]);
.translation(Vector::new(ith as f32 * 8.0 - 20.0, 20.0 + k as f32 * 11.0));
let handle = bodies.insert(rigid_body);
colliders.insert_with_parent(collider, handle, &mut bodies);
}
@@ -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![0.0, 20.0], 17.0);
testbed.look_at(Vec2::new(0.0, 20.0), 17.0);
}

View File

@@ -1,7 +1,7 @@
use rapier_testbed2d::ui::egui::Align2;
use kiss3d::color::Color;
use rapier_testbed2d::{
KeyCode, PhysicsState, TestbedGraphics,
ui::egui::{ComboBox, Slider, Ui, Window},
egui::{Align2, ComboBox, Slider, Ui, Window},
};
use rapier2d::{
control::{CharacterLength, KinematicCharacterController, PidController},
@@ -51,24 +51,24 @@ 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;
for key in gfx.keys().get_pressed() {
match *key {
KeyCode::ArrowRight => {
desired_movement += Vector::x();
KeyCode::Right => {
desired_movement += Vector::X;
}
KeyCode::ArrowLeft => {
desired_movement -= Vector::x();
KeyCode::Left => {
desired_movement -= Vector::X;
}
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::ShiftRight => {
KeyCode::RShift => {
speed /= 10.0;
}
_ => {}
@@ -78,7 +78,7 @@ fn character_movement_from_inputs(
desired_movement *= speed;
if artificial_gravity {
desired_movement -= Vector::y() * speed;
desired_movement -= Vector::Y * speed;
}
desired_movement
@@ -97,11 +97,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 isnt 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_Z;
if desired_movement.norm() != 0.0 {
if desired_movement.length() != 0.0 {
axes |= if desired_movement.y == 0.0 {
AxesMask::LIN_X
} else {
@@ -114,7 +114,7 @@ fn update_pid_controller(
let corrective_vel = pid.rigid_body_correction(
phx.integration_parameters.dt,
character_body,
(character_body.translation() + desired_movement).into(),
Pose::from_translation(character_body.translation() + desired_movement),
RigidBodyVelocity::zero(),
);
let new_vel = *character_body.vels() + corrective_vel;
@@ -150,14 +150,14 @@ fn update_kinematic_controller(
&query_pipeline.as_ref(),
&*character_shape,
&character_collider_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), false);
} 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), false);
}
controller.solve_character_collision_impulses(
@@ -170,7 +170,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(
@@ -181,7 +181,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| {
@@ -220,9 +220,9 @@ 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.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 = ang_kp;
pid_controller.ang_ki = ang_ki;
pid_controller.pd.ang_kd = ang_kd;
@@ -240,12 +240,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 floors 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 floors 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));

View File

@@ -1,2 +1,4 @@
pub mod character;
#[cfg(not(target_arch = "wasm32"))]
pub mod svg;

View File

@@ -4,7 +4,6 @@ use lyon::math::Point;
use lyon::path::PathEvent;
use lyon::tessellation::geometry_builder::*;
use lyon::tessellation::{self, FillOptions, FillTessellator};
use rapier2d::na::{Point2, Rotation2};
use usvg::prelude::*;
const RAPIER_SVG_STR: &str = r#"
@@ -37,11 +36,11 @@ const RAPIER_SVG_STR: &str = r#"
</svg>
"#;
pub fn rapier_logo() -> Vec<(Vec<Point2<f32>>, Vec<[u32; 3]>)> {
pub fn rapier_logo() -> Vec<(Vec<Vector>, Vec<[u32; 3]>)> {
tessellate_svg_str(RAPIER_SVG_STR)
}
pub fn tessellate_svg_str(svg_str: &str) -> Vec<(Vec<Point2<f32>>, Vec<[u32; 3]>)> {
pub fn tessellate_svg_str(svg_str: &str) -> Vec<(Vec<Vector>, Vec<[u32; 3]>)> {
let mut result = vec![];
let mut fill_tess = FillTessellator::new();
let opt = usvg::Options::default();
@@ -80,7 +79,7 @@ pub fn tessellate_svg_str(svg_str: &str) -> Vec<(Vec<Point2<f32>>, Vec<[u32; 3]>
.vertices
.iter()
.map(|v| {
Rotation2::new(angle) * point![v.position[0] * sx, v.position[1] * -sy]
Rotation::new(angle) * Vector::new(v.position[0] * sx, v.position[1] * -sy)
})
.collect();

View File

@@ -39,12 +39,12 @@ pub fn init_world(testbed: &mut Testbed) {
let nx = 50;
for i in 0..nx {
for j in 0..10 {
let mut rb = RigidBodyBuilder::dynamic().translation(vector![
let mut rb = RigidBodyBuilder::dynamic().translation(Vector::new(
i as f32 * 2.0 - nx as f32 / 2.0,
20.0 + j as f32 * 2.0
]);
20.0 + j as f32 * 2.0,
));
if test_ccd {
rb = rb.linvel(vector![0.0, -1000.0]).ccd_enabled(true);
rb = rb.linvel(Vector::new(0.0, -1000.0)).ccd_enabled(true);
}
let rb_handle = bodies.insert(rb);
@@ -69,19 +69,19 @@ pub fn init_world(testbed: &mut Testbed) {
* Voxelization.
*/
let polyline = vec![
point![0.0, 0.0],
point![0.0, 10.0],
point![7.0, 4.0],
point![14.0, 10.0],
point![14.0, 0.0],
point![13.0, 7.0],
point![7.0, 2.0],
point![1.0, 7.0],
Vector::new(0.0, 0.0),
Vector::new(0.0, 10.0),
Vector::new(7.0, 4.0),
Vector::new(14.0, 10.0),
Vector::new(14.0, 0.0),
Vector::new(13.0, 7.0),
Vector::new(7.0, 2.0),
Vector::new(1.0, 7.0),
];
let indices: Vec<_> = (0..polyline.len() as u32)
.map(|i| [i, (i + 1) % polyline.len() as u32])
.collect();
let rb = bodies.insert(RigidBodyBuilder::fixed().translation(vector![-20.0, -10.0]));
let rb = bodies.insert(RigidBodyBuilder::fixed().translation(Vector::new(-20.0, -10.0)));
let shape = SharedShape::voxelized_mesh(&polyline, &indices, 0.2, FillMode::default());
colliders.insert_with_parent(ColliderBuilder::new(shape), rb, &mut bodies);
@@ -92,7 +92,7 @@ pub fn init_world(testbed: &mut Testbed) {
let voxels: Vec<_> = (0..300)
.map(|i| {
let y = (i as f32 / 20.0).sin().clamp(-0.5, 0.5) * 20.0;
point![(i as f32 - 125.0) * voxel_size.x / 2.0, y * voxel_size.y]
Vector::new((i as f32 - 125.0) * voxel_size.x / 2.0, y * voxel_size.y)
})
.collect();
colliders.insert(ColliderBuilder::voxels_from_points(voxel_size, &voxels));
@@ -101,5 +101,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, 20.0], 17.0);
testbed.look_at(Vec2::new(0.0, 20.0), 17.0);
}