Game Development Reference
In-Depth Information
is formed with the other vector. In this case, the dot product will return the length
of the extended unit vector.
As with multiplication between two real numbers, the dot product is commutative,
distributive over addition, and associative:
Another useful tip is to also think of the length squared calculation as being equi-
valent to the dot product of the vector with itself—or in other words:
Sample Problem: Vector Reflection
Now that we've covered several different types of vector operations, let's apply
them to an actual video game problem. Suppose you have a ball that is travelling
toward a wall. When the ball hits the wall, you want it to reflect off of the wall.
Now, if the wall is parallel to one of the coordinate axes, this is simple to solve.
For example, if the ball bounces off a wall that parallels the x-axis, you can simply
negate the velocity in the y-direction.
But negating the x or y velocity does not work if the wall is not parallel to an axis.
The only solution to this generalized reflection problem is to use vector math. If
we can compute the reflection with vectors, it will work for any arbitrary orienta-
tion of the wall.
Vector problems can be difficult to solve without visualizing them on a sheet of
paper. Figure 3.7(a) shows the initial state of this problem. There are two known
values: the vector , which is the velocity of the ball prior to reflection, and the
normal , which is a unit vector that is perpendicular to the surface of reflection.
We need to solve for the vector , which represents the velocity after reflection.
Search WWH ::




Custom Search