Game Development Community

MAtan does what it says it does

by Gary "ChunkyKs" Briggs · in Torque Game Builder · 03/26/2005 (12:25 am) · 3 replies

From mConsoleFunctions.cc:
ConsoleFunction( mAtan, F32, 3, 3,
               "(float rise, float run) Returns the slope in radians"
               "(the arc-tangent) of a line with the given rise and run.")
{  
   return(mAtan(dAtof(argv[1]), dAtof(argv[2])));
}

And returning "the slope in radians (the arc-tangent) of a line with the given rise and run" is exactly what it does.

Unfortunately, T2D uses degrees to do stuff like %object.setRotation. So my code now looks like this:
%theta = 57 * mAtan(%a.ry[%i] - %a.ry[%i+1], %a.rx[%i] - %a.rx[%i+1]); // mAtan returns radians

Go go gadget magic numbers.

Is it possible for T2D functions such as this one to return angles in degrees?

Gary (-;

#1
03/26/2005 (12:57 am)
At the risk of stating the obvious, couldn't you use the RadtoDeg and DegtoRad functions?
#2
03/26/2005 (2:29 am)
Yes, yes I can.

But in the meantime, T2D uses the system of "0 degrees is vertical, and wind clockwise". So I'd expect all the helper functions to follow that.

Gary (-;
#3
03/26/2005 (3:11 am)
Bugs forum? ;)

You can use...
%theta = mRadToDeg( mAtan(%a.rx[%i+1] - %a.rx[%i], %a.ry[%i] - %a.ry[%i+1]) );
... or instead of using...
%x = cos(%theta) 
%y = -sin(%theta)
... you can use...
%x = sin(%theta) 
%y = -cos(%theta)

Hope this helps,

- Melv.