Debian Codegraph @

scene/3d/physics/joints/cone_twist_joint_3d.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* cone_twist_joint_3d.cpp */
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 #include "cone_twist_joint_3d.h"
32
33 void ConeTwistJoint3D::_bind_methods() {
34 ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &ConeTwistJoint3D::set_param);
35 ClassDB::bind_method(D_METHOD("get_param", "param"), &ConeTwistJoint3D::get_param);
36
37 ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "swing_span", PROPERTY_HINT_RANGE, "-180,180,0.1,radians_as_degrees"), "set_param", "get_param", PARAM_SWING_SPAN);
38 ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "twist_span", PROPERTY_HINT_RANGE, "-40000,40000,0.1,radians_as_degrees"), "set_param", "get_param", PARAM_TWIST_SPAN);
39
40 ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "bias", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_BIAS);
41 ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "softness", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_SOFTNESS);
42 ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "relaxation", PROPERTY_HINT_RANGE, "0.01,16.0,0.01"), "set_param", "get_param", PARAM_RELAXATION);
43
44 BIND_ENUM_CONSTANT(PARAM_SWING_SPAN);
45 BIND_ENUM_CONSTANT(PARAM_TWIST_SPAN);
46 BIND_ENUM_CONSTANT(PARAM_BIAS);
47 BIND_ENUM_CONSTANT(PARAM_SOFTNESS);
48 BIND_ENUM_CONSTANT(PARAM_RELAXATION);
49 BIND_ENUM_CONSTANT(PARAM_MAX);
50 }
51
52 void ConeTwistJoint3D::set_param(Param p_param, real_t p_value) {
53 ERR_FAIL_INDEX(p_param, PARAM_MAX);
54 params[p_param] = p_value;
55 if (is_configured()) {
56 PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(get_rid(), PhysicsServer3D::ConeTwistJointParam(p_param), p_value);
57 }
58
59 update_gizmos();
60 }
61
62 real_t ConeTwistJoint3D::get_param(Param p_param) const {
63 ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
64 return params[p_param];
65 }
66
67 void ConeTwistJoint3D::_configure_joint(RID p_joint, PhysicsBody3D *body_a, PhysicsBody3D *body_b) {
68 Transform3D gt = get_global_transform();
69
70 Transform3D ainv = body_a->get_global_transform().affine_inverse();
71
72 Transform3D local_a = ainv * gt;
73 local_a.orthonormalize();
74 Transform3D local_b = gt;
75
76 if (body_b) {
77 Transform3D binv = body_b->get_global_transform().affine_inverse();
78 local_b = binv * gt;
79 }
80
81 local_b.orthonormalize();
82
83 PhysicsServer3D::get_singleton()->joint_make_cone_twist(p_joint, body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b);
84 for (int i = 0; i < PARAM_MAX; i++) {
85 PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(p_joint, PhysicsServer3D::ConeTwistJointParam(i), params[i]);
86 }
87 }
88
89 ConeTwistJoint3D::ConeTwistJoint3D() {
90 params[PARAM_SWING_SPAN] = Math::PI * 0.25;
91 params[PARAM_TWIST_SPAN] = Math::PI;
92 params[PARAM_BIAS] = 0.3;
93 params[PARAM_SOFTNESS] = 0.8;
94 params[PARAM_RELAXATION] = 1.0;
95 }