Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
OPC_RayTriOverlap.h
Go to the documentation of this file.
1
#define LOCAL_EPSILON 0.000001f
2
4
15
inline_
bool
RayCollider::RayTriOverlap
(
const
Point
& vert0,
const
Point
& vert1,
const
Point
& vert2)
17
{
18
// Stats
19
mNbRayPrimTests
++;
20
21
// Find vectors for two edges sharing vert0
22
Point
edge1 = vert1 - vert0;
23
Point
edge2 = vert2 - vert0;
24
25
// Begin calculating determinant - also used to calculate U parameter
26
Point
pvec =
mDir
^edge2;
27
28
// If determinant is near zero, ray lies in plane of triangle
29
float
det = edge1|pvec;
30
31
if
(
mCulling
)
32
{
33
if
(det<
LOCAL_EPSILON
)
return
FALSE
;
34
// From here, det is > 0. So we can use integer cmp.
35
36
// Calculate distance from vert0 to ray origin
37
Point
tvec =
mOrigin
- vert0;
38
39
// Calculate U parameter and test bounds
40
mStabbedFace
.
mU
= tvec|pvec;
41
// if(IR(u)&0x80000000 || u>det) return FALSE;
42
if
((
mStabbedFace
.
mU
< 0.0f) ||
IR
(
mStabbedFace
.
mU
)>
IR
(det))
return
FALSE
;
43
44
// Prepare to test V parameter
45
Point
qvec = tvec^edge1;
46
47
// Calculate V parameter and test bounds
48
mStabbedFace
.
mV
=
mDir
|qvec;
49
if
((
mStabbedFace
.
mV
< 0.0f) ||
mStabbedFace
.
mU
+
mStabbedFace
.
mV
>det)
return
FALSE
;
50
51
// Calculate t, scale parameters, ray intersects triangle
52
mStabbedFace
.
mDistance
= edge2|qvec;
53
// Det > 0 so we can early exit here
54
// Intersection point is valid if distance is positive (else it can just be a face behind the orig point)
55
if
((
mStabbedFace
.
mDistance
< 0.0f))
return
FALSE
;
56
// Else go on
57
float
OneOverDet = 1.0f / det;
58
mStabbedFace
.
mDistance
*= OneOverDet;
59
mStabbedFace
.
mU
*= OneOverDet;
60
mStabbedFace
.
mV
*= OneOverDet;
61
}
62
else
63
{
64
// the non-culling branch
65
if
(det>-
LOCAL_EPSILON
&& det<
LOCAL_EPSILON
)
return
FALSE
;
66
float
OneOverDet = 1.0f / det;
67
68
// Calculate distance from vert0 to ray origin
69
Point
tvec =
mOrigin
- vert0;
70
71
// Calculate U parameter and test bounds
72
mStabbedFace
.
mU
= (tvec|pvec) * OneOverDet;
73
// if(IR(u)&0x80000000 || u>1.0f) return FALSE;
74
if
((
mStabbedFace
.
mU
< 0.0f) || (
mStabbedFace
.
mU
>1.0f))
return
FALSE
;
75
76
// prepare to test V parameter
77
Point
qvec = tvec^edge1;
78
79
// Calculate V parameter and test bounds
80
mStabbedFace
.
mV
= (
mDir
|qvec) * OneOverDet;
81
if
((
mStabbedFace
.
mV
< 0.0f) ||
mStabbedFace
.
mU
+
mStabbedFace
.
mV
>1.0f)
return
FALSE
;
82
83
// Calculate t, ray intersects triangle
84
mStabbedFace
.
mDistance
= (edge2|qvec) * OneOverDet;
85
// Intersection point is valid if distance is positive (else it can just be a face behind the orig point)
86
if
((
mStabbedFace
.
mDistance
< 0.0f))
return
FALSE
;
87
}
88
return
TRUE
;
89
}
src
cmd
collide2
OPC_RayTriOverlap.h
Generated on Fri May 29 2015 23:07:13 for Vegastrike 0.5.1 rc1 by
1.8.4