Graphics Reference
In-Depth Information
Control
class is capable of controlling any
XformInfo
object inside a
CModel
class that implements
SetSelected Xform()
and
GetSelectedXform()
:
Source
file.
Model.h
file
in
the
Model
folder
of
the
// Access the currently selected XformInfo object
UWB
_
XformInfo
GetSelectedXform
()
const
;
// Sets the currently selected XformInfo object
void SetSelectedXform
(
const
UWB
_
XformInfo& xform);
D3D
_
XformInfoControls
project.
The tutorials in the rest of this topic will reuse the
XformInfo
control GUI con-
tainer window and the corresponding
XformInfoControl
class for controlling
transformations.
Tutorial 9.8. The Ball-Shooting Program with
XformInfo
Tutorial 9.8.
Project Name:
D3D
_
BallShoot3
Library Support:
UWB
_
MFC
_
Lib1
UWB
_
D3D
_
Lib9
•
Goals.
Understand that we can accomplish all primitive movements and
size changes by working with transformations.
•
Approach.
Re-implement the
CBall
class in the ball-shooting program
to include an instance of
XformInfo
and support interaction via updating
transformations.
Figure 9.19 is a screenshot of running Tutorial 9.8. Notice that the behavior of
this program is identical to the ball-shooting program we have worked with. In
fact, the only difference in this implementation is in the
CBall
implementation.
Listing 9.13 shows the details of the
CBall
class. In this implementation, whereas
the
CBall
class still subclasses from the
PrimitiveCircle
, we will support all
geometry changes via the
m
_
Xform
(an
XformInfo
) object defined at label C. No-
tice that at label D, the constructor, we initialize the superclass circle to be a unit
circle located at the origin. This unit circle is the reference for all transformation
and will remain constant throughout the lifetime of the
CBall
object. At label
A, we override all of the geometry-related functions. At label A1, we implement
the corresponding functions by manipulating the
m
_
Xform
object with respect to
the underlying unit circle. For example, instead of changing the center position
of the circle, we implement the
MoveTo()
function by translating the unit circle;
changing the radius of a circle is implemented as scaling the unit circle; and so on.
With the proper transformation settings, label B1 shows that we draw the
CBall
object by first setting up the model transformation and then sending the vertices
of a unit circle down.
In this tutorial, we observe that transformation can be a valuable tool for sup-
porting user interaction. In general, if a user wants to manipulate the geometry
of a complex object with a large number of vertices, it can become expensive to
recompute the object's position and update all the vertices. For example, if the
Figure 9.19.
Tutorial
9.8.
Search WWH ::
Custom Search