Game Development Reference
In-Depth Information
The vector Z is the unit vector that points from the quad's center toward the
camera position. Calculating the cross product with U produces orthogonal vec-
tor A lying in the plane of the billboard. If
UZ is close to zero, then we can use
×
the alternate formula
ZR
B ZR
ABZ
= ×
.
(9.23)
The vectors A and B form an orthogonal pair of unit vectors that we can use to
express the vectors X and Y :
w
w
 
X
=
cos
θ
A
+
sin
θ
B
 
2
2
 
h
h
 
Y
=−
sin
θ
A
+
cos
θ
B .
(9.24)
 
2
2
 
Using these in Equation (9.20) produces the vertices of the billboarded quad.
We now consider how to orient a quad that is constrained to rotate only about the
z axis. An example of how such a quad might be used is to render the fire texture
for a torch. In this case, the fire is always pointing upward, but the plane of the
quad rotates to face the camera. As long as the camera does not view the quad
from sharply above or below, this produces the convincing illusion that the fire
has volume.
Suppose that the camera resides at the world space point C . For a quad cen-
tered at the point P , we define the vector X as
X
=−
PCC P
,
, 0
.
(9.25)
y
y
x
x
As shown in Figure 9.6, this vector is constructed by taking the difference be-
tween the camera position and the center of the quad, projecting it onto the x - y
plane, and rotating it 90 degrees counterclockwise about the z axis. If
X ,
then the camera is either directly above or directly below the quad. In this case,
the quad is being viewed on edge and therefore should not be rendered. Other-
wise, we calculate the four vertices Q ,
=
0
Q , Q , and
Q of the quad as follows.