Graphics Reference
In-Depth Information
class
UWB
_
XformInfo {
public
:
Source file.
uwbgl
_
XformInfo5.h/cpp
file in the
Common Files/
XformInfo
subfolder
// New methods for supporting rotation with Quaternion
of
the
A:
void
InitializeRotation();
void
SetUpModelStack(UWB
_
DrawHelper&);
void
UpdateRotationXByDegree(
float
);
void
SetRotation(
const mat3
&);
mat3
GetRotation();
protected
:
.
UWBGL
_
D3D
_
Lib17
project.
quat m
_
rotation;
// axis and rotation angle
.
B:
void
UWB
_
XformInfo::InitializeRotation() {
.
m
_
rotation[0]=...[1]=...[2]=0.0f;
// initial axis of rotation
m
_
rotation[3] = 1.0f;
C:
// initial angle of rotation
void
UWB
_
XformInfo::SetUpModelStack(UWB
_
DrawHelper& dh)
const
{
.
mat3
m = GetRotation();
// Convert quaternion to matrix
dh.AccumulateModelTransform(... , m, ...);
// Set matrix rotation to matrix stack
D:
void
UWB
_
XformInfo::UpdateRotationXByDegree(
float
dx) {
quat q = quatFromAA(
vec3
(1,0,0), dx);
// construct Quarternion for
R
x
E:
(
dx
)
m
_
rotation = m
_
rotation
*
q;
// concatenate the rotation (post-multiplication)
void
UWB
_
XformInfo::SetRotation(
const mat3
&m) {
mat3
r(m);
// ready to compute transpose
makeTranspose(r);
// transpose of m is post-multiplication
m
_
rotation = mat2quat(r);
// Convert matrix rotation to Quaternion
F:
mat3
UWB
_
XformInfo::GetRotation() {
mat3
r = mat2quat(m
_
rotation);
// convert from quaternion to matrix representation
makeTranspose(r);
G:
// transpose converts from post to pre-multiplication
return
r;
// r is pre-multiplication rotation matrix
Listing 16.12.
Supporting 3D rotation with a quaternion.
concatenating the corresponding quaternion. With the more compact representa-
tion, it is computationally more efficient to concatenate quaternions. The major
shortcoming of the quaternion representation is that at this point, there is no hard-
ware support for transforming vertices by a quaternion.
As programmers, we
Search WWH ::
Custom Search