From 90a8e1df3e215596d394bc2d3ffe14dc33b61bf1 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Tue, 2 Apr 2024 16:26:19 +0200 Subject: [PATCH] fix params to work for spring joint (#49) --- godot-rapier.code-workspace | 2 +- scripts/build-dev.sh | 4 ++-- scripts/build.sh | 4 ++-- src/joints/rapier_damped_spring_joint_2d.cpp | 2 +- src/rapier2d-wrapper/src/joint.rs | 11 ++++++----- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/godot-rapier.code-workspace b/godot-rapier.code-workspace index b41a3941..ec0fa9a8 100644 --- a/godot-rapier.code-workspace +++ b/godot-rapier.code-workspace @@ -11,7 +11,7 @@ ], "settings": { "rust-analyzer.linkedProjects": [ - "${workspaceFolder:godot-rapier-2d}/src/rapier2d-wrapper/Cargo.toml" + "../godot-rapier-2d/src/rapier2d-wrapper/Cargo.toml" ], "rust-analyzer.showUnlinkedFileNotification": false, "lldb.launch.sourceMap": { diff --git a/scripts/build-dev.sh b/scripts/build-dev.sh index 24e1f248..864f1733 100755 --- a/scripts/build-dev.sh +++ b/scripts/build-dev.sh @@ -3,6 +3,6 @@ cargo build --features="single,simd-stable,serde-serialize,parallel" cd ../.. scons arch=arm64 target=template_debug debug_symbols=yes dev_build=yes -rm -rf Godot-Physics-Tests/addons -cp -rf bin/addons Godot-Physics-Tests/addons +rm -rf Godot-Physics-Tests/addons/godot-rapier2d +cp -rf bin/addons/godot-rapier2d Godot-Physics-Tests/addons/godot-rapier2d diff --git a/scripts/build.sh b/scripts/build.sh index c4786188..4520a9b6 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,6 +3,6 @@ cargo build --release --features="single,simd-stable,parallel" cd ../.. scons arch=arm64 target=template_debug debug_symbols=yes -rm -rf Godot-Physics-Tests/addons -cp -rf bin/addons Godot-Physics-Tests/addons +rm -rf Godot-Physics-Tests/addons/godot-rapier2d +cp -rf bin/addons/godot-rapier2d Godot-Physics-Tests/addons/godot-rapier2d diff --git a/src/joints/rapier_damped_spring_joint_2d.cpp b/src/joints/rapier_damped_spring_joint_2d.cpp index de7911e6..c8646a10 100644 --- a/src/joints/rapier_damped_spring_joint_2d.cpp +++ b/src/joints/rapier_damped_spring_joint_2d.cpp @@ -13,7 +13,7 @@ void RapierDampedSpringJoint2D::set_param(PhysicsServer2D::DampedSpringParam p_p stiffness = p_value; } break; } - rapier2d::joint_change_spring_params(space_handle, handle, rest_length, damping, stiffness); + rapier2d::joint_change_spring_params(space_handle, handle, stiffness, damping, rest_length); } real_t RapierDampedSpringJoint2D::get_param(PhysicsServer2D::DampedSpringParam p_param) const { diff --git a/src/rapier2d-wrapper/src/joint.rs b/src/rapier2d-wrapper/src/joint.rs index 9def0ffe..2afb3696 100644 --- a/src/rapier2d-wrapper/src/joint.rs +++ b/src/rapier2d-wrapper/src/joint.rs @@ -41,9 +41,11 @@ pub extern "C" fn joint_change_revolute_params(world_handle : Handle, joint_hand assert!(joint.is_some()); let joint = joint.unwrap().data.as_revolute_mut(); assert!(joint.is_some()); - let mut joint = joint.unwrap(); + let joint = joint.unwrap(); if motor_enabled { - joint = joint.set_motor_velocity(motor_target_velocity, 0.0); + joint.set_motor_velocity(motor_target_velocity, 0.0); + } else { + joint.set_motor_velocity(0.0, 0.0); } if angular_limit_enabled { joint.set_limits([angular_limit_lower, angular_limit_upper]); @@ -81,7 +83,6 @@ pub extern "C" fn joint_create_spring(world_handle : Handle, body_handle_1 : Han .local_anchor1(point!(anchor_1.x, anchor_1.y)) .local_anchor2(point!(anchor_2.x, anchor_2.y)) .contacts_enabled(!disable_collision); - return physics_world.insert_joint(body_handle_1, body_handle_2, joint); } @@ -94,8 +95,8 @@ pub extern "C" fn joint_change_spring_params(world_handle : Handle, joint_handle let joint = physics_world.impulse_joint_set.get_mut(handle_to_joint_handle(joint_handle)); assert!(joint.is_some()); - let mut joint = joint.unwrap().data; - joint.set_motor_position(JointAxis::X, rest_length, stiffness, damping); + let spring_joint = joint.unwrap(); + spring_joint.data.set_motor_position(JointAxis::X, rest_length, stiffness, damping); } #[no_mangle]