Debian Codegraph @

editor/scene/3d/gizmos/physics/vehicle_body_3d_gizmo_plugin.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* vehicle_body_3d_gizmo_plugin.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 "vehicle_body_3d_gizmo_plugin.h"
32
33 #include "scene/3d/physics/vehicle_body_3d.h"
34
35 VehicleWheel3DGizmoPlugin::VehicleWheel3DGizmoPlugin() {
36 Color gizmo_color = SceneTree::get_singleton()->get_debug_collisions_color();
37 create_material("shape_material", gizmo_color);
38 }
39
40 bool VehicleWheel3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
41 return Object::cast_to<VehicleWheel3D>(p_spatial) != nullptr;
42 }
43
44 String VehicleWheel3DGizmoPlugin::get_gizmo_name() const {
45 return "VehicleWheel3D";
46 }
47
48 int VehicleWheel3DGizmoPlugin::get_priority() const {
49 return -1;
50 }
51
52 void VehicleWheel3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
53 VehicleWheel3D *car_wheel = Object::cast_to<VehicleWheel3D>(p_gizmo->get_node_3d());
54
55 p_gizmo->clear();
56
57 Vector<Vector3> points;
58
59 float r = car_wheel->get_radius();
60 const int skip = 10;
61 for (int i = 0; i <= 360; i += skip) {
62 float ra = Math::deg_to_rad((float)i);
63 float rb = Math::deg_to_rad((float)i + skip);
64 Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
65 Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
66
67 points.push_back(Vector3(0, a.x, a.y));
68 points.push_back(Vector3(0, b.x, b.y));
69
70 const int springsec = 4;
71
72 for (int j = 0; j < springsec; j++) {
73 float t = car_wheel->get_suspension_rest_length() * 5;
74 points.push_back(Vector3(a.x, i / 360.0 * t / springsec + j * (t / springsec), a.y) * 0.2);
75 points.push_back(Vector3(b.x, (i + skip) / 360.0 * t / springsec + j * (t / springsec), b.y) * 0.2);
76 }
77 }
78
79 //travel
80 points.push_back(Vector3(0, 0, 0));
81 points.push_back(Vector3(0, car_wheel->get_suspension_rest_length(), 0));
82
83 //axis
84 points.push_back(Vector3(r * 0.2, car_wheel->get_suspension_rest_length(), 0));
85 points.push_back(Vector3(-r * 0.2, car_wheel->get_suspension_rest_length(), 0));
86 //axis
87 points.push_back(Vector3(r * 0.2, 0, 0));
88 points.push_back(Vector3(-r * 0.2, 0, 0));
89
90 //forward line
91 points.push_back(Vector3(0, -r, 0));
92 points.push_back(Vector3(0, -r, r * 2));
93 points.push_back(Vector3(0, -r, r * 2));
94 points.push_back(Vector3(r * 2 * 0.2, -r, r * 2 * 0.8));
95 points.push_back(Vector3(0, -r, r * 2));
96 points.push_back(Vector3(-r * 2 * 0.2, -r, r * 2 * 0.8));
97
98 Ref<Material> material = get_material("shape_material", p_gizmo);
99
100 p_gizmo->add_lines(points, material);
101 p_gizmo->add_collision_segments(points);
102 }