Game Development Community

GUI Speedometer for all ShapeBase objects

by Jason "fireVein" Culwell · in Torque Game Engine · 01/05/2005 (5:27 am) · 3 replies

Just for anyone's future reference(since I couldn't find this elsewhere) here is a quick fix to display the speedometer for a player object. Actually for any ShapeBase object.

In guiSpeedometer.cc in the function onRender change the following line:

Vehicle* control = dynamic_cast<Vehicle*>(conn->getControlObject());

To:

ShapeBase* control = dynamic_cast<ShapeBase*>(conn->getControlObject());

And voila! Simple, eh? C'mon, you knew you could have figured it out. :)

-Jase

p.s. Also works properly when mounting a vehicle. Of course, since the controlobject is set to the vehicle when you mount, what did you expect? :P

I hope it helps someone.

- Update -

To show the speedometer only when the player object is mounted to a vehicle or if the controlobject is set to the vehicle, do the above as well as the following.

Same file, same function. Change:

if (!control)
      return;

To:

if (!control || (!control->isMounted() && !(control->getTypeMask() & VehicleObjectType)))
      return;

Again, I hope it helps someone.

[edit]
Fixed a small bug where the speedometer wasn't being drawn for the vehicle if you were not a mounted player object. Should work fine, now.

About the author

http://www.microdotproductions.com - I am a self taught programmer that has been hacking away at code for a little over 10 years now. I am a very passionate and persistent programmer, and gamer. I love challenges and problem solving.


#1
01/05/2005 (5:40 am)
Thanks! :-)

- Brett
#2
01/05/2005 (5:59 am)
No problem, thanks for letting me know I doofed and posted in the wrong forum. :)

-Jase
#3
03/10/2005 (8:21 am)
Juan,

Simplest solution for that case would be to add a consoleMethod to GuiSpeedometer called "setObject". Then in script you could do a GuiSpeed.setObject(%myCar);

Then change the top of GuiSpeedometerHud::onRender to look like this:

ShapeBase* control;
  if (!mObject) {
   // Must have a connection and player control object
   GameConnection* conn = GameConnection::getServerConnection();
   if (!conn)
      return;
   control = dynamic_cast<ShapeBase*>(conn->getControlObject());
   if (!control)
      return;
  } else {
    control = mObject;
  }

Add this to the private section:
ShapeBase* mObject;

Add this public member function:
void GuiSpeedometerHud::setObject(const ShapeBase* sb)
{
  mObject = sb;
}

Finally, add this console method:
ConsoleMethod( GuiSpeedometerHud, setlObject, bool, 3, 3, "(ShapeBase obj)")
{
   ShapeBase* controlObject;
   if (Sim::findObject(argv[2],controlObject)) {
      object->setObject(controlObject);
      return true;
   }
   else
      object->setObject(0);
   return false;
}

*Edit: filled in the rest of the blanks. ;)

I did this in post, I haven't tested it. There are probably small syntax errors or something.

Thanks,
Brian