| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "../jolt_physics_server_3d.h" |
| 34 |
#include "jolt_joint_3d.h" |
| 35 |
|
| 36 |
#include "Jolt/Jolt.h" |
| 37 |
|
| 38 |
#include "Jolt/Physics/Constraints/SliderConstraint.h" |
| 39 |
|
| 40 |
class JoltSliderJoint3D final : public JoltJoint3D { |
| 41 |
typedef PhysicsServer3D::SliderJointParam Parameter; |
| 42 |
typedef JoltPhysicsServer3D::SliderJointParamJolt JoltParameter; |
| 43 |
typedef JoltPhysicsServer3D::SliderJointFlagJolt JoltFlag; |
| 44 |
|
| 45 |
double limit_upper = 0.0; |
| 46 |
double limit_lower = 0.0; |
| 47 |
|
| 48 |
double limit_spring_frequency = 0.0; |
| 49 |
double limit_spring_damping = 0.0; |
| 50 |
|
| 51 |
double motor_target_speed = 0.0f; |
| 52 |
double motor_max_force = FLT_MAX; |
| 53 |
|
| 54 |
bool limits_enabled = true; |
| 55 |
bool limit_spring_enabled = false; |
| 56 |
|
| 57 |
bool motor_enabled = false; |
| 58 |
|
| 59 |
JPH::Constraint *_build_slider(JPH::Body *p_jolt_body_a, JPH::Body *p_jolt_body_b, const Transform3D &p_shifted_ref_a, const Transform3D &p_shifted_ref_b, float p_limit) const; |
| 60 |
JPH::Constraint *_build_fixed(JPH::Body *p_jolt_body_a, JPH::Body *p_jolt_body_b, const Transform3D &p_shifted_ref_a, const Transform3D &p_shifted_ref_b) const; |
| 61 |
|
| 62 |
bool _is_sprung() const { return limit_spring_enabled && limit_spring_frequency > 0.0; } |
| 63 |
bool _is_fixed() const { return limits_enabled && limit_lower == limit_upper && !_is_sprung(); } |
| 64 |
|
| 65 |
void _update_motor_state(); |
| 66 |
void _update_motor_velocity(); |
| 67 |
void _update_motor_limit(); |
| 68 |
|
| 69 |
void _limits_changed(); |
| 70 |
void _limit_spring_changed(); |
| 71 |
void _motor_state_changed(); |
| 72 |
void _motor_speed_changed(); |
| 73 |
void _motor_limit_changed(); |
| 74 |
|
| 75 |
public: |
| 76 |
JoltSliderJoint3D(const JoltJoint3D &p_old_joint, JoltBody3D *p_body_a, JoltBody3D *p_body_b, const Transform3D &p_local_ref_a, const Transform3D &p_local_ref_b); |
| 77 |
|
| 78 |
virtual PhysicsServer3D::JointType get_type() const override { return PhysicsServer3D::JOINT_TYPE_SLIDER; } |
| 79 |
|
| 80 |
double get_param(PhysicsServer3D::SliderJointParam p_param) const; |
| 81 |
void set_param(PhysicsServer3D::SliderJointParam p_param, double p_value); |
| 82 |
|
| 83 |
double get_jolt_param(JoltParameter p_param) const; |
| 84 |
void set_jolt_param(JoltParameter p_param, double p_value); |
| 85 |
|
| 86 |
bool get_jolt_flag(JoltFlag p_flag) const; |
| 87 |
void set_jolt_flag(JoltFlag p_flag, bool p_enabled); |
| 88 |
|
| 89 |
float get_applied_force() const; |
| 90 |
float get_applied_torque() const; |
| 91 |
|
| 92 |
virtual void rebuild() override; |
| 93 |
}; |