Turning on mouselook while right click down
by Justin Knight · in Torque 3D Professional · 02/01/2010 (12:38 pm) · 3 replies
I'm currently trying to turn on mouse look while the right mouse button is down. I've created this function to turn the cursor off on the mouse down event:
The problem I have is that I don't know how to catch the corresponding mouse up. I'm testing for it in PlayGui::onRightMouseUp (didn't expect to get it here anyhow because cursor is off now) and in default.bind.cs:-
If I click a second time the altTrigger bind gets triggered on both mouse down and up and the cursor gets turned on but I'm not sure where the original mouse up event is getting lost.
function PlayGui::onRightMouseDown(%this, %pos, %start, %ray)
{
echo ("PlayGUI rightMouseDown");
Canvas.cursorOff();
}The problem I have is that I don't know how to catch the corresponding mouse up. I'm testing for it in PlayGui::onRightMouseUp (didn't expect to get it here anyhow because cursor is off now) and in default.bind.cs:-
function altTrigger(%val) {
echo( "In altTrigger, val=" @ %val);
if( %val) { //Mouse down
echo( "Right mouse down - turning cursor off");
Canvas.cursorOff();
} else {
echo( "Right mouse up - turning cursor back on");
Canvas.cursorOn();
}
$mvTriggerCount1++;
}
moveMap.bind( mouse, button0, mouseFire );
moveMap.bind( mouse, button1, altTrigger );If I click a second time the altTrigger bind gets triggered on both mouse down and up and the cursor gets turned on but I'm not sure where the original mouse up event is getting lost.
About the author
#2
02/05/2010 (4:27 am)
Thanks very much Henry - just what I needed, and yes it works with T3D.
#3
Only problem I have is that it seems to screw up the world editor - after I mouselook the hotspot for the cursor in the editor isn't under the cursor any more.
02/10/2010 (2:53 pm)
For reference here is my code now to turn mouselook on when right click is down:function mouseFire(%val)
{
$mvTriggerCount0++;
}
function altTriggerGlobal(%val) {
if( %val) { //Mouse down
Canvas.cursorOff();
} else {
Canvas.cursorOn();
}
$mvTriggerCount1++;
}
moveMap.bind( mouse, button0, mouseFire );
//moveMap.bind( mouse, button1, altTrigger );
GlobalActionMap.bind( mouse, button1, altTriggerGlobal);Only problem I have is that it seems to screw up the world editor - after I mouselook the hotspot for the cursor in the editor isn't under the cursor any more.
Torque Owner Henry Todd
Atomic Walrus
1) the cursor is gone, so it can't be a mouse up for the PlayGUI (obviously you already predicted this would happen) and,
2) The engine refuses to send a val 0 moveMap event when a val 1 event hasn't been recorded previously for that bind.
I guess if it was willing to take the up-event and pass it to the moveMap without a previous down-event, you would end up reversing how triggers work, since they function on an incremented global var. It would ++ on mouse up, firing, and then ++ again on mouse down, stopping the fire.
After I typed up all that, I went to see if this had been done as a resource. Apparently the trick is to bind your right mouse button through the global action map, instead of the moveMap. Apparently the global action map always gets called, even if the mouse is being hijacked by a GUI cursor, so you can skip the PlayGUI onMouseDown entirely and just use the bind. This way your up event has a corresponding down event, you don't break the triggers, and it should work.
www.torquepowered.com/community/resources/view/16527
I don't think anyone tried that with T3D, but I'd think it would work. Worst case, you could open up the editor scripts and see how it does this. The disadvantage, as the resource mentions, is that mouse1 is now linked forever to this function, as nothing trumps the globalActionMap. So you can't use right click in your GUI menus, it will always enable freelook.