Game Development Community

TGE/A Freelook on Mouse Button

by Ryan C. Scott · 03/02/2009 (9:22 am) · 3 comments

For games needing to use the gui cursor and providing freelook functionality when a mouse button is held down (like the way the editor works).

First off, a touch of script to get things working:

///////////////////////////////////

function freelook( %val ) {
if( %val ) cursorOff();
else cursorOn();
}

globalActionMap.bind( mouse, button1, freelook );

///////////////////////////////////


What makes that happen/work:
In game/main.cc, input events are doled out to the global input map, the Canvas control (which is a globally accessible instance of GuiCanvas::), and the regular input map stack.

So in the case of mouse input once you turn the cursor on, the Canvas object will then process mouse events and grab the release event. This is why you need to bind any mouse functions that turn on the cursor in the globalActionMap so that the button release will still be processed with the Gui cursor on. This has the side effect of making it so whatever mouse button you bind not getting passed through to the Gui any longer. In the case of the right button that's generally not a problem as it's not used by default, but your mileage may vary.

Note: In windowed mode you may get some issues with the placement of the mouse cursor when turning it on and off depending on your platform. Others have battled with similar issues, but seeing if getMousePosition/setMousePosition solve your problem is as good a place to start as any other.

About the author

Recent Blogs

• TGE using Ogre3d

#1
03/02/2009 (9:29 am)
Just wanted to say thanks for the millionth time, saved me so many headaches.
#2
03/05/2009 (12:35 am)
Thanx 2:)
#3
03/09/2009 (10:32 am)
small modification for TGEA 1.8.1 maybe for other versions.

function freelook( %val ) { 
if( %val ) canvas.cursorOff(); 
else canvas.cursorOn(); 
}

other than that it works brilliantly, just what the MMORPG ordered :-)