Graphics Reference
In-Depth Information
Model
External
Events
Program code for updating application state:
UpdateSimulation()
// move balls ...
...
SetHeroVelocity()
// return current hero's velocity ...
Controller
MainEventLoop()
(GUI API)
Program code from Listing 1.6:
LMBDownRoutine (mousePosition)
// define Hero Ball center ...
...
ServiceTimer ()
UpdateSimulation()
...
RedrawRoutine ()
DrawBalls( ... )
...
Persistent application state :
AllWorldBalls, HeroBall
DefiningNewHeroBall
Graphics API
View
Program code for drawing application state:
DrawView() // draw window region
TransformPoints() // window to view specifc
...
// there are other routines for interfacing
// to the Graphics API ...
Figure 5.1.
Components of an interactive graphics application.
MVC framework, the model component is the application state, the view com-
ponent is responsible for providing the support for the model to present itself to
the user, and the controller component is responsible for providing the support
for the user to interact with the model. Within this framework, our solution from
Section 1.6 (Listing 1.7) is simply the implementation of a controller. In this chap-
ter, we will develop the understanding of the other two components in the MVC
framework and how these components collaborate to support interactive graphics
applications.
Figure 5.1 shows the details of an MVC framework to describe the behavior
of a typical interactive graphics application. We continue to use the ball-shooting
program as our example to illustrate the details of the components. The top-right
rectangular box is the model, the bottom-right rectangular box is the view, and
the rectangular box on the left is the controller component. These three boxes
represent program code we, as application developers, must develop. The two
dotted rounded boxes represent external graphics and GUI APIs.
The model component defines the persistent application state (e.g., AllWorld
Balls , HeroBall ) and implements interface functions for this application state
(e.g., UpdateSimulation() ). Because we are working with a “graphics” ap-
plication, we expect graphical primitives to be part of the representation for the
application state (e.g., CirclePrimitives ). This fact is represented in Figure 5.1
by the application state (the ellipse) partially covering the graphics API box. In
the rest of this section, we will use the terms model and persistent application
state interchangeably.
Search WWH ::




Custom Search