Game Development Reference
In-Depth Information
function
LSPlaneIntersection(
RayCast
r
,
Plane
p
)
LSPlaneReturn
retVal
retVal
.
intersects
=
false
// Calculate v in parametric line segment equa-
tion
Vector3
v
=
r
.
endPoint
-
r
.
startPoint
// Check if the line segment is parallel to the
plane
float
vDotn
= DotProduct(
v
,
p
.
normal
)
if
vDotn
is not approximately 0
t
= -1 * (DotProduct(
r
.
startPoint
,
p
.
normal
)
+
p
.
d
)
t
/=
vDotn
// t should be between startPoint and en-
dPoint (0 to 1)
if
t
>= 0 &&
t
<= 1
retVal
.
intersects
=
true
// Calculate the point of intersection
retVal
.
point
=
r
.
startPoint
+
v
*
t
end
else
// Test if r.startPoint is on the plane
...
end
return
retVal
end