typedef enum { MMNoOperation, MMPickAndTranslateObject, MMPickAndRotateObject, MMPickAndZTranslateObject, MMTranslateObject, MMRotateObject, MMZTranslateObject, MMRotateCameraStart, MMRotateCamera, MMPanCameraStart, MMPanCamera, MMDollyCameraStart, MMDollyCamera, MOUSEMOVEOPERATIONFORCEENUMSIZEINT = RWFORCEENUMSIZEINT } MouseMoveOperation;
win/events.c to enter these new modes according to whether the shift or control keys are held down. In the code below, shift enters the rotate camera mode, control the dolly mode, and neither, the pan mode. This was chosen to reflect the operations performed on atomics.
static RsEventStatus HandleRightButtonDown(RsMouseStatus *mouseStatus) { /* Right mouse button down event handling... */ if (mouseStatus->shift) { MouseMoveAction = MMRotateCameraStart; } else if (mouseStatus->control) { MouseMoveAction = MMDollyCameraStart; } else { MouseMoveAction = MMPanCameraStart; } return rsEVENTPROCESSED;
}
Idle() function in main.c, add code to process these new modes. The code will be very similar to the MMRotateCameraStart mode. Call functions called DollyCamera() and PanCamera().
case MMRotateCameraStart : RotateCamera(TRUE); MouseMoveAction = MMRotateCamera; break;
case MMRotateCamera : RotateCamera(FALSE); break;
case MMDollyCameraStart : DollyCamera(TRUE); MouseMoveAction = MMDollyCamera; break;
case MMDollyCamera : DollyCamera(FALSE); break;
case MMPanCameraStart : PanCamera(TRUE); MouseMoveAction = MMPanCamera; break;
case MMPanCamera : PanCamera(FALSE); break;
DollyCamera() and PanCamera() functions. These functions operate in an identical manner to the function we wrote earlier to rotate the camera. In both the new cases the functions access the current values of the camera's matrix and use the vectors to translate the camera. We will use up and down motion of the mouse to move the camera forward and backwards, and up and down and left and right movements to pan the camera. As we have done before we will convert movement of the mouse into dx and dy variables that are used to scale the vectors.
static void DollyCamera(RwBool first) { RwFrame *f; RwV3d at; RwReal dy; if (!first) { f = RwCameraGetFrame(Camera); at = *RwMatrixGetAt(RwFrameGetMatrix(f)); dy = OldPos.y - MousePos.y; RwV3dScale(&at, &at, dy*0.1f); RwFrameTranslate(f, &at, rwCOMBINEPOSTCONCAT); } OldPos = MousePos;
}
/* ***************************************************************************** */ static void PanCamera(RwBool first) { RwFrame *f; RwV3d right, up, trans; RwReal dx, dy; if (!first) { f = RwCameraGetFrame(Camera); right = *RwMatrixGetRight(RwFrameGetMatrix(f)); up = *RwMatrixGetUp(RwFrameGetMatrix(f)); dx = OldPos.x - MousePos.x; dy = OldPos.y - MousePos.y; RwV3dScale(&right, &right, dx*0.1f); RwV3dScale(&up, &up, dy*0.1f); RwV3dAdd(&trans, &up, &right); RwFrameTranslate(f, &trans, rwCOMBINEPOSTCONCAT); } OldPos = MousePos;
}
Now we will change the RotateCamera() function to support rotation of the camera about the x-axis as the mouse moves up and down. This will allow the camera to look up and down, as well as left and right.
RotateCamera() function:
/* RotateCamera function */ static void
RotateCamera(RwBool first) { static const RwV3d xaxis = {1.0f, 0.0f, 0.0f}; static const RwV3d yaxis = {0.0f, 1.0f, 0.0f}; RwFrame *f; RwReal dx, dy;
f = RwCameraGetFrame(Camera); RwFrameRotate(f, &yaxis, dx * 0.1f, rwCOMBINEPRECONCAT); RwFrameRotate(f, &xaxis, -dy * 0.1f, rwCOMBINEPRECONCAT);
}
OldPos = MousePos;
}
/* RotateCamera function */ static void
RotateCamera(RwBool first) { static const RwV3d xaxis = {1.0f, 0.0f, 0.0f}; static const RwV3d yaxis = {0.0f, 1.0f, 0.0f}; RwFrame *f; RwReal dx, dy;
if (!first) { RwMatrix *m; dx = OldPos.x - MousePos.x; dy = OldPos.y - MousePos.y; f = RwCameraGetFrame(Camera); RwFrameRotate(f, &yaxis, dx * 0.1f, rwCOMBINEPRECONCAT); RwFrameRotate(f, &xaxis, -dy * 0.1f, rwCOMBINEPRECONCAT);
m = RwFrameGetMatrix(f);
RwV3dCrossProduct(&m->right, &yaxis, &m->at); m->right.y = 0.0f; RwV3dNormalize(&m->right, &m->right); RwV3dCrossProduct(&m->up, &m->at, &m->right); RwV3dNormalize(&m->up, &m->up); RwV3dCrossProduct(&m->right, &m->up, &m->at); } OldPos = MousePos;
}

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