TGE/A Freelook on Mouse Button
by Ryan C. Scott · 03/02/2009 (1:22 am) · 4 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.
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.
#2
03/04/2009 (4:35 pm)
Thanx 2:)
#3
other than that it works brilliantly, just what the MMORPG ordered :-)
03/09/2009 (3: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 :-)
#4
09/08/2010 (4:30 am)
where do i put this code?
Torque Owner Richard Preziosi
WinterLeaf Entertainment