Graphics Reference
In-Depth Information
.
A1:
void
UWB
_
Primitive::Draw(eLevelOfDetail lod, UWB
_
DrawHelper& draw
_
helper)
const
{
.
SetupDrawAttributes(draw
_
helper);
DrawPrimitive(lod, draw
_
helper);
.
void
UWB
_
Primitive::SetVelocity(
vec3
velocity){ m
_
velocity = velocity; }
bool
UWB
_
Primitive::IsStationary()
const
{
return
( UWB
_
ZERO
_
TOLERANCE >= fabs(m
_
velocity.x) && ...
.
D1:
void
UWB
_
Primitive::SetupDrawAttributes(UWB
_
DrawHelper& draw
_
helper)
const
{
draw
_
helper.ResetAttributes();
draw
_
helper.SetColor1(m
_
FlatColor);
.
F1:
Listing 7.9.
(cont.)
We made a design decision where for the ease of programming, we have
defined the superset of all primitive attributes in the base class. For ex-
ample, the
m
_
PointSize
attribute is defined. However, this attribute is
only meaningful for a point primitive, and all non-point subclasses will ig-
nore this attribute. In this way, our implementation is not optimized for
memory efficiency. However, because all attributes and their correspond-
ing set/get functions are defined in the
Primitive
base class, all subclass
objects can have uniform public interface functions. As we will see in
the
CModel
implementation, this uniform interface simplifies programming
with the
Primitive
hierarchy.
The
m
_
Velocity
is an unusual attribute to be defined in a primitive hierar-
chy. This is because all other primitive attributes affect the appearance of
the attribute, whereas the velocity affects the physical behavior of the prim-
itive object. Once again, we define this physical attribute in the base class
for the uniformity of public methods and the ease of programming with the
hierarchy.
•
F: The subclass-responsible functions for supporting drawing.
As dis-
cussed, the
Draw()
function specifies the drawing procedure in the form
of pure virtual functions, and the subclass must override these functions
Search WWH ::
Custom Search