Game Development Community

T3D 1.1 Beta 2 - GetTransform() returns a value in degrees, not radians - RESOLVED

by Bryce · in Torque 3D Professional · 08/18/2010 (4:41 pm) · 11 replies

Build: 1.1 Beta 2

Platform: Windows Vista Basic

Target: Anywhere getTransform() is used

Issue:

In TGE and previous versions of Torque 3D, if you would use the getTransform() function on a player, it would return something like this:

0 0 0 0 0 1 0.2

That last number would be the player's rotation on the Z axis in radians. However, if you get the transform of a player or any object in 1.1 Beta 2, you'll get something like this:

0 0 0 0 0 1 265

That last number is suddenly in degrees. This is probably why the player's transform doesn't match the camera's when you press F7, the setTransform() function is expecting the value in radians. This is also screwing with Matrix Multiply functions, because those functions also expect the rotation to be in radians.

Steps to repeat:
Go into the console, enter
$transform = LocalClientConnection.Player.getTransform();

The console should print out the transform, notice the last number is in degrees. Let's see what happens when we tell the player to match his own transform:

LocalClientConnection.player.setTransform($transform);

He should look in some other direction.


If someone could post a fix for this as soon as possible, that would be wonderful. I'm trying to get an AI kit released by next week and this bug is messing up a lot of things :P

#1
08/18/2010 (4:50 pm)
Quote:
This is probably why the player's transform doesn't match the camera's when you press F7,


Ah! I was just about to post something about that. Well hunted down, Bryce.
#2
08/18/2010 (7:22 pm)
This is a big dumb bug... i've alerted the authorities and we're on it.
#3
08/18/2010 (7:24 pm)
I found a "fix" as far as I know. Problem seems to lie in the Console functions in scenegraph/sceneObject.cpp.

Change:

DefineEngineMethod( SceneObject, getTransform, TransformF, (),,
   "Get the object's transform.\n"
   "@return the current transform of the object\n" )
{
   return object->getTransform();
}

to:

ConsoleMethod( SceneObject, getTransform, const char*, 2, 2, "Get transform of object.")
{
   char *returnBuffer = Con::getReturnBuffer(256);
   const MatrixF& mat = object->getTransform();
   Point3F pos;
   mat.getColumn(3,&pos);
   AngAxisF aa(mat);
   dSprintf(returnBuffer,256,"%g %g %g %g %g %g %g",
            pos.x,pos.y,pos.z,aa.axis.x,aa.axis.y,aa.axis.z,aa.angle);
   return returnBuffer;
}

And change:

DefineEngineMethod( SceneObject, setTransform, void, ( TransformF txfm ),,
   "Set the object's transform (orientation and position)."
   "@param txfm object transform to set" )
{
   object->setTransform( txfm.getMatrix() );
}

to:

ConsoleMethod( SceneObject, setTransform, void, 3, 3, "(Transform T)")
{
   Point3F pos;
   const MatrixF& tmat = object->getTransform();
   tmat.getColumn(3,&pos);
   AngAxisF aa(tmat);

   dSscanf(argv[2],"%g %g %g %g %g %g %g",
           &pos.x,&pos.y,&pos.z,&aa.axis.x,&aa.axis.y,&aa.axis.z,&aa.angle);

   MatrixF mat;
   aa.setMatrix(&mat);
   mat.setColumn(3,pos);
   object->setTransform(mat);
}

I'm not sure how drastic going from "DefineEngineMethod" to "ConsoleMethod" is, but it seems to work fine and from what I can tell, I haven't broken anything.
#4
08/19/2010 (6:47 pm)
Already logged as TQA-803 for the QA Team to verify.
#5
08/19/2010 (6:54 pm)
This is essentially a duplicate of www.torquepowered.com/community/forums/viewthread/119179 so it would be a good idea to keep an eye on that thread also.
#7
08/30/2010 (7:50 pm)
This is fixed in 1.1 Beta 3. getTransform() now returns in radians again.
#8
09/01/2010 (2:37 am)
Splendid
#10
09/01/2010 (11:34 pm)
Very interesting change :)
#11
09/09/2010 (12:15 pm)
For anyone willing to apply the fix themselves (making getTransform() return radians), here it is:

In math\mathTypes.cpp, chance this:
ConsoleGetType( TypeTransformF )
{
   TransformF* aa = ( TransformF* ) dptr;
   char* returnBuffer = Con::getReturnBuffer( 256 );
   dSprintf( returnBuffer, 256, "%g %g %g %g %g %g %g",
             aa->mPosition.x, aa->mPosition.y, aa->mPosition.z,
             aa->mOrientation.axis.x, aa->mOrientation.axis.y, aa->mOrientation.axis.z, mRadToDeg( aa->mOrientation.angle ) );
   return returnBuffer;
}

To this:
ConsoleGetType( TypeTransformF )
{
   TransformF* aa = ( TransformF* ) dptr;
   char* returnBuffer = Con::getReturnBuffer( 256 );
   dSprintf( returnBuffer, 256, "%g %g %g %g %g %g %g",
             aa->mPosition.x, aa->mPosition.y, aa->mPosition.z,
             aa->mOrientation.axis.x, aa->mOrientation.axis.y, aa->mOrientation.axis.z, aa->mOrientation.angle );
   return returnBuffer;
}