Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
VehicleCollisionTester.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11
12class PhysicsSystem;
16class BodyFilter;
17
19class JPH_EXPORT VehicleCollisionTester : public RefTarget<VehicleCollisionTester>, public NonCopyable
20{
21public:
23
26 explicit VehicleCollisionTester(ObjectLayer inObjectLayer) : mObjectLayer(inObjectLayer) { }
27
29 virtual ~VehicleCollisionTester() = default;
30
32 ObjectLayer GetObjectLayer() const { return mObjectLayer; }
33 void SetObjectLayer(ObjectLayer inObjectLayer) { mObjectLayer = inObjectLayer; }
34
36 void SetBroadPhaseLayerFilter(const BroadPhaseLayerFilter *inFilter) { mBroadPhaseLayerFilter = inFilter; }
37 const BroadPhaseLayerFilter * GetBroadPhaseLayerFilter() const { return mBroadPhaseLayerFilter; }
38
40 void SetObjectLayerFilter(const ObjectLayerFilter *inFilter) { mObjectLayerFilter = inFilter; }
41 const ObjectLayerFilter * GetObjectLayerFilter() const { return mObjectLayerFilter; }
42
44 void SetBodyFilter(const BodyFilter *inFilter) { mBodyFilter = inFilter; }
45 const BodyFilter * GetBodyFilter() const { return mBodyFilter; }
46
60 virtual bool Collide(PhysicsSystem &inPhysicsSystem, const VehicleConstraint &inVehicleConstraint, uint inWheelIndex, RVec3Arg inOrigin, Vec3Arg inDirection, const BodyID &inVehicleBodyID, Body *&outBody, SubShapeID &outSubShapeID, RVec3 &outContactPosition, Vec3 &outContactNormal, float &outSuspensionLength) const = 0;
61
74 virtual void PredictContactProperties(PhysicsSystem &inPhysicsSystem, const VehicleConstraint &inVehicleConstraint, uint inWheelIndex, RVec3Arg inOrigin, Vec3Arg inDirection, const BodyID &inVehicleBodyID, Body *&ioBody, SubShapeID &ioSubShapeID, RVec3 &ioContactPosition, Vec3 &ioContactNormal, float &ioSuspensionLength) const = 0;
75
76protected:
77 const BroadPhaseLayerFilter * mBroadPhaseLayerFilter = nullptr;
78 const ObjectLayerFilter * mObjectLayerFilter = nullptr;
79 const BodyFilter * mBodyFilter = nullptr;
80 ObjectLayer mObjectLayer = cObjectLayerInvalid;
81};
82
85{
86public:
88
93 VehicleCollisionTesterRay(ObjectLayer inObjectLayer, Vec3Arg inUp = Vec3::sAxisY(), float inMaxSlopeAngle = DegreesToRadians(80.0f)) : VehicleCollisionTester(inObjectLayer), mUp(inUp), mCosMaxSlopeAngle(Cos(inMaxSlopeAngle)) { }
94
95 // See: VehicleCollisionTester
96 virtual bool Collide(PhysicsSystem &inPhysicsSystem, const VehicleConstraint &inVehicleConstraint, uint inWheelIndex, RVec3Arg inOrigin, Vec3Arg inDirection, const BodyID &inVehicleBodyID, Body *&outBody, SubShapeID &outSubShapeID, RVec3 &outContactPosition, Vec3 &outContactNormal, float &outSuspensionLength) const override;
97 virtual void PredictContactProperties(PhysicsSystem &inPhysicsSystem, const VehicleConstraint &inVehicleConstraint, uint inWheelIndex, RVec3Arg inOrigin, Vec3Arg inDirection, const BodyID &inVehicleBodyID, Body *&ioBody, SubShapeID &ioSubShapeID, RVec3 &ioContactPosition, Vec3 &ioContactNormal, float &ioSuspensionLength) const override;
98
99private:
100 Vec3 mUp;
101 float mCosMaxSlopeAngle;
102};
103
106{
107public:
109
115 VehicleCollisionTesterCastSphere(ObjectLayer inObjectLayer, float inRadius, Vec3Arg inUp = Vec3::sAxisY(), float inMaxSlopeAngle = DegreesToRadians(80.0f)) : VehicleCollisionTester(inObjectLayer), mRadius(inRadius), mUp(inUp), mCosMaxSlopeAngle(Cos(inMaxSlopeAngle)) { }
116
117 // See: VehicleCollisionTester
118 virtual bool Collide(PhysicsSystem &inPhysicsSystem, const VehicleConstraint &inVehicleConstraint, uint inWheelIndex, RVec3Arg inOrigin, Vec3Arg inDirection, const BodyID &inVehicleBodyID, Body *&outBody, SubShapeID &outSubShapeID, RVec3 &outContactPosition, Vec3 &outContactNormal, float &outSuspensionLength) const override;
119 virtual void PredictContactProperties(PhysicsSystem &inPhysicsSystem, const VehicleConstraint &inVehicleConstraint, uint inWheelIndex, RVec3Arg inOrigin, Vec3Arg inDirection, const BodyID &inVehicleBodyID, Body *&ioBody, SubShapeID &ioSubShapeID, RVec3 &ioContactPosition, Vec3 &ioContactNormal, float &ioSuspensionLength) const override;
120
121private:
122 float mRadius;
123 Vec3 mUp;
124 float mCosMaxSlopeAngle;
125};
126
129{
130public:
132
136 VehicleCollisionTesterCastCylinder(ObjectLayer inObjectLayer, float inConvexRadiusFraction = 0.1f) : VehicleCollisionTester(inObjectLayer), mConvexRadiusFraction(inConvexRadiusFraction) { JPH_ASSERT(mConvexRadiusFraction >= 0.0f && mConvexRadiusFraction <= 1.0f); }
137
138 // See: VehicleCollisionTester
139 virtual bool Collide(PhysicsSystem &inPhysicsSystem, const VehicleConstraint &inVehicleConstraint, uint inWheelIndex, RVec3Arg inOrigin, Vec3Arg inDirection, const BodyID &inVehicleBodyID, Body *&outBody, SubShapeID &outSubShapeID, RVec3 &outContactPosition, Vec3 &outContactNormal, float &outSuspensionLength) const override;
140 virtual void PredictContactProperties(PhysicsSystem &inPhysicsSystem, const VehicleConstraint &inVehicleConstraint, uint inWheelIndex, RVec3Arg inOrigin, Vec3Arg inDirection, const BodyID &inVehicleBodyID, Body *&ioBody, SubShapeID &ioSubShapeID, RVec3 &ioContactPosition, Vec3 &ioContactNormal, float &ioSuspensionLength) const override;
141
142private:
143 float mConvexRadiusFraction;
144};
145
#define JPH_EXPORT
Definition: Core.h:227
unsigned int uint
Definition: Core.h:439
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
constexpr float DegreesToRadians(float inV)
Convert a value from degrees to radians.
Definition: Math.h:13
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
uint16 ObjectLayer
Definition: ObjectLayer.h:16
JPH_INLINE float Cos(float inX)
Cosine of x (input in radians)
Definition: Trigonometry.h:20
Class function to filter out bodies, returns true if test should collide with body.
Definition: BodyFilter.h:16
Definition: Body.h:35
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition: BodyID.h:13
Filter class for broadphase layers.
Definition: BroadPhaseLayer.h:94
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition: NonCopyable.h:11
Filter class for object layers.
Definition: ObjectLayer.h:28
Definition: PhysicsSystem.h:29
Definition: Reference.h:35
A sub shape id contains a path to an element (usually a triangle or other primitive type) of a compou...
Definition: SubShapeID.h:23
Definition: Vec3.h:16
static JPH_INLINE Vec3 sAxisY()
Definition: Vec3.h:53
Collision tester that tests collision using a cylinder shape.
Definition: VehicleCollisionTester.h:129
JPH_OVERRIDE_NEW_DELETE VehicleCollisionTesterCastCylinder(ObjectLayer inObjectLayer, float inConvexRadiusFraction=0.1f)
Definition: VehicleCollisionTester.h:136
Collision tester that tests collision using a sphere cast.
Definition: VehicleCollisionTester.h:106
JPH_OVERRIDE_NEW_DELETE VehicleCollisionTesterCastSphere(ObjectLayer inObjectLayer, float inRadius, Vec3Arg inUp=Vec3::sAxisY(), float inMaxSlopeAngle=DegreesToRadians(80.0f))
Definition: VehicleCollisionTester.h:115
Class that does collision detection between wheels and ground.
Definition: VehicleCollisionTester.h:20
ObjectLayer GetObjectLayer() const
Object layer to use for collision detection, this is used when the filters are not overridden.
Definition: VehicleCollisionTester.h:32
virtual bool Collide(PhysicsSystem &inPhysicsSystem, const VehicleConstraint &inVehicleConstraint, uint inWheelIndex, RVec3Arg inOrigin, Vec3Arg inDirection, const BodyID &inVehicleBodyID, Body *&outBody, SubShapeID &outSubShapeID, RVec3 &outContactPosition, Vec3 &outContactNormal, float &outSuspensionLength) const =0
virtual void PredictContactProperties(PhysicsSystem &inPhysicsSystem, const VehicleConstraint &inVehicleConstraint, uint inWheelIndex, RVec3Arg inOrigin, Vec3Arg inDirection, const BodyID &inVehicleBodyID, Body *&ioBody, SubShapeID &ioSubShapeID, RVec3 &ioContactPosition, Vec3 &ioContactNormal, float &ioSuspensionLength) const =0
void SetBodyFilter(const BodyFilter *inFilter)
Access to the body filter, when set this overrides the default filter that filters out the vehicle bo...
Definition: VehicleCollisionTester.h:44
JPH_OVERRIDE_NEW_DELETE VehicleCollisionTester()=default
Constructors.
VehicleCollisionTester(ObjectLayer inObjectLayer)
Definition: VehicleCollisionTester.h:26
virtual ~VehicleCollisionTester()=default
Virtual destructor.
const BodyFilter * GetBodyFilter() const
Definition: VehicleCollisionTester.h:45
void SetBroadPhaseLayerFilter(const BroadPhaseLayerFilter *inFilter)
Access to the broad phase layer filter, when set this overrides the object layer supplied in the cons...
Definition: VehicleCollisionTester.h:36
const BroadPhaseLayerFilter * GetBroadPhaseLayerFilter() const
Definition: VehicleCollisionTester.h:37
const ObjectLayerFilter * GetObjectLayerFilter() const
Definition: VehicleCollisionTester.h:41
void SetObjectLayerFilter(const ObjectLayerFilter *inFilter)
Access to the object layer filter, when set this overrides the object layer supplied in the construct...
Definition: VehicleCollisionTester.h:40
void SetObjectLayer(ObjectLayer inObjectLayer)
Definition: VehicleCollisionTester.h:33
Collision tester that tests collision using a raycast.
Definition: VehicleCollisionTester.h:85
JPH_OVERRIDE_NEW_DELETE VehicleCollisionTesterRay(ObjectLayer inObjectLayer, Vec3Arg inUp=Vec3::sAxisY(), float inMaxSlopeAngle=DegreesToRadians(80.0f))
Definition: VehicleCollisionTester.h:93
Definition: VehicleConstraint.h:66