Mouse Controls
by Xavier "eXoDuS" Amado · 02/12/2002 (10:23 am) · 15 comments
In this tutorial we will add some mouse controls to the torque options dialog.
First let's add the two new gui controls in the options dialog. So open up optionsDlg.gui (fps/client/ui/optionsDlg.gui) and find the section for the controls Pane. It should read like this:
Notice that it doesnt have any closing brace after the last parameter. That's because we can add other gui controls inside this one, making them childs of the OptControlsPane. So after that block of code add these 2 new gui Controls:
Ok, notice the first one is a checkbox, we will use this one to set if we want inverted mouse look or normal mouse look. The variable used for this will be $pref::Input::MouseInvert. Then we have a slider, which we'll use to adjust the mouse's sensivity. Notice this one when changed executes the OptMouseSetSensivity() function with the value passed as parameter.
We will now change some sizes from the optionsDlg to make room for the two new controls. In the new GuiControl(OptControlsPane) { change the extent parameter to "357 250".
Now search for new GuiWindowCtrl() { at the top of the file and change its extent parameter to "377 340". Finally look for the following button:
In this button let's change the position to "305 310". Ok, done with the gui.
Well now open up optionsDlg.cs (fps/client/scripts/optionsDlg.cs) and look for the function OptionsDlg::onWake(%this). At the end of this function add the following line:
Now add the following code somewhere in optionsDlg.cs. It doesnt really matter where, for example add it at the end of the file.
That function sets the $pref variable to the value selected on the slider.
Open up default.bind.cs and search for "function pitch(%val)" change that function so it looks like this one:
What we changed here is to enable the invert mouse, depending on the state of the Invert Mouse Checkbox, which toggles beetween 1 or 0, this function will adjust the pitch to either positive or negative movement.
Now some lines up you should see the function getMouseAdjustAmount, change it so it looks like this one:
This one determines the movement amount, it multiplies (%val * ($cameraFov / 90) * 0.01) with the value chosen in the slider (which was assigned to the $pref::Input::MouseSenivity variable).
Ok that's all, now go into the game and you should be able to invert the mouse and to adjust its sensivity. If not email me: reivax (at) sinectis (dot) com (dot) ar
Or basically, reivax@sinectis.com.ar :)
Thanks to everyone on that Invert Mouse forum thread !!
First let's add the two new gui controls in the options dialog. So open up optionsDlg.gui (fps/client/ui/optionsDlg.gui) and find the section for the controls Pane. It should read like this:
[b]
new GuiControl(OptControlsPane) {
profile = "GuiWindowProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "9 55";
extent = "357 208";
minExtent = "8 8";
visible = "0";
helpTag = "0";[/b]Notice that it doesnt have any closing brace after the last parameter. That's because we can add other gui controls inside this one, making them childs of the OptControlsPane. So after that block of code add these 2 new gui Controls:
[b]
new GuiCheckBoxCtrl() {
profile = "GuiCheckBoxProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "7 210";
extent = "140 30";
minExtent = "8 8";
visible = "1";
variable = "$pref::Input::MouseInvert";
helpTag = "0";
text = "Invert Mouse?";
groupNum = "-1";
buttonType = "ToggleButton";
};
new GuiSliderCtrl(OptMouseSensitivity) {
profile = "GuiSliderProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "179 217";
extent = "170 34";
minExtent = "8 8";
visible = "1";
variable = "value";
altCommand = "OptMouseSetSensitivity(OptMouseSensitivity.value);";
helpTag = "0";
range = "0.100000 2.000000";
ticks = "1000";
value = "0.12375";
};[/b] Ok, notice the first one is a checkbox, we will use this one to set if we want inverted mouse look or normal mouse look. The variable used for this will be $pref::Input::MouseInvert. Then we have a slider, which we'll use to adjust the mouse's sensivity. Notice this one when changed executes the OptMouseSetSensivity() function with the value passed as parameter.
We will now change some sizes from the optionsDlg to make room for the two new controls. In the new GuiControl(OptControlsPane) { change the extent parameter to "357 250".
Now search for new GuiWindowCtrl() { at the top of the file and change its extent parameter to "377 340". Finally look for the following button:
[b]
new GuiButtonCtrl() {
profile = "GuiButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "305 270";
extent = "60 23";
minExtent = "8 8";
visible = "1";
command = "Canvas.popDialog(optionsDlg);";
helpTag = "0";
text = "OK";
};[/b] In this button let's change the position to "305 310". Ok, done with the gui.
Well now open up optionsDlg.cs (fps/client/scripts/optionsDlg.cs) and look for the function OptionsDlg::onWake(%this). At the end of this function add the following line:
[b]
OptMouseSensitivity.setValue( $pref::Input::MouseSensitivity);[/b] Now add the following code somewhere in optionsDlg.cs. It doesnt really matter where, for example add it at the end of the file.
[b]
function OptMouseSetSensitivity(%value)
{
$pref::Input::MouseSensitivity = %value;
}[/b] That function sets the $pref variable to the value selected on the slider.
Open up default.bind.cs and search for "function pitch(%val)" change that function so it looks like this one:
[b]
function pitch(%val)
{
if($Pref::Input::MouseInvert)
$mvPitch -= getMouseAdjustAmount(%val);
else $mvPitch += getMouseAdjustAmount(%val);
}[/b] What we changed here is to enable the invert mouse, depending on the state of the Invert Mouse Checkbox, which toggles beetween 1 or 0, this function will adjust the pitch to either positive or negative movement.
Now some lines up you should see the function getMouseAdjustAmount, change it so it looks like this one:
[b]
function getMouseAdjustAmount(%val)
{
// based on a default camera fov of 90'
return((%val * ($cameraFov / 90) * 0.01) * $pref::Input::MouseSensitivity);
}[/b] This one determines the movement amount, it multiplies (%val * ($cameraFov / 90) * 0.01) with the value chosen in the slider (which was assigned to the $pref::Input::MouseSenivity variable).
Ok that's all, now go into the game and you should be able to invert the mouse and to adjust its sensivity. If not email me: reivax (at) sinectis (dot) com (dot) ar
Or basically, reivax@sinectis.com.ar :)
Thanks to everyone on that Invert Mouse forum thread !!
#2
exposing it in gui will be easy... just add a lil control that changes that value...
02/16/2002 (12:06 pm)
mmm... looks nice to me :)exposing it in gui will be easy... just add a lil control that changes that value...
#3
//set your exit to this
function onOK()
{
setMouse();
Canvas.popDialog(optionsDlg);
}
//function to bind the mouse controls
function setMouse()
{
%yFlags = chkInvert.getValue() ? "SI" : "S";
%sens = SensitivitySlider.getValue();
moveMap.bind(mouse0, "yaxis", %yFlags, %sens, pitch);
moveMap.bind(mouse0, "xaxis", S, %sens, yaw);
}
function OptionsDlg::onWake(%this)
{
SensitivitySlider.setValue( moveMap.getScale( mouse, yaxis ));
chkInvert.setValue( moveMap.isInverted( mouse, yaxis ) );
}
04/27/2002 (10:39 pm)
With help from T2 to find the proper function//set your exit to this
function onOK()
{
setMouse();
Canvas.popDialog(optionsDlg);
}
//function to bind the mouse controls
function setMouse()
{
%yFlags = chkInvert.getValue() ? "SI" : "S";
%sens = SensitivitySlider.getValue();
moveMap.bind(mouse0, "yaxis", %yFlags, %sens, pitch);
moveMap.bind(mouse0, "xaxis", S, %sens, yaw);
}
function OptionsDlg::onWake(%this)
{
SensitivitySlider.setValue( moveMap.getScale( mouse, yaxis ));
chkInvert.setValue( moveMap.isInverted( mouse, yaxis ) );
}
#4
07/13/2002 (7:18 am)
the stupid copiers among us could need a ready-to-cut&paste function for what Joel mentioned - anyone up to that?
#5
07/16/2002 (6:30 am)
Well I added everything, but now I cant move the mouse anymore.
#6
11/19/2002 (8:32 pm)
Really usefull. My brother has the brain inverted compared to mine so he's now happy :) It's a must have for all games. Thanks Much Xavier
#7
03/09/2003 (12:49 pm)
Being of the inverted-brains of our species (it happens to all flight-sim lovers), I'm really happy I came across this :))
#8
04/20/2004 (6:33 am)
Great Great!!! i just add it into my proyect, THANKS!
#9
this should be in HEAD ....
08/18/2004 (1:20 pm)
well you have save me for some work ..... thanksthis should be in HEAD ....
#10
11/24/2005 (8:05 pm)
why this is still not in HEAD? ;)
#12
11/22/2006 (9:42 am)
Great resource thanks :D
#13
Xavier... Why not update? 5 years and you still didn't have time to update? :P
04/22/2007 (1:24 pm)
Still works with the changes John Hortenstine mentions in TGEA. Xavier... Why not update? 5 years and you still didn't have time to update? :P
#14
12/16/2007 (6:11 pm)
FYI your mouse may not work at all when you first try it. This is because you haven' t yet set the values in the options dialog. Just go in there and set some values, and you'll be fine.
#15
08/09/2008 (5:38 am)
WooooW... great resource... 
Torque 3D Owner Joel Baxter
Inversion and sensitivity are specified when you bind a mouse axis to a function. For instance, the bind command
moveMap.bind(mouse0, "yaxis", S, 1.000000, pitch);
binds the mouse Y axis to the "pitch" function, non-inverted, with a scaling (sensitivity) of 1.0.
You can specify a different scaling instead of 1.0 AFAIK, although I haven't tried it personally yet since I'm happy with 1.0.
As for inversion, you add an "I" to the input characteristics, like:
moveMap.bind(mouse0, "yaxis", SI, 1.000000, pitch);
"S" is for "scaled", "I" is for "inverted". There's also "D" for "deadzone" available; if there's a deadzone, insert the argument specifying the deadzone before the scale.
Now, I don't know how you'd want to go about exposing that to a GUI, but if you have Tribes 2 you could look at those scripts to get ideas. Anyway, your solution looks like it would be functional, but just FYI it does a little more runtime work than it needs to.