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 inline Vec GetPointOnRay(float inFraction) const
32 {
33 return mOrigin + inFraction * mDirection;
34 }
35
36 Vec mOrigin;
38};
39
40struct RayCast : public RayCastT<Vec3, Mat44, RayCast>
41{
43};
44
45struct RRayCast : public RayCastT<RVec3, RMat44, RRayCast>
46{
48
50 explicit RRayCast(const RayCast &inRay) :
51 RRayCast(RVec3(inRay.mOrigin), inRay.mDirection)
52 {
53 }
54
56 explicit operator RayCast() const
57 {
59 }
60};
61
64{
65public:
67
69 EBackFaceMode mBackFaceMode = EBackFaceMode::IgnoreBackFaces;
70
73};
74
EBackFaceMode
How collision detection functions will treat back facing triangles.
Definition: BackFaceMode.h:11
#define JPH_NAMESPACE_END
Definition: Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
#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:64
JPH_OVERRIDE_NEW_DELETE EBackFaceMode mBackFaceMode
How backfacing triangles should be treated.
Definition: RayCast.h:69
bool mTreatConvexAsSolid
If convex shapes should be treated as solid. When true, a ray starting inside a convex shape will gen...
Definition: RayCast.h:72
Definition: Vec3.h:16
Definition: RayCast.h:46
RRayCast(const RayCast &inRay)
Convert from RayCast, converts single to double precision.
Definition: RayCast.h:50
Definition: RayCast.h:41
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.
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:37
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:31
Vec mOrigin
Origin of the ray.
Definition: RayCast.h:36