I am just trying to code up a quick arc ball system for my RTS Camera. What I want to do is:
When the user right clicks 'down' the current mouse coordinates are saved and mouse cursor should disappear, then on a mouse move (while the right button is still down), the change in mouse coordinates (from the saved ones) is found. The mouse is then returned to the position that is saved. The camera is then rotated in a direction that depends on the change mouse in coordinates. When the right mouse button is released the mouse becomes visible and is at the same location it was when the button was pressed down.
So here is the code:
Code: Select all
//... an input handling method, handles SEvent event;
if( event.MouseInput.Event == EMIE_MOUSE_MOVED ){
// mouse move
// handle the move if needed
if( keydown == 0 ){
if( event.MouseInput.X <= mMouseThresh[LEFT] ) mDoMove[LEFT] = true; else mDoMove[LEFT] = false;
if( event.MouseInput.X >= mMouseThresh[RIGHT] ) mDoMove[RIGHT] = true; else mDoMove[RIGHT] = false;
if( event.MouseInput.Y <= mMouseThresh[UP] ) mDoMove[UP] = true; else mDoMove[UP] = false;
if( event.MouseInput.Y >= mMouseThresh[DOWN] ) mDoMove[DOWN] = true; else mDoMove[DOWN] = false;
}
// handle the rotate if needed
if( mArcBallActive ){
if( event.MouseInput.X - mArcBeginX > 0 ) mDoRotate[RIGHT] = true; else mDoRotate[RIGHT] = false;
if( event.MouseInput.X - mArcBeginX < 0 ) mDoRotate[LEFT] = true; else mDoRotate[LEFT] = false;
if( event.MouseInput.Y - mArcBeginY > 0 ) mDoRotate[DOWN] = true; else mDoRotate[DOWN] = false;
if( event.MouseInput.Y - mArcBeginY < 0 ) mDoRotate[UP] = true; else mDoRotate[UP] = false;
mDevice->getCursorControl()->setPosition( irr::core::position2d<s32>(mArcBeginX, mArcBeginY) );
}
/*
.. more code here ..
*/
} else if( event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN ){
// r mouse click down
cout << " arc ball started " << endl;
mArcBallActive = true;
mArcBeginX = event.MouseInput.X;
mArcBeginY = event.MouseInput.Y;
//mDevice->getCursorControl()->setVisible( false );
} else if( event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP ){
// r mouse release
cout << " arc ball ended " << endl;
mArcBallActive = false;
mDoRotate[RIGHT] = false;
mDoRotate[LEFT] = false;
mDoRotate[DOWN] = false;
mDoRotate[UP] = false;
mDevice->getCursorControl()->setPosition( irr::core::position2d<s32>(mArcBeginX, mArcBeginY) );
mDevice->getCursorControl()->setVisible( true );
}
Anyone know whats wrong?
thanks,
sevans