1 | /**************************************************************************/ |
2 | /* godot_pin_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_PIN_JOINT_3D_H |
32 | #define GODOT_PIN_JOINT_3D_H |
33 | |
34 | /* |
35 | Adapted 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 | /* |
42 | Bullet Continuous Collision Detection and Physics Library |
43 | Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ |
44 | |
45 | This software is provided 'as-is', without any express or implied warranty. |
46 | In no event will the authors be held liable for any damages arising from the use of this software. |
47 | Permission is granted to anyone to use this software for any purpose, |
48 | including commercial applications, and to alter it and redistribute it freely, |
49 | subject to the following restrictions: |
50 | |
51 | 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. |
52 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. |
53 | 3. This notice may not be removed or altered from any source distribution. |
54 | */ |
55 | |
56 | class GodotPinJoint3D : public GodotJoint3D { |
57 | union { |
58 | struct { |
59 | GodotBody3D *A; |
60 | GodotBody3D *B; |
61 | }; |
62 | |
63 | GodotBody3D *_arr[2] = {}; |
64 | }; |
65 | |
66 | real_t m_tau = 0.3; //bias |
67 | real_t m_damping = 1.0; |
68 | real_t m_impulseClamp = 0.0; |
69 | real_t m_appliedImpulse = 0.0; |
70 | |
71 | GodotJacobianEntry3D m_jac[3] = {}; //3 orthogonal linear constraints |
72 | |
73 | Vector3 m_pivotInA; |
74 | Vector3 m_pivotInB; |
75 | |
76 | public: |
77 | virtual PhysicsServer3D::JointType get_type() const override { return PhysicsServer3D::JOINT_TYPE_PIN; } |
78 | |
79 | virtual bool setup(real_t p_step) override; |
80 | virtual void solve(real_t p_step) override; |
81 | |
82 | void set_param(PhysicsServer3D::PinJointParam p_param, real_t p_value); |
83 | real_t get_param(PhysicsServer3D::PinJointParam p_param) const; |
84 | |
85 | void set_pos_a(const Vector3 &p_pos) { m_pivotInA = p_pos; } |
86 | void set_pos_b(const Vector3 &p_pos) { m_pivotInB = p_pos; } |
87 | |
88 | Vector3 get_position_a() { return m_pivotInA; } |
89 | Vector3 get_position_b() { return m_pivotInB; } |
90 | |
91 | GodotPinJoint3D(GodotBody3D *p_body_a, const Vector3 &p_pos_a, GodotBody3D *p_body_b, const Vector3 &p_pos_b); |
92 | ~GodotPinJoint3D(); |
93 | }; |
94 | |
95 | #endif // GODOT_PIN_JOINT_3D_H |
96 | |