Graphics Reference
In-Depth Information
else if (nFlags & MK _ RBUTTON)
if (down) // RMB down event
theApp.GetModel().MoveGraphicsObject(...);
void CDrawAndMouseHandler::OnMouseMove( unsigned int nFlags, int hwX, int hwY)
// Hardware to device transform
HardwareToDevice(hwX, hwY, deviceX, deviceY);
if (nFlags & MK _ LBUTTON)
// LMB drag event
theApp.GetModel().EndDefineGraphicsObject(...);
else if (nFlags & MK _ RBUTTON)
// RMB drag event
theApp.GetModel().MoveGraphicsObject(...);
Listing 7.14. (cont.)
7.5
Collisions of Primitives
We have presented a primitive hierarchy with an interface that supports uniform
interactions with different primitive types. From Tutorial 7.2, we have experi-
enced that it is straightforward to work with the hierarchy to create/edit different
primitives with the same set of mouse-click events. We have also seen that the
Primitive base class supports all attributes (e.g., color, fill mode) that affect the
appearance of the primitives. The velocity attribute is different from the rest be-
cause this attribute affects the physical behavior instead of the appearance of the
primitive. In this section, we examine one other physical behavior of primitives:
collision. In a complex library system, physical behavior should be defined as
a separate hierarchy that collaborates with the primitive hierarchy. In the inter-
ests of learning graphics without extensively studying the physical behavior of
objects, we will only work with two physical behaviors in our primitive class: ve-
locity and collision. We have already seen the straightforward effects of velocity,
and in this section, we will examine collision between primitives.
To detect collision between two primitives, we need to compute if the primi-
tives overlap in space. Note that detecting overlapping in space is different from
intersecting primitives. For example, we have experience with detecting circle
collision mathematically in the ball-shooting program, where we compared the
distance between the centers of two circles with the sum of their radii. This is
very different from mathematically intersecting the two circles by computing the
roots to the quadratic functions. In general, when working with many primitive
Search WWH ::




Custom Search