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:
@@ -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 can’t 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 can’t 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 isn’t 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user