Graphics Reference
In-Depth Information
void UWB _ Camera::GetMouseRotationsInRadian( float &xRot, vec3 &xRef,
float &yRot, vec3 &yRef) const {
. // xRot=
θ x , yRot= θ y
Source file.
uwbgl _ Camera _ Xform1.cpp
file
A: view _ direction = m _ LookAt - m _ CameraPos; // V v = p a p e
xRef = cross(m _ UpVector, view _ direction); // xRef = V w = V up × V v
normalize(xRef);
B: yRef = (0, 1, 0); // yRef is the y-axis
.
C: xRot = UWB _ ToRadians(m _ XRot); // the vertical θ x rotation angle
yRot = UWB _ ToRadians(m _ YRot); // the horizontal
in
the Common Files/
Camera
subfolder
of
the
UWBGL _ D3D _ Lib14 project.
θ y rotation angle
}
Listing 15.12. The UWB_Camera support for camera rotation.
camera orbiting rotations, or the entire world is rotated according to the inverse
of the camera orbiting rotations. In our library, we have chosen to implement
Equation (15.4) (over Equation (15.3)) because we have to compute and update
the VIEW matrix anyway. Listing 15.12 shows the UWB _ Camera support for cam-
era rotations. We see that in addition to the two angles of rotation ( xRot and
yRot ), the GetMouseRotationsInRadian() function also returns the two cor-
responding axes of rotation ( xRef and yRef ). At label A, the xRef rotation axis
is set to the V w vector, and at label B, the yRef rotation axis is set to the y -axis.
m _ XRot (
y ) are instance variables of the UWB _ Camera class
that record the rotations set by the user. In this case, the left/right left mouse but-
ton drag sets m _ YRot , and the up/down left mouse button drag changes m _ XRot .
Listing 15.13 shows the last stage of view matrix computation that is missing at la-
bel A1c from Listing 15.8. Recall that the ComputeViewMatrix() is responsible
for computing the view matrix that will be loaded into the D3D VIEW matrix pro-
cessor. Once again, here we see that at label A1b, the M w 2 e from Equation (14.4)
is computed and stored in the variable mat . Here we see the details of supporting
camera rotation in WC-to-EC transformation matrix. The camera rotation pa-
rameters, including the two angles and their corresponding axes are accessed at
label A1d. At label A1e, we invoke the D3DXMatrixRotationAxis() function
to compute the two rotation operators R v w and R y , with results stored in xRotMat
and yRotMat . At label A1f, the operators are concatenated with the view matrix
to compute the M r w 2 e of Equation (15.4). The computed WC-to-EC matrix com-
pensates for the horizontal and vertical rotations of the camera, and we can avoid
re-computing the eye position every time the user adjusts the camera rotation.
x )and m _ YRot (
θ
θ
Search WWH ::




Custom Search