2D Tutorial: Panning and Zooming

The default AppWizard-created application already has pan and zoom capabilities. However, we will review how these capabilities have been hooked up since they serve as a roadmap for adding additional interaction capabilities to your applications.

Creating new Operators

The applications MFC-view class 'CSoccerView' contains the OnPan, OnZoom, and OnZoomToWindow methods, which get called when the user clicks on the various pan/zoom GUI buttons. Each passes a new MVO Operator object to a local utility function LocalSetOperator().


Let's take a look at LocalSetOperator. It gets the current operator object associated with the HBaseView object, deletes it, and sets the new operator.

{
if (op)
delete op;
GetSolidView()->SetOperator(NewOperator);
}

Mapping User Interaction to Operators

But how do subsequent mouse/keyboard events results in a pan or zoom operation? All we've done is set an operator on the current view! Let's remember that CSoccerView (along with CSoccerDoc and CSoccerApp) are derived from the HOOPS/MFC base classes. We take a closer look at the CHoopsView mouse handling methods to see what's happening. (The HOOPS/MFC source is located in your <hoops>/dev_tools/hoops_mfc/source directory) The CHoopsView::OnLButtonDown method sets up an HEventInfo object with the event type, local XY point and UI flags. It then calls an 'event listener' macro which will send the HEventInfo object to the current operators 'matching' OnLButtonDown method.

void CHoopsView::OnLButtonDown(UINT nFlags, CPoint point)
{
if (m_pHView)
{
event.SetPoint(HE_LButtonDown, point.x, point.y, MapFlags(nFlags));
HLISTENER_EVENT(HMouseListener, m_pHView->GetEventManager(), OnLButtonDown(event))
if (op)
{
if (op->Capture())
SetCapture();
}
else
CView::OnLButtonDown(nFlags, point);
}
}

Similar functions exist for other mouse and keyboard events, and the HOOPS/QT integrations supplied HQWidget does the same thing for mouse/keyboard events. So, whenever user interaction occurs in the view, the generated event gets mapped/dispatched to the current operators corresponding method. The HOOPS/MVO pan and zoom operators implement pan and zoom functionality be making appropriate camera modifications within their various mouse down, motion and up methods. Take a look at the documentation for HOpCameraZoom to see what methods it implements.

Creation and usage of operators is reviewed in sections 2.4 -> 2.6 of the HOOPS/MVO Programming Guide