Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
RayAABox.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
11{
12public:
14 inline RayInvDirection() = default;
16
18 inline void Set(Vec3Arg inDirection)
19 {
20 // if (abs(inDirection) <= Epsilon) the ray is nearly parallel to the slab.
22
23 // Calculate 1 / direction while avoiding division by zero
25 }
26
29};
30
34{
35 // Constants
38
39 // Test against all three axii simultaneously.
40 Vec3 t1 = (inBoundsMin - inOrigin) * inInvDirection.mInvDirection;
41 Vec3 t2 = (inBoundsMax - inOrigin) * inInvDirection.mInvDirection;
42
43 // Compute the max of min(t1,t2) and the min of max(t1,t2) ensuring we don't
44 // use the results from any directions parallel to the slab.
47
48 // t_min.xyz = maximum(t_min.x, t_min.y, t_min.z);
51
52 // t_max.xyz = minimum(t_max.x, t_max.y, t_max.z);
55
56 // if (t_min > t_max) return FLT_MAX;
58
59 // if (t_max < 0.0f) return FLT_MAX;
61
62 // if (inInvDirection.mIsParallel && !(Min <= inOrigin && inOrigin <= Max)) return FLT_MAX; else return t_min;
68}
69
73{
74 // Constants
77
78 // Origin
82
83 // Parallel
84 UVec4 parallelx = inInvDirection.mIsParallel.SplatX();
85 UVec4 parallely = inInvDirection.mIsParallel.SplatY();
86 UVec4 parallelz = inInvDirection.mIsParallel.SplatZ();
87
88 // Inverse direction
89 Vec4 invdirx = inInvDirection.mInvDirection.SplatX();
90 Vec4 invdiry = inInvDirection.mInvDirection.SplatY();
91 Vec4 invdirz = inInvDirection.mInvDirection.SplatZ();
92
93 // Test against all three axii simultaneously.
100
101 // Compute the max of min(t1,t2) and the min of max(t1,t2) ensuring we don't
102 // use the results from any directions parallel to the slab.
109
110 // t_min.xyz = maximum(t_min.x, t_min.y, t_min.z);
112
113 // t_max.xyz = minimum(t_max.x, t_max.y, t_max.z);
115
116 // if (t_min > t_max) return FLT_MAX;
118
119 // if (t_max < 0.0f) return FLT_MAX;
121
122 // if bounds are invalid return FLOAT_MAX;
125
126 // if (inInvDirection.mIsParallel && !(Min <= inOrigin && inOrigin <= Max)) return FLT_MAX; else return t_min;
132}
133
137{
138 // Constants
141
142 // Test against all three axii simultaneously.
143 Vec3 t1 = (inBoundsMin - inOrigin) * inInvDirection.mInvDirection;
144 Vec3 t2 = (inBoundsMax - inOrigin) * inInvDirection.mInvDirection;
145
146 // Compute the max of min(t1,t2) and the min of max(t1,t2) ensuring we don't
147 // use the results from any directions parallel to the slab.
150
151 // t_min.xyz = maximum(t_min.x, t_min.y, t_min.z);
154
155 // t_max.xyz = minimum(t_max.x, t_max.y, t_max.z);
158
159 // if (t_min > t_max) return FLT_MAX;
161
162 // if (t_max < 0.0f) return FLT_MAX;
164
165 // if (inInvDirection.mIsParallel && !(Min <= inOrigin && inOrigin <= Max)) return FLT_MAX; else return t_min;
172}
173
176{
177 // Constants
180
181 // Test against all three axii simultaneously.
182 Vec3 t1 = (inBoundsMin - inOrigin) * inInvDirection.mInvDirection;
183 Vec3 t2 = (inBoundsMax - inOrigin) * inInvDirection.mInvDirection;
184
185 // Compute the max of min(t1,t2) and the min of max(t1,t2) ensuring we don't
186 // use the results from any directions parallel to the slab.
189
190 // t_min.xyz = maximum(t_min.x, t_min.y, t_min.z);
193
194 // t_max.xyz = minimum(t_max.x, t_max.y, t_max.z);
197
198 // if (t_min > t_max) return false;
200
201 // if (t_max < 0.0f) return false;
203
204 // if (t_min > inClosest) return false;
206
207 // if (inInvDirection.mIsParallel && !(Min <= inOrigin && inOrigin <= Max)) return false; else return true;
210
211 return !no_intersection.TestAnyXYZTrue();
212}
213
240
#define JPH_NAMESPACE_END
Definition Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition Core.h:361
AllocateFunction Allocate
Definition Memory.cpp:59
JPH_INLINE Vec4 RayAABox4(Vec3Arg inOrigin, const RayInvDirection &inInvDirection, Vec4Arg inBoundsMinX, Vec4Arg inBoundsMinY, Vec4Arg inBoundsMinZ, Vec4Arg inBoundsMaxX, Vec4Arg inBoundsMaxY, Vec4Arg inBoundsMaxZ)
Definition RayAABox.h:72
JPH_INLINE bool RayAABoxHits(Vec3Arg inOrigin, const RayInvDirection &inInvDirection, Vec3Arg inBoundsMin, Vec3Arg inBoundsMax, float inClosest)
Intersect AABB with ray, returns true if there is a hit closer than inClosest.
Definition RayAABox.h:175
JPH_INLINE float RayAABox(Vec3Arg inOrigin, const RayInvDirection &inInvDirection, Vec3Arg inBoundsMin, Vec3Arg inBoundsMax)
Definition RayAABox.h:33
@ SWIZZLE_Z
Use the Z component.
Definition Swizzle.h:14
@ SWIZZLE_X
Use the X component.
Definition Swizzle.h:12
@ SWIZZLE_Y
Use the Y component.
Definition Swizzle.h:13
Helper structure holding the reciprocal of a ray for Ray vs AABox testing.
Definition RayAABox.h:11
UVec4 mIsParallel
for each component if it is parallel to the coordinate axis
Definition RayAABox.h:28
Vec3 mInvDirection
1 / ray direction
Definition RayAABox.h:27
RayInvDirection(Vec3Arg inDirection)
Definition RayAABox.h:15
RayInvDirection()=default
Constructors.
void Set(Vec3Arg inDirection)
Set reciprocal from ray direction.
Definition RayAABox.h:18
Definition UVec4.h:12
JPH_INLINE UVec4 SplatY() const
Replicate the Y component to all components.
Definition UVec4.inl:288
JPH_INLINE UVec4 SplatX() const
Replicate the X component to all components.
Definition UVec4.inl:277
static JPH_INLINE UVec4 sAnd(UVec4Arg inV1, UVec4Arg inV2)
Logical and (component wise)
Definition UVec4.inl:194
static JPH_INLINE UVec4 sOr(UVec4Arg inV1, UVec4Arg inV2)
Logical or (component wise)
Definition UVec4.inl:166
JPH_INLINE UVec4 SplatZ() const
Replicate the Z component to all components.
Definition UVec4.inl:299
Definition Vec3.h:16
static JPH_INLINE Vec3 sMax(Vec3Arg inV1, Vec3Arg inV2)
Return the maximum of each of the components.
Definition Vec3.inl:159
static JPH_INLINE Vec3 sMin(Vec3Arg inV1, Vec3Arg inV2)
Return the minimum value of each of the components.
Definition Vec3.inl:146
JPH_INLINE float GetX() const
Get individual components.
Definition Vec3.h:123
static JPH_INLINE UVec4 sGreaterOrEqual(Vec3Arg inV1, Vec3Arg inV2)
Greater than or equal (component wise)
Definition Vec3.inl:237
static JPH_INLINE UVec4 sLessOrEqual(Vec3Arg inV1, Vec3Arg inV2)
Less than or equal (component wise)
Definition Vec3.inl:207
JPH_INLINE Vec3 Abs() const
Return the absolute value of each of the components.
Definition Vec3.inl:564
JPH_INLINE Vec3 Reciprocal() const
Reciprocal vector (1 / value) for each of the components.
Definition Vec3.inl:577
static JPH_INLINE UVec4 sGreater(Vec3Arg inV1, Vec3Arg inV2)
Greater than (component wise)
Definition Vec3.inl:222
static JPH_INLINE Vec3 sSelect(Vec3Arg inV1, Vec3Arg inV2, UVec4Arg inControl)
Component wise select, returns inV1 when highest bit of inControl = 0 and inV2 when highest bit of in...
Definition Vec3.inl:269
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:107
static JPH_INLINE UVec4 sLess(Vec3Arg inV1, Vec3Arg inV2)
Less than (component wise)
Definition Vec3.inl:192
static JPH_INLINE Vec3 sReplicate(float inV)
Replicate inV across all components.
Definition Vec3.inl:118
JPH_INLINE Vec3 Swizzle() const
Swizzle the elements in inV.
Definition Vec4.h:14
JPH_INLINE Vec4 SplatX() const
Replicate the X component to all components.
Definition Vec4.inl:547
static JPH_INLINE UVec4 sGreater(Vec4Arg inV1, Vec4Arg inV2)
Greater than (component wise)
Definition Vec4.inl:208
static JPH_INLINE UVec4 sLess(Vec4Arg inV1, Vec4Arg inV2)
Less than (component wise)
Definition Vec4.inl:180
static JPH_INLINE Vec4 sSelect(Vec4Arg inV1, Vec4Arg inV2, UVec4Arg inControl)
Component wise select, returns inV1 when highest bit of inControl = 0 and inV2 when highest bit of in...
Definition Vec4.inl:254
JPH_INLINE Vec4 SplatY() const
Replicate the Y component to all components.
Definition Vec4.inl:558
static JPH_INLINE Vec4 sMin(Vec4Arg inV1, Vec4Arg inV2)
Return the minimum value of each of the components.
Definition Vec4.inl:138
JPH_INLINE Vec4 SplatZ() const
Replicate the Z component to all components.
Definition Vec4.inl:569
static JPH_INLINE Vec4 sZero()
Vector with all zeros.
Definition Vec4.inl:63
static JPH_INLINE Vec4 sMax(Vec4Arg inV1, Vec4Arg inV2)
Return the maximum of each of the components.
Definition Vec4.inl:152
static JPH_INLINE Vec4 sReplicate(float inV)
Replicate inV across all components.
Definition Vec4.inl:74