Game Development Reference
In-Depth Information
will be the same regardless of which vertex we select, because all of them are on
the same plane.
Once we've solved for and d , we can then store these values in our Plane data
structure:
struct Plane
Vector3 normal
float d
end
Rays and Line Segments
A ray starts at a specific point and extends infinitely in one particular direction.
In games, it's typical to represent a ray using a parametric function. Recall that
a parametric function is one that is expressed in terms of an arbitrary parameter,
generally by the name of t . For a ray, the parametric function is
where R 0 isthestartingpointoftheplaneand isthedirectiontherayistravelling
in. Because a ray starts at a specific point and extends infinitely, for this represent-
ation of a ray to work properly, t must be greater than or equal to 0. This means
that when t is 0, the parametric function will yield the starting point R 0 .
A line segment is similar to a ray, except it has both a start and end point. We can
actually use the same exact parametric function to represent a line segment. The
only difference is we now also have a maximum value of t , because a line segment
has a discrete end point.
Technically, a ray cast involves firing a ray and checking whether or not the ray
intersects with one or more objects. However, what is confusing is that most phys-
icsengines,including HavokandBox2D,usetheterm“raycast” wheninactuality
they are using a line segment, not a ray. The reason for this is that game worlds
usually have constraints, so it typically makes sense to use the more constrained
line segment.
I admit that this terminology might be confusing. However, I wanted to be consist-
ent with the terminology I've seen used in the game industry. So keep in mind as
you continue reading the topic that whenever you see the term “ray cast,” we are
actually using a line segment .
Search WWH ::




Custom Search