Game Development Community

mAtan2 function call passing reversed vars

by Rex Hiebert · in Torque 3D Professional · 09/28/2009 (2:24 pm) · 1 replies

In "mMathFn.h" you find "mAtan2" defined as:

inline F32 mAtan2(const F32 x, const F32 y)
{
return (F32) atan2(x, y);
}

X is passed as X and Y is passed as Y. No problem. But if we follow "atan2" to where it's defined in "math.h" we find it defined as:

inline float __CRTDECL atan2(_In_ float _Y, _In_ float _X)
{return (atan2f(_Y, _X)); }

Wait... the X value we passed is now defined as Y and the Y value as X. This gives incorrect (or at least, unexpected) results. When I reversed the order of the values I passed in, i then got the expected return value.

This function is used in another of other modules and could be causing problems that were, so far, unexplained.

RMH

#1
09/28/2009 (2:40 pm)
I think the parameters are just misnamed.

The accepted standard is that Y is the first parameter and X is the second.

Good catch.