Debian Codegraph @

modules/godot_physics_3d/godot_joint_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* godot_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 "godot_body_3d.h"
34 #include "godot_constraint_3d.h"
35
36 class GodotJoint3D : public GodotConstraint3D {
37 protected:
38 bool dynamic_A = false;
39 bool dynamic_B = false;
40
41 void plane_space(const Vector3 &n, Vector3 &p, Vector3 &q) {
42 if (Math::abs(n.z) > Math::SQRT12) {
43 // choose p in y-z plane
44 real_t a = n[1] * n[1] + n[2] * n[2];
45 real_t k = 1.0 / Math::sqrt(a);
46 p = Vector3(0, -n[2] * k, n[1] * k);
47 // set q = n x p
48 q = Vector3(a * k, -n[0] * p[2], n[0] * p[1]);
49 } else {
50 // choose p in x-y plane
51 real_t a = n.x * n.x + n.y * n.y;
52 real_t k = 1.0 / Math::sqrt(a);
53 p = Vector3(-n.y * k, n.x * k, 0);
54 // set q = n x p
55 q = Vector3(-n.z * p.y, n.z * p.x, a * k);
56 }
57 }
58
59 _FORCE_INLINE_ real_t atan2fast(real_t y, real_t x) {
60 real_t coeff_1 = Math::PI / 4.0f;
61 real_t coeff_2 = 3.0f * coeff_1;
62 real_t abs_y = Math::abs(y);
63 real_t angle;
64 if (x >= 0.0f) {
65 real_t r = (x - abs_y) / (x + abs_y);
66 angle = coeff_1 - coeff_1 * r;
67 } else {
68 real_t r = (x + abs_y) / (abs_y - x);
69 angle = coeff_2 - coeff_1 * r;
70 }
71 return (y < 0.0f) ? -angle : angle;
72 }
73
74 public:
75 virtual bool setup(real_t p_step) override { return false; }
76 virtual bool pre_solve(real_t p_step) override { return true; }
77 virtual void solve(real_t p_step) override {}
78
79 void copy_settings_from(GodotJoint3D *p_joint) {
80 set_self(p_joint->get_self());
81 set_priority(p_joint->get_priority());
82 disable_collisions_between_bodies(p_joint->is_disabled_collisions_between_bodies());
83 }
84
85 virtual PhysicsServer3D::JointType get_type() const { return PhysicsServer3D::JOINT_TYPE_MAX; }
86 _FORCE_INLINE_ GodotJoint3D(GodotBody3D **p_body_ptr = nullptr, int p_body_count = 0) :
87 GodotConstraint3D(p_body_ptr, p_body_count) {
88 }
89
90 virtual ~GodotJoint3D() {
91 for (int i = 0; i < get_body_count(); i++) {
92 GodotBody3D *body = get_body_ptr()[i];
93 if (body) {
94 body->remove_constraint(this);
95 }
96 }
97 }
98 };