Game Development Reference
In-Depth Information
It is very easy to do a circle-point or sphere-point intersection test. This is a test
that checks if a point is inside a certain circle or sphere. Let's take the circle
example. A circle is defined by the circle position and a radius. If a unit circle
exists at [5, 6] and there is a point [5.5, 6.5] the first step is to get the distance
from the circle origin. This is done by vector subtraction of the circle origin from
the point [5, 6] [5.5, 6.5] ΒΌ [0.5, 0.5] giving the vector from the point to the
center of the circle. The distance between the point and the circle is then calcu-
lated by performing the length operation on that vector. This gives a length of
0.707 . . . . If this length is smaller than the circle radius, then the point is inside
the circle; if it is greater, it is outside. If it is the same, it's on the very edge of the
circle, as Figure 8.12 shows.
The same method works for sphere-point intersection. This is a quick way to see
if the player is in a certain position or if the mouse has been used to click on a
certain area. If you don't feel comfortable with it, try sketching out a few
Figure 8.12
Circle-point intersection.
 
Search WWH ::




Custom Search