Skip to content

Commit

Permalink
fix params to work for spring joint (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Apr 2, 2024
1 parent a262534 commit 90a8e1d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion godot-rapier.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion src/joints/rapier_damped_spring_joint_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions src/rapier2d-wrapper/src/joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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]
Expand Down

0 comments on commit 90a8e1d

Please sign in to comment.