Game Development Community

[Solved] OnMouseDown and other callbacks (T3D 1.1)

by Luis E Pabon · in Torque 3D Professional · 07/20/2011 (9:32 pm) · 3 replies

Sorry if there's a thread about this already. Searching for OnMouseDown on the forum search gives me no results.

I have been trying to get mouse callbacks working on a project, but they are not triggering. I even checked on the source code, but it just never triggers on PlayGui. I even tried using the exact code from the RTS tutorial, which others have confirmed works on older builds of T3D.

#1
07/21/2011 (9:33 am)
PlayGui is a GameTSCtrl. Unfortunately, the callback does not comply with documentation standards, which is why it is not showing up in the CHM. Here is the GameTSCtrl function for onMouseDown:

void GameTSCtrl::onMouseDown(const GuiEvent &evt)
{
   Parent::onMouseDown(evt);
   if( isMethod( "onMouseDown" ) )
      makeScriptCall( "onMouseDown", evt );
}

That leads into this code:

void GameTSCtrl::makeScriptCall(const char *func, const GuiEvent &evt) const
{
   // write screen position
   char *sp = Con::getArgBuffer(32);
   dSprintf(sp, 32, "%d %d", evt.mousePoint.x, evt.mousePoint.y);

   // write world position
   char *wp = Con::getArgBuffer(32);
   Point3F camPos;
   mLastCameraQuery.cameraMatrix.getColumn(3, &camPos);
   dSprintf(wp, 32, "%g %g %g", camPos.x, camPos.y, camPos.z);

   // write click vector
   char *vec = Con::getArgBuffer(32);
   Point3F fp(evt.mousePoint.x, evt.mousePoint.y, 1.0);
   Point3F ray;
   unproject(fp, &ray);
   ray -= camPos;
   ray.normalizeSafe();
   dSprintf(vec, 32, "%g %g %g", ray.x, ray.y, ray.z);

   Con::executef( (SimObject*)this, func, sp, wp, vec );
}

That boils down to this script function:

function PlayGui::onMouseDown(%this, %screenPos, %worldPos, %clickVector)
{
}

Completely off topic, is your avatar a cartoon version of Mayael the Anima?
#2
07/21/2011 (12:35 pm)
Found the culprit. It turns out the problem was with a ShapeNameHud that was the same size as the playGui. Thanks for the help! :)

And no, it's not Mayael (though the card looks almost identical). It's the cover for The Secret of Kells.
#3
07/21/2011 (7:33 pm)
Ah, good to know you found the answer =)