1/**************************************************************************/
2/* joint_3d_gizmo_plugin.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 JOINT_3D_GIZMO_PLUGIN_H
32#define JOINT_3D_GIZMO_PLUGIN_H
33
34#include "editor/plugins/node_3d_editor_gizmos.h"
35
36class Joint3DGizmoPlugin : public EditorNode3DGizmoPlugin {
37 GDCLASS(Joint3DGizmoPlugin, EditorNode3DGizmoPlugin);
38
39 Timer *update_timer = nullptr;
40 uint64_t update_idx = 0;
41
42 void incremental_update_gizmos();
43
44public:
45 bool has_gizmo(Node3D *p_spatial) override;
46 String get_gizmo_name() const override;
47 int get_priority() const override;
48 void redraw(EditorNode3DGizmo *p_gizmo) override;
49
50 static void CreatePinJointGizmo(const Transform3D &p_offset, Vector<Vector3> &r_cursor_points);
51 static void CreateHingeJointGizmo(const Transform3D &p_offset, const Transform3D &p_trs_joint, const Transform3D &p_trs_body_a, const Transform3D &p_trs_body_b, real_t p_limit_lower, real_t p_limit_upper, bool p_use_limit, Vector<Vector3> &r_common_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
52 static void CreateSliderJointGizmo(const Transform3D &p_offset, const Transform3D &p_trs_joint, const Transform3D &p_trs_body_a, const Transform3D &p_trs_body_b, real_t p_angular_limit_lower, real_t p_angular_limit_upper, real_t p_linear_limit_lower, real_t p_linear_limit_upper, Vector<Vector3> &r_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
53 static void CreateConeTwistJointGizmo(const Transform3D &p_offset, const Transform3D &p_trs_joint, const Transform3D &p_trs_body_a, const Transform3D &p_trs_body_b, real_t p_swing, real_t p_twist, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points);
54 static void CreateGeneric6DOFJointGizmo(
55 const Transform3D &p_offset,
56 const Transform3D &p_trs_joint,
57 const Transform3D &p_trs_body_a,
58 const Transform3D &p_trs_body_b,
59 real_t p_angular_limit_lower_x,
60 real_t p_angular_limit_upper_x,
61 real_t p_linear_limit_lower_x,
62 real_t p_linear_limit_upper_x,
63 bool p_enable_angular_limit_x,
64 bool p_enable_linear_limit_x,
65 real_t p_angular_limit_lower_y,
66 real_t p_angular_limit_upper_y,
67 real_t p_linear_limit_lower_y,
68 real_t p_linear_limit_upper_y,
69 bool p_enable_angular_limit_y,
70 bool p_enable_linear_limit_y,
71 real_t p_angular_limit_lower_z,
72 real_t p_angular_limit_upper_z,
73 real_t p_linear_limit_lower_z,
74 real_t p_linear_limit_upper_z,
75 bool p_enable_angular_limit_z,
76 bool p_enable_linear_limit_z,
77 Vector<Vector3> &r_points,
78 Vector<Vector3> *r_body_a_points,
79 Vector<Vector3> *r_body_b_points);
80
81 Joint3DGizmoPlugin();
82};
83
84class JointGizmosDrawer {
85public:
86 static Basis look_body(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
87 static Basis look_body_toward(Vector3::Axis p_axis, const Transform3D &joint_transform, const Transform3D &body_transform);
88 static Basis look_body_toward_x(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
89 static Basis look_body_toward_y(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
90 /// Special function just used for physics joints, it returns a basis constrained toward Joint Z axis
91 /// with axis X and Y that are looking toward the body and oriented toward up
92 static Basis look_body_toward_z(const Transform3D &p_joint_transform, const Transform3D &p_body_transform);
93
94 // Draw circle around p_axis
95 static void draw_circle(Vector3::Axis p_axis, real_t p_radius, const Transform3D &p_offset, const Basis &p_base, real_t p_limit_lower, real_t p_limit_upper, Vector<Vector3> &r_points, bool p_inverse = false);
96 static void draw_cone(const Transform3D &p_offset, const Basis &p_base, real_t p_swing, real_t p_twist, Vector<Vector3> &r_points);
97};
98
99#endif // JOINT_3D_GIZMO_PLUGIN_H
100