Graphics Reference
In-Depth Information
to implement the actual drawing operations. As illustrated at label F1, by
default, the Primitive base class resets all drawing attributes and sets the
flat shading color. Subclasses must override this function to set individual
primitive-specific attributes.
Because some of the functions in the Primitive class are undefined (e.g., Draw
Primitive() ), this is a pure virtual class and we cannot instantiate objects of this
class.
The concrete Primitive classes. The PrimitivePoint class subclasses from
the Primitive class and implements the behavior of a point primitive. List-
ing 7.10 shows that the PrimitivePoint class overrides the update (A) and the
mouse editing functions (B). As illustrated at label A1, the update function as-
sumes that the velocity is defined as units per second and simply moves the po-
sition of the point. The mouse editing support functions at B1 always set the
point location. The set/get location functions (at label C1) are defined to sup-
port the definition of vertex position for the point. Notice the implementation of
the DrawPrimitive() function (D1) and the collaboration with the superclass of
the set attribute function (D2). These two functions are called when the Draw()
method tries to draw a point.
Listing 7.11 shows that the PrimitiveLine class is similar to the Primitive
Point class. The line class overrides the update (A) and mouse editing functions
(B) and implements the set-up draw attribute and draw primitive functions (D).
In this case, the line class has different vertex geometry accessing functions at
label C for setting and getting the endpoints (defined at label E). The implemen-
tation of the Update() function at label A1 shows behavior similar to the point
primitive, where in this case, both of the endpoints are moved (the entire line
will move). The implementation of mouse editing functions at B1 shows that the
vertexID can be used to encode the n th mouse click.
In this case, during the
first ( vertexID =
0) mouse click, both of the points on the line are set. In subse-
quent mouse clicks, only the endpoint of the line is affected. As will be shown
in the CModel implementation, this functionality allows us to always draw a line
from the first mouse click position to the current mouse position for line editing.
Lastly, the implementation of the attribute setting function at label D2 shows the
line collaborating with the superclass and setting Gouraud shading attributes.
Listing 7.12 shows that the PrimitiveCircle class is similar to the point
and line classes. In fact, all concrete subclasses of the Primitive class will have
this similar structure. In this case, at label A1 we see that the Update() function
moves the center of the circle. At label B1, once again we see that the vertexID
is being treated as the n th mouse click, where we define the circle center and
Search WWH ::




Custom Search