| 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 "jolt_custom_shape_type.h" |
| 34 |
|
| 35 |
#include "Jolt/Jolt.h" |
| 36 |
|
| 37 |
#include "Jolt/Physics/Collision/Shape/ConvexShape.h" |
| 38 |
|
| 39 |
class JoltCustomRayShapeSettings final : public JPH::ConvexShapeSettings { |
| 40 |
public: |
| 41 |
JPH::RefConst<JPH::PhysicsMaterial> material; |
| 42 |
float length = 1.0f; |
| 43 |
bool slide_on_slope = false; |
| 44 |
|
| 45 |
JoltCustomRayShapeSettings() = default; |
| 46 |
JoltCustomRayShapeSettings(float p_length, bool p_slide_on_slope, const JPH::PhysicsMaterial *p_material = nullptr) : |
| 47 |
material(p_material), length(p_length), slide_on_slope(p_slide_on_slope) {} |
| 48 |
|
| 49 |
virtual JPH::ShapeSettings::ShapeResult Create() const override; |
| 50 |
}; |
| 51 |
|
| 52 |
class JoltCustomRayShape final : public JPH::ConvexShape { |
| 53 |
public: |
| 54 |
JPH::RefConst<JPH::PhysicsMaterial> material; |
| 55 |
float length = 0.0f; |
| 56 |
bool slide_on_slope = false; |
| 57 |
|
| 58 |
static void register_type(); |
| 59 |
|
| 60 |
JoltCustomRayShape() : |
| 61 |
JPH::ConvexShape(JoltCustomShapeSubType::RAY) {} |
| 62 |
|
| 63 |
JoltCustomRayShape(const JoltCustomRayShapeSettings &p_settings, JPH::Shape::ShapeResult &p_result) : |
| 64 |
JPH::ConvexShape(JoltCustomShapeSubType::RAY, p_settings, p_result), material(p_settings.material), length(p_settings.length), slide_on_slope(p_settings.slide_on_slope) { |
| 65 |
if (!p_result.HasError()) { |
| 66 |
p_result.Set(this); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
JoltCustomRayShape(float p_length, bool p_slide_on_slope, const JPH::PhysicsMaterial *p_material = nullptr) : |
| 71 |
JPH::ConvexShape(JoltCustomShapeSubType::RAY), material(p_material), length(p_length), slide_on_slope(p_slide_on_slope) {} |
| 72 |
|
| 73 |
virtual JPH::AABox GetLocalBounds() const override; |
| 74 |
|
| 75 |
virtual float GetInnerRadius() const override; |
| 76 |
|
| 77 |
virtual JPH::MassProperties GetMassProperties() const override; |
| 78 |
|
| 79 |
virtual JPH::Vec3 GetSurfaceNormal(const JPH::SubShapeID &p_sub_shape_id, JPH::Vec3Arg p_local_surface_position) const override { return JPH::Vec3::sAxisZ(); } |
| 80 |
|
| 81 |
virtual void GetSubmergedVolume(JPH::Mat44Arg p_center_of_mass_transform, JPH::Vec3Arg p_scale, const JPH::Plane &p_surface, float &p_total_volume, float &p_submerged_volume, JPH::Vec3 &p_center_of_buoyancy JPH_IF_DEBUG_RENDERER(, JPH::RVec3Arg p_base_offset)) const override { |
| 82 |
p_total_volume = 0.0f; |
| 83 |
p_submerged_volume = 0.0f; |
| 84 |
p_center_of_buoyancy = JPH::Vec3::sZero(); |
| 85 |
} |
| 86 |
|
| 87 |
#ifdef JPH_DEBUG_RENDERER |
| 88 |
virtual void Draw(JPH::DebugRenderer *p_renderer, JPH::RMat44Arg p_center_of_mass_transform, JPH::Vec3Arg p_scale, JPH::ColorArg p_color, bool p_use_material_colors, bool p_draw_wireframe) const override; |
| 89 |
#endif |
| 90 |
|
| 91 |
virtual bool CastRay(const JPH::RayCast &p_ray, const JPH::SubShapeIDCreator &p_sub_shape_id_creator, JPH::RayCastResult &p_hit) const override { return false; } |
| 92 |
|
| 93 |
virtual void CastRay(const JPH::RayCast &p_ray, const JPH::RayCastSettings &p_ray_cast_settings, const JPH::SubShapeIDCreator &p_sub_shape_id_creator, JPH::CastRayCollector &p_collector, const JPH::ShapeFilter &p_shape_filter = JPH::ShapeFilter()) const override {} |
| 94 |
|
| 95 |
virtual void CollidePoint(JPH::Vec3Arg p_point, const JPH::SubShapeIDCreator &p_sub_shape_id_creator, JPH::CollidePointCollector &p_collector, const JPH::ShapeFilter &p_shape_filter = JPH::ShapeFilter()) const override {} |
| 96 |
|
| 97 |
virtual void CollideSoftBodyVertices(JPH::Mat44Arg p_center_of_mass_transform, JPH::Vec3Arg p_scale, const JPH::CollideSoftBodyVertexIterator &p_vertices, JPH::uint p_num_vertices, int p_colliding_shape_index) const override {} |
| 98 |
|
| 99 |
virtual JPH::Shape::Stats GetStats() const override { return JPH::Shape::Stats(sizeof(*this), 0); } |
| 100 |
|
| 101 |
virtual float GetVolume() const override { return 0.0f; } |
| 102 |
|
| 103 |
virtual const JPH::ConvexShape::Support *GetSupportFunction(JPH::ConvexShape::ESupportMode p_mode, JPH::ConvexShape::SupportBuffer &p_buffer, JPH::Vec3Arg p_scale) const override; |
| 104 |
}; |