Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
RayCast.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
8
10
12template <class Vec, class Mat, class RayCastType>
14{
16
18 RayCastT() = default; // Allow raycast to be created uninitialized
19 RayCastT(typename Vec::ArgType inOrigin, Vec3Arg inDirection) : mOrigin(inOrigin), mDirection(inDirection) { }
21
23 RayCastType Transformed(typename Mat::ArgType inTransform) const
24 {
25 Vec ray_origin = inTransform * mOrigin;
26 Vec3 ray_direction(inTransform * (mOrigin + mDirection) - ray_origin);
27 return { ray_origin, ray_direction };
28 }
29
31 RayCastType Translated(typename Vec::ArgType inTranslation) const
32 {
33 return { inTranslation + mOrigin, mDirection };
34 }
35
37 inline Vec GetPointOnRay(float inFraction) const
38 {
39 return mOrigin + inFraction * mDirection;
40 }
41
42 Vec mOrigin;
44};
45
46struct RayCast : public RayCastT<Vec3, Mat44, RayCast>
47{
49};
50
51struct RRayCast : public RayCastT<RVec3, RMat44, RRayCast>
52{
54
56 explicit RRayCast(const RayCast &inRay) :
57 RRayCast(RVec3(inRay.mOrigin), inRay.mDirection)
58 {
59 }
60
62 explicit operator RayCast() const
63 {
65 }
66};
67
70{
71public:
73
75 EBackFaceMode mBackFaceMode = EBackFaceMode::IgnoreBackFaces;
76
79};
80
EBackFaceMode
How collision detection functions will treat back facing triangles.
Definition: BackFaceMode.h:11
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
Mat44 RMat44
Definition: Real.h:31
Vec3 RVec3
Definition: Real.h:29
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition: Mat44.h:13
Settings to be passed with a ray cast.
Definition: RayCast.h:70
JPH_OVERRIDE_NEW_DELETE EBackFaceMode mBackFaceMode
How backfacing triangles should be treated.
Definition: RayCast.h:75
bool mTreatConvexAsSolid
If convex shapes should be treated as solid. When true, a ray starting inside a convex shape will gen...
Definition: RayCast.h:78
Definition: Vec3.h:16
Definition: RayCast.h:52
RRayCast(const RayCast &inRay)
Convert from RayCast, converts single to double precision.
Definition: RayCast.h:56
Definition: RayCast.h:47
Structure that holds a single ray cast.
Definition: RayCast.h:14
RayCastT(const RayCastT< Vec, Mat, RayCastType > &)=default
JPH_OVERRIDE_NEW_DELETE RayCastT()=default
Constructors.
RayCastType Translated(typename Vec::ArgType inTranslation) const
Translate ray using inTranslation.
Definition: RayCast.h:31
RayCastT(typename Vec::ArgType inOrigin, Vec3Arg inDirection)
Definition: RayCast.h:19
Vec3 mDirection
Direction and length of the ray (anything beyond this length will not be reported as a hit)
Definition: RayCast.h:43
RayCastType Transformed(typename Mat::ArgType inTransform) const
Transform this ray using inTransform.
Definition: RayCast.h:23
Vec GetPointOnRay(float inFraction) const
Get point with fraction inFraction on ray (0 = start of ray, 1 = end of ray)
Definition: RayCast.h:37
Vec mOrigin
Origin of the ray.
Definition: RayCast.h:42