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