forked from tatepoon/OpCoDe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOPC_RayAABBOverlap.h
94 lines (79 loc) · 4.47 KB
/
OPC_RayAABBOverlap.h
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Opcode 1.1: ray-AABB overlap tests based on Woo's code
// Opcode 1.2: ray-AABB overlap tests based on the separating axis theorem
// Opcode 1.3.2: configuration. Apply or do not apply the model's scale??
//
// The point of intersection is not computed anymore. The distance to impact is not needed anymore
// since we now have two different queries for segments or rays.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Computes a segment-AABB overlap test using the separating axis theorem. Segment is cached within the class.
* \param center [in] AABB center
* \param extents [in] AABB extents
* \return true on overlap
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// What we do here is just a simple hack over the method declaration in order do keep the
/// intersection code easier to maintain. This code will be moved to RayCollider macros sooner or later
#if defined(OPC_RAYCOLLIDER_SCALE_BEFORE_OVERLAP)
inline_ BOOL RayCollider::SegmentAABBOverlap(const Point& center_, const Point& extents_)
{
// Applies model's local scale
const IceMaths::Point center = center_ * mLocalScale;
const IceMaths::Point extents = extents_* mLocalScale;
#else
inline_ BOOL RayCollider::SegmentAABBOverlap(const Point& center, const Point& extents)
{
#endif
// Stats
mNbRayBVTests++;
// Pierre's code: looks like an AABB-AABB test
float Dx = mData2.x - center.x; if(fabsf(Dx) > extents.x + mFDir.x) return FALSE;
float Dy = mData2.y - center.y; if(fabsf(Dy) > extents.y + mFDir.y) return FALSE;
float Dz = mData2.z - center.z; if(fabsf(Dz) > extents.z + mFDir.z) return FALSE;
//float f;
#if __cplusplus <= 201402L
register
#endif
float f = mData.y * Dz - mData.z * Dy; if(fabsf(f) > extents.y*mFDir.z + extents.z*mFDir.y) return FALSE;
f = mData.z * Dx - mData.x * Dz; if(fabsf(f) > extents.x*mFDir.z + extents.z*mFDir.x) return FALSE;
f = mData.x * Dy - mData.y * Dx; if(fabsf(f) > extents.x*mFDir.y + extents.y*mFDir.x) return FALSE;
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Computes a ray-AABB overlap test using the separating axis theorem. Ray is cached within the class.
* \param center [in] AABB center
* \param extents [in] AABB extents
* \return true on overlap
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(OPC_RAYCOLLIDER_SCALE_BEFORE_OVERLAP)
inline_ BOOL RayCollider::RayAABBOverlap(const Point& center_, const Point& extents_)
{
const Point center = center_*mLocalScale;
const Point extents = extents_*mLocalScale;
#else
inline_ BOOL RayCollider::RayAABBOverlap(const Point& center, const Point& extents)
{
#endif
// Stats
mNbRayBVTests++;
// PIERRE'S CODE:
// float Dx = mOrigin.x - center.x; if(fabsf(Dx) > extents.x && Dx*mDir.x>=0.0f) return FALSE;
// float Dy = mOrigin.y - center.y; if(fabsf(Dy) > extents.y && Dy*mDir.y>=0.0f) return FALSE;
// float Dz = mOrigin.z - center.z; if(fabsf(Dz) > extents.z && Dz*mDir.z>=0.0f) return FALSE;
float Dx = mOrigin.x - center.x; if(GREATER(Dx, extents.x) && Dx*mDir.x>=0.0f) return FALSE;
float Dy = mOrigin.y - center.y; if(GREATER(Dy, extents.y) && Dy*mDir.y>=0.0f) return FALSE;
float Dz = mOrigin.z - center.z; if(GREATER(Dz, extents.z) && Dz*mDir.z>=0.0f) return FALSE;
// float Dx = mOrigin.x - center.x; if(GREATER(Dx, extents.x) && ((SIR(Dx)-1)^SIR(mDir.x))>=0.0f) return FALSE;
// float Dy = mOrigin.y - center.y; if(GREATER(Dy, extents.y) && ((SIR(Dy)-1)^SIR(mDir.y))>=0.0f) return FALSE;
// float Dz = mOrigin.z - center.z; if(GREATER(Dz, extents.z) && ((SIR(Dz)-1)^SIR(mDir.z))>=0.0f) return FALSE;
//float f;
#if __cplusplus <= 201402L
register
#endif
float f = mDir.y * Dz - mDir.z * Dy; if(fabsf(f) > extents.y*mFDir.z + extents.z*mFDir.y) return FALSE;
f = mDir.z * Dx - mDir.x * Dz; if(fabsf(f) > extents.x*mFDir.z + extents.z*mFDir.x) return FALSE;
f = mDir.x * Dy - mDir.y * Dx; if(fabsf(f) > extents.x*mFDir.y + extents.y*mFDir.x) return FALSE;
return TRUE;
}