Idle() function, will use this state to modify the world. The first state that we will capture will be the state of the left mouse button. When we determine that the left mouse button is pressed down we will use RenderWare Graphics collision routines to pick an atomic.
main.c, add a new global RwV2d variable called MousePos and initialize it to {0, 0}. Add an extern declaration for this global in the utils.h header file. In win/events.c, add the following code to track the position of the mouse as it moves in the window:
static RsEventStatus HandleMouseMove(RsMouseStatus *mouseStatus) { /* Mouse move event handling... */ MousePos = mouseStatus->pos; return rsEVENTPROCESSED; }
HandleLeftButtonUp() function, and debug the application. Click the left mouse button in the application window, and look at the global variable MousePos. You should be able to confirm that the position of the mouse is being recorded correctly. This will mean that we are now in a position to record when the user releases the left mouse button, and to do a pick operation to decide whether any cube has been selected.
utils.h create an enumerated type that we can use to record the operation that is to be performed. For now, if the user releases the left mouse button, then we will move from a "No Operation" state into a "Pick" state. We will call these operations "Mouse Move Modes":
#ifndef UTILS #define UTILS typedef enum { MMNoOperation,
MMPickObject,
MOUSEMOVEOPERATIONFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
} MouseMoveOperation;
utils.h header file into main.c. Then define a global variable in main.c called MouseMoveAction. We will use this variable to decide what action to take when the user uses the mouse. Also extern this new variable in the utils.h header file.
win/events.c file, when the user releases the left mouse button, we should change state to the pick operation mode:
return rsEVENTPROCESSED; } /* HandleLeftButtonUp Function */ static RsEventStatus HandleLeftButtonUp(RsMouseStatus *mouseStatus __RWUNUSED__) { /* Left mouse button up event handling... */
MouseMoveAction = MMPickObject;
return rsEVENTPROCESSED;
}
Idle() function in main.c. This code will inspect the state of the MouseMoveAction variable to decide what to do. If it finds that the variable is in the MMPickObject state, then we will perform a ray cast and decide what object, if any, the ray intersects with.
Idle() function to handle the state of MouseMoveAction. Create a file local variable called PickedAtomic of type RpAtomic* that is used to record the result of the RwCameraPickAtomicOnPixel() function. This function, from the RtPick toolkit performs the pick that we are interested in. It actually uses the bounding sphere of the atomic to decide whether an object has been picked, so is at best approximate. It will do for now, however.
/* Update any animations here... */ lastAnimTime = thisTime; switch(MouseMoveAction) {
case MMPickObject : PickedAtomic = RwCameraPickAtomicOnPixel(Camera, &MousePos); MouseMoveAction = MMNoOperation; break; default: break; } Render();
The RtPick toolkit makes use of the collision and intersection libraries. We must register the collision plugin before the RtPick library can be used.
AttachPlugins() function in main.c code to attach the collision plugin.
/* Attach world plug-in... */ if( !RpWorldPluginAttach() ) { return FALSE; }
if (!RpCollisionPluginAttach() ) { return FALSE; }
main.c lines to include the rpcollis.h and rtpick.h header files. Compile the code. Before you can link this project, you will need to add the rtintsec.lib, rpcollis.lib, and rtpick.lib libraries to the project.
#include "rplogo.h" #endif
#include "rpcollis.h" #include "rtcharse.h" #include "rtpick.h"
#include "skeleton.h"
© 1993-2004 Criterion Software Limited. All rights reserved. Built Thu Feb 12 13:46:58 2004.
Send Feedback