Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/godot_physics_3d/joints/godot_hinge_joint_3d.h
10278 views
1
/**************************************************************************/
2
/* godot_hinge_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
/*
34
Adapted to Godot from the Bullet library.
35
*/
36
37
#include "../godot_joint_3d.h"
38
#include "godot_jacobian_entry_3d.h"
39
40
/*
41
Bullet Continuous Collision Detection and Physics Library
42
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
43
44
This software is provided 'as-is', without any express or implied warranty.
45
In no event will the authors be held liable for any damages arising from the use of this software.
46
Permission is granted to anyone to use this software for any purpose,
47
including commercial applications, and to alter it and redistribute it freely,
48
subject to the following restrictions:
49
50
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
51
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
52
3. This notice may not be removed or altered from any source distribution.
53
*/
54
55
class GodotHingeJoint3D : public GodotJoint3D {
56
union {
57
struct {
58
GodotBody3D *A;
59
GodotBody3D *B;
60
};
61
62
GodotBody3D *_arr[2] = {};
63
};
64
65
GodotJacobianEntry3D m_jac[3]; //3 orthogonal linear constraints
66
GodotJacobianEntry3D m_jacAng[3]; //2 orthogonal angular constraints+ 1 for limit/motor
67
68
Transform3D m_rbAFrame; // constraint axii. Assumes z is hinge axis.
69
Transform3D m_rbBFrame;
70
71
real_t m_motorTargetVelocity = 0.0;
72
real_t m_maxMotorImpulse = 0.0;
73
74
real_t m_limitSoftness = 0.9;
75
real_t m_biasFactor = 0.3;
76
real_t m_relaxationFactor = 1.0;
77
78
real_t m_lowerLimit = Math::PI;
79
real_t m_upperLimit = -Math::PI;
80
81
real_t m_kHinge = 0.0;
82
83
real_t m_limitSign = 0.0;
84
real_t m_correction = 0.0;
85
86
real_t m_accLimitImpulse = 0.0;
87
88
real_t tau = 0.3;
89
90
bool m_useLimit = false;
91
bool m_angularOnly = false;
92
bool m_enableAngularMotor = false;
93
bool m_solveLimit = false;
94
95
real_t m_appliedImpulse = 0.0;
96
97
public:
98
virtual PhysicsServer3D::JointType get_type() const override { return PhysicsServer3D::JOINT_TYPE_HINGE; }
99
100
virtual bool setup(real_t p_step) override;
101
virtual void solve(real_t p_step) override;
102
103
real_t get_hinge_angle();
104
105
void set_param(PhysicsServer3D::HingeJointParam p_param, real_t p_value);
106
real_t get_param(PhysicsServer3D::HingeJointParam p_param) const;
107
108
void set_flag(PhysicsServer3D::HingeJointFlag p_flag, bool p_value);
109
bool get_flag(PhysicsServer3D::HingeJointFlag p_flag) const;
110
111
GodotHingeJoint3D(GodotBody3D *rbA, GodotBody3D *rbB, const Transform3D &frameA, const Transform3D &frameB);
112
GodotHingeJoint3D(GodotBody3D *rbA, GodotBody3D *rbB, const Vector3 &pivotInA, const Vector3 &pivotInB, const Vector3 &axisInA, const Vector3 &axisInB);
113
};
114
115