Game Development Community

Mouse-look

by Dave Strock · in Torque Game Engine · 06/13/2002 (4:59 pm) · 12 replies

First the question(s):

0) Can anyone point me to where the World Editor handles the the mouse-look effect? The one when you hold down the right mouse button in the render window and it moves the camera up or down, and turns the player model. I've looked through all the editor .cs files, as wells as many other places and I can't seem to find it.

1) How do you get the cursor to permanently show up? I've seen CursorOn() used in a few places, is that how its done?

Now I'll give a short description of what I'm trying to do:

I'm trying to get my default camera to behave exactly the way it does in the world editor. I want it to follow the player as they run around, etc, and only change angles on a right-click mouse-look kind of thing, just like in the world editor. I don't want it to be like the "free look" where it orbits the player. Oh, and I also want the cursor to always be visible/usable (except when mouse-look is on). I was going to work out the new camera mode myself, but then I noticed that the world editor behaves exactly how I want it, so I'd like to track that down.

Any advice would be great. Thanks.

#1
06/14/2002 (2:33 pm)
Well the mouse-look effect turns out to be pretty easy to do. I just created a new ActionMap and bound the xaxis to yaw and yaxis to pitch, just like it used to be in moveMap. Then just made a toggle in moveMap to push my newMap.

Anyway, I thought that would be the harder of the two questions and it turned out to be easy. I still haven't figured out how to have the cursor show up permanently.

There is GuiCanvas::checkCursor() defined in the CanvasCursor package in cursor.cs. It's called each time you push or pop a dialog, or do a setContent() to the canvas. The comment for checkCursor says that it iterates through all the controls and looks to see if they have the .noCursor attribute set. If all of them have .noCursor set then the cursor is not displayed, otherwise it is displayed. The problem is, I have controls in playGui that do not have .noCursor set, and yet the cursor is not displayed.

Anyone have any idea on how to get the cursor on permanently?
#2
06/15/2002 (5:06 am)
put someplace like default.bind.cs...


function toggleCursor(%val)
{
   if(%val)
   {
      if(Canvas.isCursorOn())
         CursorOff();
      else
         CursorOn();
   }
}
moveMap.bind(keyboard, "c",           "toggleCursor");
#3
06/15/2002 (2:38 pm)
Ok, thanks. Thats helpfull. Atleast I can get the cursor up there now.

I was trying to get this to work automatically, using CusorOn() in PlayGui:onAwake() but that didn't work. I didn't even think about binding a key to do it manually.

The problem I'm having now, is that when the cursor is up, it doesn't seem to listen to some of my other bound commands. For instance, I have the right mouse button bound to my new mouse-look, but while the cursor is up (either from toggling it on, or from toggling my inventory on) the right mouse button doesn't do anything. I can still run around and control the player, etc while the cursor is up in either of those modes, but the mouse-look doesn't work.

Any ideas on whats going on?

What I really need to do is find out how the world editor does it. I just can't figure it out tho. There are onRightMouse[Up/Down] functions that seem to call empty on3DRightMouse[Up/Down] functions. I don't really know where else to look.
#4
06/16/2002 (4:00 pm)
look at the mouse handlers in GuiShapeNameHud, GuiTSCtrl, EditTSCtrl, TerrainEditor, WorldEditor & GameTSCtrl.

No all of them will have mouse handlers. The solution is probably in one of EditTSCtrl, TerrainEditor or WorldEditor. You probably implement something similar in GuiShapeNameHud.

Not sure though, but thats the general vicinity.
#5
02/03/2006 (10:31 am)
Dave, have you figured out how to do this yet? I know it's been a long time since this post, but I'm trying to do the exact same thing that you mentioned in your original post.

I've been messing with this for a while now, and have tried all sorts of things and also cannot get this to work. I've even tried the "advanced camera" type resources that are floating around and still do not get the desired effect. I've also exposed most of the mousexxxx commands so they "pass through" to the parent controls, with no success.

I can get it to work fine if I use a different key (instead of the right mouse button) to get it working, but thats obviously not desired. Since the world editor is doing this, it's at least *possible*, its just a matter of figuring it out.

Did you ever find a solution to this?
#6
02/03/2006 (2:32 pm)
Cursor to be on all the time client/ui/ nocursor = "0"
#7
02/03/2006 (2:34 pm)
Oi just realized its a old post...
#8
07/08/2006 (9:09 am)
Quote:
Well the mouse-look effect turns out to be pretty easy to do. I just created a new ActionMap and bound the xaxis to yaw and yaxis to pitch, just like it used to be in moveMap. Then just made a toggle in moveMap to push my newMap.

Can you post some more specifics on this? I am seeking the same functionality in my game.
#9
01/03/2007 (4:05 am)
I'm look for hold down the right mouse-button to look around codes too.
anyone can post the answer?

here's my code:
moveMap.bind(mouse, "button1", FreeLook);
function FreeLook( )
{
      $mvFreeLook = true;
       yaw ;
       pitch;
}

but it won't stop free look. how to correct this?
How do I know the mouse button is pressed or released?
#10
01/03/2007 (4:10 am)
You are missing the variable in the function;
function FreeLook( %val )
%val will be 1 for pressed and 0 for depressed. You can set the $mvFreeLook variable to %val.
#11
01/03/2007 (5:22 am)
It only do once every click. It can't run continued.
here's my code:
moveMap.bind( mouse, "button1", FreeLook);

function FreeLook(%val)
{      
$mvFreeLook = %val;
if (%val)
{
echo("pressed.......");
yaw(%val);
pitch(%val);
}
else
echo("released.....");
}

How to run continued while I pressed right button?
Just like press F11 in world editor.
thanks.
#12
01/03/2007 (6:31 am)
I figure it out: hold down the right mouse-button to look around .
Here's correct code:
//moveMap.bind( mouse, xaxis, yaw );
//moveMap.bind( mouse, yaxis, pitch );
moveMap.bind( mouse, "button1", FreeLook);

function FreeLook(%val)
{
  if (%val)
  {
    echo("pressed.......");
    moveMap.bind( mouse, xaxis, yaw );
    moveMap.bind( mouse, yaxis, pitch );
  }
  else
  {
    echo("released.....");
    moveMap.bind( mouse, xaxis, "");
    moveMap.bind( mouse, yaxis, "");
  }
}

I'm not sure it has good performance or not. but it works.
If you have best answer, please post it here, thanks.