Debian Codegraph @

modules/jolt_physics/objects/jolt_shaped_object_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* jolt_shaped_object_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 "jolt_object_3d.h"
34
35 #include "core/templates/self_list.h"
36
37 #include "Jolt/Jolt.h"
38
39 #include "Jolt/Physics/Body/Body.h"
40 #include "Jolt/Physics/Body/BodyCreationSettings.h"
41
42 class JoltShapedObject3D : public JoltObject3D {
43 friend class JoltShape3D;
44
45 protected:
46 SelfList<JoltShapedObject3D> shapes_changed_element;
47 SelfList<JoltShapedObject3D> needs_optimization_element;
48
49 Vector3 scale = Vector3(1, 1, 1);
50
51 JPH::ShapeRefC jolt_shape;
52 JPH::ShapeRefC previous_jolt_shape;
53
54 JPH::BodyCreationSettings *jolt_settings = new JPH::BodyCreationSettings();
55
56 virtual JPH::EMotionType _get_motion_type() const = 0;
57
58 bool _is_big() const;
59
60 JPH::ShapeRefC _try_build_shape(bool p_optimize_compound);
61 JPH::ShapeRefC _try_build_single_shape();
62 JPH::ShapeRefC _try_build_compound_shape(bool p_optimize);
63
64 void _enqueue_shapes_changed();
65 void _dequeue_shapes_changed();
66
67 void _enqueue_needs_optimization();
68 void _dequeue_needs_optimization();
69
70 virtual void _shapes_changed();
71 virtual void _shapes_committed();
72 virtual void _space_changing() override;
73
74 public:
75 explicit JoltShapedObject3D(ObjectType p_object_type);
76 virtual ~JoltShapedObject3D() override;
77
78 Transform3D get_transform_unscaled() const;
79 Transform3D get_transform_scaled() const;
80
81 Vector3 get_scale() const { return scale; }
82 Basis get_basis() const;
83 Vector3 get_position() const;
84
85 Vector3 get_center_of_mass() const;
86 Vector3 get_center_of_mass_relative() const;
87 Vector3 get_center_of_mass_local() const;
88
89 Vector3 get_linear_velocity() const;
90 Vector3 get_angular_velocity() const;
91
92 AABB get_aabb() const;
93
94 virtual bool has_custom_center_of_mass() const = 0;
95 virtual Vector3 get_center_of_mass_custom() const = 0;
96
97 JPH::ShapeRefC build_shapes(bool p_optimize_compound);
98
99 void commit_shapes(bool p_optimize_compound);
100
101 const JPH::Shape *get_jolt_shape() const { return jolt_shape; }
102 const JPH::Shape *get_previous_jolt_shape() const { return previous_jolt_shape; }
103
104 void add_shape(JoltShape3D *p_shape, Transform3D p_transform, bool p_disabled);
105 void remove_shape(const JoltShape3D *p_shape);
106 void remove_shape(int p_index);
107
108 JoltShape3D *get_shape(int p_index) const;
109 void set_shape(int p_index, JoltShape3D *p_shape);
110
111 void clear_shapes();
112 void clear_previous_shape();
113
114 int get_shape_count() const { return shapes.size(); }
115
116 int find_shape_index(uint32_t p_shape_instance_id) const;
117 int find_shape_index(const JPH::SubShapeID &p_sub_shape_id) const;
118
119 JoltShape3D *find_shape(uint32_t p_shape_instance_id) const;
120 JoltShape3D *find_shape(const JPH::SubShapeID &p_sub_shape_id) const;
121
122 Transform3D get_shape_transform_unscaled(int p_index) const;
123 Transform3D get_shape_transform_scaled(int p_index) const;
124 void set_shape_transform(int p_index, Transform3D p_transform);
125
126 Vector3 get_shape_scale(int p_index) const;
127
128 bool is_shape_disabled(int p_index) const;
129 void set_shape_disabled(int p_index, bool p_disabled);
130 };