Graphics Reference
In-Depth Information
Tutorial 14.3. Viewing Frustum and Perspective Projection
Tutorial 14.3.
Project Name:
D3D
_
AdjustPersp
Library Support:
UWB_MFC_Lib1
•
Goal.
Get experience with the viewing frustum and perspective projection.
•
Approach.
Supply GUI control slider bars for viewing frustum parameters
of Tutorial 14.1.
Figure 14.13 is a screenshot of running Tutorial 14.3. This tutorial is exactly the
same as Tutorial 14.2 except for the initialization of the D3D
PROJECTION
ma-
trix processor. Listing 14.3 shows the set-up of the
PROJECTION
matrix processor
in the
GrfxWindowD3D::OnPaint()
function. The variables that correspond to
the parameters of the viewing frustum are controlled by the GUI slider bars. At
label A, we see the visible volume parameters being referenced for the compu-
tation of the
matProj
matrix, and then the
matProj
matrix is loaded into the
D3D
PROJECTION
matrix processor. Once again, details of the mathematics con-
cerning
matProj
will be discussed in Section 14.6. Here, we are interested in
investigating the effects of changing the viewing frustum parameters.
The rendered image of Tutorial 14.3 does resemble the photograph of two
squares in 3D space (Figure 13.1). We can observe the familiar property of objects
becoming smaller as they are farther from the camera. As previously, we can raise
the camera
y
-position value to look at the squares from a higher position. Once
again, we notice that as the camera (and visible volume) moves away, the squares
begin to move out of the viewing frustum and get clipped by the far plane. We
can increase the far plane setting to continue seeing both of the squares. Just as in
the case for Tutorial 14.2, increasing the near plane distance will eventually begin
to clip away the front edges of the squares.
Figure 14.13.
Tutorial
14.3.
Source file.
GrfxWindowD3D.cpp
file in
the
GrfxWindow
folder of the
D3D
_
AdjustPersp
project.
void
CGrfxWindowD3D::OnPaint() {
.
//
Identical to Tutorial 14.1
...
Step 2:
initialize selected hardware and set the coordinate system parameters.
// Set
WORLD
and
VIEW
matrix processors ...
Identical to Tutorial 14.1
.
D3DXMATRIX
matProj;
// Viewing Frustum parameters: m
_
ViewFOV, aspec
_
ratio, m
_
ViewNearPlane, m
_
ViewFarPlane
// compute
matProj
A:
3DXMatrixPerspectiveFovRH(&matProj, fov/aspect
_
ratio/near/far);
// load
matProj
to D3D PROJECTION processor
m
_
pD3DDevice->SetTransform(D3DTS
_
PROJECTION, &matProj);
Listing 14.3.
Details of the matrix processors settings (Tutorial 14.3).
Search WWH ::
Custom Search