Game Development Reference
In-Depth Information
Figure 3.9 The normal going into the page for triangle ABC (in a right-handed
coordinate system).
Because we only care about the direction of the normal, and not the magnitude, we
should make sure to always normalize this vector. This concept of a normal does
not apply only to triangles; any polygon has a single normal as long as it lies on a
single plane.
Note that we could also take the cross product in the opposite order, in which case
we would still get a vector perpendicular to the triangle's plane, although it will be
facing in the opposite direction. Chapter 4 discusses the concept of winding order,
which determines the order in which we should perform the cross product.
Sample Problem: Rotating a 2D Character
Let's take a look at another sample problem. Suppose we have a top-down action
game where a player character moves through the world. We are scripting an in-
game cutscene where an explosion occurs at a specific location, and we want the
player to turn and face this explosion. However, the cutscene can trigger in a vari-
ety of scenarios, so the initial direction the player is facing is variable. We also do
not want the player to suddenly snap to face the explosion; rather, it should be a
smooth transition over a brief period of time.
Search WWH ::




Custom Search