Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/jolt_physics/joints/jolt_generic_6dof_joint_3d.h
10278 views
1
/**************************************************************************/
2
/* jolt_generic_6dof_joint_3d.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
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
};
125
126