| 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/SixDOFConstraint.h" |
| 39 |
|
| 40 |
class JoltGeneric6DOFJoint3D final : public JoltJoint3D { |
| 41 |
typedef Vector3::Axis Axis; |
| 42 |
typedef JPH::SixDOFConstraintSettings::EAxis JoltAxis; |
| 43 |
typedef PhysicsServer3D::G6DOFJointAxisParam Param; |
| 44 |
typedef JoltPhysicsServer3D::G6DOFJointAxisParamJolt JoltParam; |
| 45 |
typedef PhysicsServer3D::G6DOFJointAxisFlag Flag; |
| 46 |
typedef JoltPhysicsServer3D::G6DOFJointAxisFlagJolt JoltFlag; |
| 47 |
|
| 48 |
enum { |
| 49 |
AXIS_LINEAR_X = JoltAxis::TranslationX, |
| 50 |
AXIS_LINEAR_Y = JoltAxis::TranslationY, |
| 51 |
AXIS_LINEAR_Z = JoltAxis::TranslationZ, |
| 52 |
AXIS_ANGULAR_X = JoltAxis::RotationX, |
| 53 |
AXIS_ANGULAR_Y = JoltAxis::RotationY, |
| 54 |
AXIS_ANGULAR_Z = JoltAxis::RotationZ, |
| 55 |
AXIS_COUNT = JoltAxis::Num, |
| 56 |
AXES_LINEAR = AXIS_LINEAR_X, |
| 57 |
AXES_ANGULAR = AXIS_ANGULAR_X, |
| 58 |
}; |
| 59 |
|
| 60 |
double limit_lower[AXIS_COUNT] = {}; |
| 61 |
double limit_upper[AXIS_COUNT] = {}; |
| 62 |
|
| 63 |
double limit_spring_frequency[AXIS_COUNT] = {}; |
| 64 |
double limit_spring_damping[AXIS_COUNT] = {}; |
| 65 |
|
| 66 |
double motor_speed[AXIS_COUNT] = {}; |
| 67 |
double motor_limit[AXIS_COUNT] = { FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX }; |
| 68 |
|
| 69 |
double spring_stiffness[AXIS_COUNT] = {}; |
| 70 |
double spring_frequency[AXIS_COUNT] = {}; |
| 71 |
double spring_damping[AXIS_COUNT] = {}; |
| 72 |
double spring_equilibrium[AXIS_COUNT] = {}; |
| 73 |
double spring_limit[AXIS_COUNT] = { FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX }; |
| 74 |
|
| 75 |
bool limit_enabled[AXIS_COUNT] = {}; |
| 76 |
|
| 77 |
bool limit_spring_enabled[AXIS_COUNT] = {}; |
| 78 |
|
| 79 |
bool motor_enabled[AXIS_COUNT] = {}; |
| 80 |
|
| 81 |
bool spring_enabled[AXIS_COUNT] = {}; |
| 82 |
bool spring_use_frequency[AXIS_COUNT] = {}; |
| 83 |
|
| 84 |
JPH::Constraint *_build_6dof(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; |
| 85 |
|
| 86 |
void _update_limit_spring_parameters(int p_axis); |
| 87 |
void _update_motor_state(int p_axis); |
| 88 |
void _update_motor_velocity(int p_axis); |
| 89 |
void _update_motor_limit(int p_axis); |
| 90 |
void _update_spring_parameters(int p_axis); |
| 91 |
void _update_spring_equilibrium(int p_axis); |
| 92 |
|
| 93 |
void _limits_changed(); |
| 94 |
void _limit_spring_parameters_changed(int p_axis); |
| 95 |
void _motor_state_changed(int p_axis); |
| 96 |
void _motor_speed_changed(int p_axis); |
| 97 |
void _motor_limit_changed(int p_axis); |
| 98 |
void _spring_state_changed(int p_axis); |
| 99 |
void _spring_parameters_changed(int p_axis); |
| 100 |
void _spring_equilibrium_changed(int p_axis); |
| 101 |
void _spring_limit_changed(int p_axis); |
| 102 |
|
| 103 |
public: |
| 104 |
JoltGeneric6DOFJoint3D(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); |
| 105 |
|
| 106 |
virtual PhysicsServer3D::JointType get_type() const override { return PhysicsServer3D::JOINT_TYPE_6DOF; } |
| 107 |
|
| 108 |
double get_param(Axis p_axis, Param p_param) const; |
| 109 |
void set_param(Axis p_axis, Param p_param, double p_value); |
| 110 |
|
| 111 |
bool get_flag(Axis p_axis, Flag p_flag) const; |
| 112 |
void set_flag(Axis p_axis, Flag p_flag, bool p_enabled); |
| 113 |
|
| 114 |
double get_jolt_param(Axis p_axis, JoltParam p_param) const; |
| 115 |
void set_jolt_param(Axis p_axis, JoltParam p_param, double p_value); |
| 116 |
|
| 117 |
bool get_jolt_flag(Axis p_axis, JoltFlag p_flag) const; |
| 118 |
void set_jolt_flag(Axis p_axis, JoltFlag p_flag, bool p_enabled); |
| 119 |
|
| 120 |
float get_applied_force() const; |
| 121 |
float get_applied_torque() const; |
| 122 |
|
| 123 |
virtual void rebuild() override; |
| 124 |
}; |