Fake Arcball rotation

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
sevans
Posts: 6
Joined: Thu Mar 01, 2007 6:00 am

Fake Arcball rotation

Post by sevans »

Hey,

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 );
}
The problem I am having is that once the user presses down the right click button, the game essentially freezes and no frames are drawn, until the user releases the right mouse button. This also means that the rotation is not taking place.

Anyone know whats wrong?

thanks,
sevans
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

if program freezes you may have infinitive loop. maybe some other part of the code causes it
Post Reply