Game Development Reference
In-Depth Information
float dx=x-col;
float dz=z-row;
Figure 13.11 shows our cell after this translation.
Figure 13.11:
The cell we are
in before and
after we trans-
late by the
translation that
takes the cell's
upper-left vertex
to the origin
Then, if dx < 1.0 - dx we are in the “upper” triangle $ v0v1v2 . Other-
wise, we are in the “lower” triangle $ v0v2v3 (see Figure 13.10).
Now we explain how to find the height if we are in the “upper” tri-
angle. The process is similar for the “lower” triangle, and of course the
code for both follows shortly. To find the height if we are in the “upper”
triangle, we construct two vectors, u =( cellSpacing , B-A , 0) and v =
(0, C-A , - cellSpacing ), on the sides of the triangle and originating at
the terminal point of the vector q =( q x , A , q z ) as Figure 13.12.a shows.
Then we linearly interpolate along u by dx , and we linearly interpolate
along v by dz . Figure 13.12.b illustrates these interpolations. The
y-coordinate of the vector ( q + dx u + dz v ) gives the height based on
the given x- and z-coordinates; recall the geometric interpretation of
vector addition to see this.
Figure 13.12:
(a) Computing
two vectors on
the adjacent
and opposite
sides of the tri-
angle. (b) The
height is found
by linearly inter-
polating down u
by dx and then
by linearly inter-
polating down v
by dz .
Note that since we are only concerned about the interpolated height
value, we can just interpolate the y-components and ignore the other
components. Thus, the height is obtained by the sum A + dxu y + dzv y .
Search WWH ::




Custom Search