i
i
i
i
i
i
i
i
488 19. Building Interactive Graphics Applications
In this way, we derive a framework that is suitable for implementing general in-
teractive graphics applications. With a proper framework guiding our design and
implementation, we will be better equipped to develop programs that are easier to
understand, maintain, modify, and expand.
19.3.1 The Modelview-Controller Framework
Based on our experience developing solutions in Section 19.2, we understand that
interactive graphics applications can be described as applications that allow users
to interactively update their internal states. These applications provide real-time
visualization of their internal states (e.g., the free-falling balls) with computer
graphics (e.g., drawing circles). The modelview-controller (MVC) framework
provides a convenient structure for discussing this type of application. In the
MVC framework, the model is the application state, the view is responsible for
setting up support for the model to present itself to the user, and the controller
is responsible for providing the support for the user to interact with the model.
Within this framework, our solution from Figure 19.8 is simply the implementa-
tion of a controller. In this section, 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 19.10 shows the details of a 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. These are the
external libraries that we will use as a base for building our system. Examples of
popular Graphics APIs include OpenGL, Microsoft Direct-3D (D3D), Java 3D,
among others. As mentioned in Section 19.2.2, examples of popular GUI APIs
include GLUT, FLTK, MFC, and Java Swing Library.
The model component defines the persistent application state (e.g., AllWorld-
Balls, HeroBalls, etc.) and implements interface functions for this application
state (e.g., UpdateSimulation()). Since 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 19.10
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.