Game Development Community

Help with mObjToWorld

by Martin "Founder" Hoover · in Torque Game Engine · 07/04/2004 (10:11 am) · 7 replies

I wrote a function to get the positions of a wheeled vehicles hub nodes. The idea being to get the world space positions for scripts. The code below gets the proper x and y, but the z is always a certain distance above the terrain, no matter what. SO I am guessing that maybe my math is wronge or I just don't know enough about the matricies.


MatrixF realHub = mShapeInstance->mNodeTransforms[wheel->data->springNode];
            realHub.getColumn(3, &hubPos);
            mObjToWorld.mulP(hubPos);
            return hubPos;

Any help would be much appriciated.

#1
07/04/2004 (10:23 am)
Maybe the point is at the center of the hub, and not on the ground?
#2
07/04/2004 (10:26 am)
Yes. but what I failed to mention is that even if the vehicle is 100 meters above/below the terrain, the positions returned will be the same (lets say 2 meters) above the terrain.
#3
07/04/2004 (11:36 am)
Time to say "oops". I didn't realize I was procdessing the positions through a function that messed with the z value. I owned myself once again. Heh, sorry for the trouble.
#4
07/04/2004 (11:47 am)
Glad you got it fixed. :)
#5
07/04/2004 (12:45 pm)
I'm wokring on a getClosestWheel function to find the correct wheel to lock/damage(I'm using your wheel locking code). However, I've made no progress for week. Heres the thread. www.garagegames.com/mg/forums/result.thread.php?qt=19596

I tried using the code you posted, but alway get a return value of one. Do you think you could share your function?
#6
07/04/2004 (9:37 pm)
You bet. I ended up changing the function some more since for what I am doing I need the rendered positions of the wheel hubs. I actually noticed your thread the other day, but when I started working on this it didn't occur to me that they were similar problems. Anyway this provides the world space position of the specified wheel hub, I hope you can get some use from it.

Point3F WheeledVehicle::getWheelPos(S32 wheelNode)
{
   S32 z = 0;
   Point3F hubPos;
   hubPos.set(0.f,0.f,0.f);
   Wheel* wend = &mWheel[mDataBlock->wheelCount];
   for (Wheel* wheel = mWheel; wheel < wend; wheel++)
   {
      if(wheel->tire)
      {
         if(z == wheelNode)
         {
            MatrixF realHub = mShapeInstance->mNodeTransforms[wheel->data->springNode];
            MatrixF trans = getTransform();
            trans.mul(realHub);
            trans.getColumn(3, &hubPos);
            hubPos.z -= wheel->spring->length * wheel->extension;
            return hubPos;
         }
         z++;
      }
   }
   return hubPos;
}

ConsoleMethod(WheeledVehicle, getWheelPos, const char*, 3, 3, "obj.getWheelPos(wheel#)")
{
   S32 wheel = dAtoi(argv[2]);
   if (wheel >= 0 && wheel < object->getWheelCount())
   {
      Point3F pos = object->getWheelPos(wheel);

      char* buffer = Con::getArgBuffer(64);
      dSprintf(buffer, 64, "%f %f %f", pos.x, pos.y, pos.z);

      return buffer;
      
   }
   else
      Con::warnf("getWheelPos: wheel index out of bounds, vehicle has %d hubs", argv[3],object->getWheelCount());

}

BTW, if anyone uses these functions as-is, don't forget to prototype the first one for the wheeledVehicle class.
#7
07/04/2004 (10:12 pm)
Thanks alot. Now I can script in some cool damage effects. I want to make it so a bullet can alter the lock angle of a locked wheel.