Game Development Community

Mouse Move Function in Torque 3d

by TigerHeros · in Torque 3D Professional · 06/19/2010 (12:21 am) · 5 replies

Hi All

In My Project

When the Mouse cursor is move over the AI Player or an Object. The Normal cursor should change to Hand Cursor.

I have identified the AI Player Object Name through Ray Casting method.


function PlayGui::onMouseMove(%this, %pos, %start, %ray)
{
canvas.setCursor(HandCursor)
}

The above code did not works. How can i do it?.

#1
06/20/2010 (11:49 pm)
I think I have to integrate into the Engine? Could Any one can Give the Proper Link(C++ files) ? or any idea? if the mouse is over the Object. how can i change the Cursor?
#2
06/22/2010 (2:26 am)
Could any One Help me How can i use ContainerRayCast function in mouse move function.

#3
06/22/2010 (10:45 am)
There's nothing wrong with what you're trying to do, but for some reason there is no script callback implemented for the GameTSCtrl onMouseMove method. So it requires a trivial source code change. In "T3D/gameTSCtrl.cpp" add this to the end of "GameTSCtrl::onMouseMove()"

if( isMethod( "onMouseMove" ) )
      makeScriptCall( "onMouseMove", evt );

Recompile. Now you can access onMouseMove from script. So assuming that you turn the PlayGui cursor on via keyboard or whatever, you can handle the script callbacks like this:

// Here's the cursor I'll change to when over an object, etc.
new GuiCursor(HandCursor)
{
   hotSpot = "15 15";
   bitmapName = "core/cursors/CUR_Hand";  // A 20x19 PNG file
};

// Here's the script callback handler
function PlayGui::onMouseMove(%this, %screenPt, %start, %ray)
{
   %ray = VectorScale(%ray, 100);   // The distance to cast the ray
   %end = VectorAdd(%start, %ray);  // end = start point + ray vector

   %mask = $TypeMasks::StaticTSObjectType | $TypeMasks::PlayerObjectType;

   %exclude = ServerConnection.getControlObject(); // Don't hit ourself

   %result = ContainerRayCast(%start, %end, %mask, %exclude);

   if(%result)  // We're over something of interest!
   {
      %obj = GetWord(%result, 0);  // First word is hit object ID

      // Make sure this is not a player (only want AI and static objects)
      if(%obj.getClassName() !$= "Player")
      {
         Canvas.setCursor(HandCursor);
      }
   }
   else   // The raycast hit nothing
   {
      Canvas.setCursor(DefaultCursor);   // Or whatever cursor you want
   }
}

I tried this out on TSStatics and it worked (didn't try the AI player part). This should get you going, but I would suggest moving this to C++ to get a performance boost.
#4
06/23/2010 (10:33 pm)
Thank You Rayan Mounts for your help. It works in Static Object and AI Player also . I have used AIPlayerObjectType type mask to identify the AI Player Name and the cursor is also changing for AI Player.

Thank You.
#5
05/30/2013 (9:30 am)
SetCursor is not working in 3.0 any ideas?

new GuiCursor( HandCursor )
{
hotSpot = "1 1";
renderOffset = "0 0";
bitmapName = "~/art/gui/images/CUR_hand";
};

in the playgui::onMouseMove()

Canvas.setCursor(HandCursor);

no effect .. any ideas?