Idle() function. The code we write will enter a pick-and-translate mode when the left mouse button is pressed. As the mouse moves we will update the position of the selected atomic. When the mouse is released, we will drop the atomic.
#ifndef UTILS #define UTILS
typedef enum { MMNoOperation, MMPickAndTranslateObject,
MMTranslateObject,
MOUSEMOVEOPERATIONFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
} MouseMoveOperation;
win/events.c to enter the MMPickAndTranslateObject mode when the left mouse button is pressed down. When the mouse button is released enter the MMNoOperation mode.
static RsEventStatus HandleLeftButtonDown(RsMouseStatus *mouseStatus) { /* Left mouse button down event handling... */
MouseMoveAction = MMPickAndTranslateObject;
return rsEVENTPROCESSED;
}
/* HandleLeftButtonUp Function */ static RsEventStatus HandleLeftButtonUp(RsMouseStatus *mouseStatus __RWUNUSED__) { /* Left mouse button up event handling... */ MouseMoveAction = MMNoOperation; return rsEVENTPROCESSED; }
main.c to perform the translation, and create RwV2d OldPos as a file global variable. We will call the TranslateAtomic() function whenever the mouse is dragged around the scene.
f = RwCameraGetFrame(Camera); dx = OldPos.x - MousePos.x; dy = OldPos.y - MousePos.y;
right = *RwMatrixGetRight(RwFrameGetMatrix(f)); up = *RwMatrixGetUp(RwFrameGetMatrix(f));
RwV3dScale(&right, &right, dx*0.01f); RwV3dScale(&up, &up, dy*0.01f); RwV3dAdd(&trans, &up, &right);
f = RpAtomicGetFrame(PickedAtomic); RwFrameTranslate(f, &trans, rwCOMBINEPOSTCONCAT);
OldPos = MousePos;
}
static void Idle(void)
Idle() function to process the new MouseMoveAction. If we detect a pick-and-translate mode, then we will perform a pick, and then switch to a translate state. In the translate state we will call the TranslateAtomic() function to use the change in mouse position to translate the atomic. Modify the Idle() function as shown:
/* Update any animations here... */ lastAnimTime = thisTime; switch(MouseMoveAction) { case MMPickAndTranslateObject : PickedAtomic = RwCameraPickAtomicOnPixel(Camera, &MousePos); if (PickedAtomic) { AtomicGetBBox(PickedAtomic, &PickBox); OldPos = MousePos; MouseMoveAction = MMTranslateObject; } else { MouseMoveAction = MMNoOperation; } break;
case MMTranslateObject : TranslateAtomic(); break;
default: PickedAtomic = NULL; break; } Render();

© 1993-2004 Criterion Software Limited. All rights reserved. Built Thu Feb 12 13:46:58 2004.
Send Feedback