| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 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 |
}; |