Graphics Reference
In-Depth Information
class UWB _ XformInfo {
.
Source file.
XformInfo3.h/cpp
file
void SetUpModelStack( UWB _ DrawHelper& draw _ helper ) const ;
.
// Access the rotation angle
in
the
Common
Files/
XFormInfo subfolder
of
the
UWBGL _ D3D _ Lib14 project.
A:
void GetRotationInRadians( float &x, float &y, float &z) const ;
// Set the variables for rotations
void SetRotationRadians( float x, float y, float z);
// Represent rotation angles
float m _ xrotation _ radians, m _ yrotation _ radians, m _ zrotation _ radians;
B:
};
void UWB _ XformInfo::SetUpModelStack(UWB _ DrawHelper& draw _ helper) const {
vec3 rotation(m _ xrotation _ radians, m _ yrotation _ radians, m _ zrotation _ radians);
draw _ helper.AccumulateModelTransform(m _ translation, m _ scale, rotation, m _ pivot);
C:
}
Listing 15.5. The UWB _ XformInfo support for 3D rotation.
rotation is the z -axis. For this reason, in 2D space we only need one floating-point
number,
is a rotation defined
with respect to the z -axis. Listing 15.5 shows the expansion to the XformInfo
class to support rotation in 3D space. Labels A and B show a straightforward
approach to implement rotations in 3D space where we use three floating-point
numbers to represent rotation angles with respect to each of the three major axes.
At label C, we see that the actual computation of the transformation operator is
performed by the AccumulateModelTransform function of DrawHelper . List-
ing 15.6 shows that we generalize the z rotation of Equation (9.10) with three
separate rotations. At label A, we concatenate rotations with respect to the x -, y -,
and z -axes consecutively. The computed transformation operator becomes
θ
, to represent the rotation angle. The rotation R
( θ )
R z
R y
R x
M t 7 =
T
(
p
)
S
(
s
)
( θ z )
( θ y )
( θ x )
T
(
p
)
T
(
t
)
M t ,
(15.1)
where M t 7 and M t are the final and initial tops of the matrix stack. Notice
that we did not provide any justification for the ordering of the three rotations.
Would different rotation orderings, for example, R x R y R z versus R z R y R x ,pro-
duce the same results? As it turns out, it is nontrivial to accomplish intuitive
interactive rotation in 3D space, and the above simple rotation support is in-
adequate. We will examine this topic in much more detail in the next chapter.
Search WWH ::




Custom Search