Debian Codegraph @

modules/jolt_physics/shapes/jolt_shape_instance_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* jolt_shape_instance_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 "core/math/transform_3d.h"
34
35 #include "Jolt/Jolt.h"
36
37 #include "Jolt/Physics/Collision/Shape/Shape.h"
38
39 class JoltShapedObject3D;
40 class JoltShape3D;
41
42 class JoltShapeInstance3D {
43 // This RAII helper exists solely to avoid needing to maintain move construction/assignment in `JoltShapeInstance3D`.
44 struct ShapeReference {
45 JoltShapedObject3D *parent = nullptr;
46 JoltShape3D *shape = nullptr;
47
48 ShapeReference() = default;
49 ShapeReference(JoltShapedObject3D *p_parent, JoltShape3D *p_shape);
50 ShapeReference(const ShapeReference &p_other) = delete;
51 ShapeReference(ShapeReference &&p_other);
52 ~ShapeReference();
53
54 ShapeReference &operator=(const ShapeReference &p_other) = delete;
55 ShapeReference &operator=(ShapeReference &&p_other);
56
57 JoltShape3D *operator*() const { return shape; }
58 JoltShape3D *operator->() const { return shape; }
59 operator JoltShape3D *() const { return shape; }
60 };
61
62 inline static uint32_t next_id = 1;
63
64 Transform3D transform;
65 Vector3 scale;
66 ShapeReference shape;
67 JPH::ShapeRefC jolt_ref;
68 uint32_t id = next_id++;
69 bool disabled = false;
70
71 public:
72 JoltShapeInstance3D() = default;
73 JoltShapeInstance3D(JoltShapedObject3D *p_parent, JoltShape3D *p_shape, const Transform3D &p_transform = Transform3D(), const Vector3 &p_scale = Vector3(1.0f, 1.0f, 1.0f), bool p_disabled = false);
74
75 uint32_t get_id() const { return id; }
76
77 JoltShape3D *get_shape() const { return shape; }
78
79 const JPH::Shape *get_jolt_ref() const { return jolt_ref; }
80
81 const Transform3D &get_transform_unscaled() const { return transform; }
82 Transform3D get_transform_scaled() const { return transform.scaled_local(scale); }
83 void set_transform(const Transform3D &p_transform) { transform = p_transform; }
84
85 const Vector3 &get_scale() const { return scale; }
86 void set_scale(const Vector3 &p_scale) { scale = p_scale; }
87
88 AABB get_aabb() const;
89
90 bool is_built() const { return jolt_ref != nullptr; }
91
92 bool is_enabled() const { return !disabled; }
93 bool is_disabled() const { return disabled; }
94
95 void enable() { disabled = false; }
96 void disable() { disabled = true; }
97
98 bool try_build();
99 };