Game Development Community

mAtan giving error message even when it works

by Luis E Pabon · in iTorque 2D · 10/03/2011 (2:25 pm) · 3 replies

In the API, it states that mAtan has one parameter: %val. It also works perfectly if used like that. However, the console spams error messages when doing it like that. I tried switching to mAtan(%rise, %sun), but that function was not working as I expected.

Example:
%val = %normal.X / %normal.Y;
%angle = mAtan(%val);
//%angle = mAtan(%normal.X, %normal.Y);
echo("%angle" SPC %angle);

Running this code gives me the following message:
scripts/player.cs (52): ::mAtan - wrong number of arguments.
scripts/player.cs (52): usage: ( val ) Use the mAtan function to get the inverse tangent of rise/run in radians.
@param rise Vertical component of a line.
@param run Horizontal component of a line.
@return Returns the slope in radians (the arc-tangent) of a line with the given rise and run.
@sa mTan

The value in %angle is correct though.

If I switch comments in the code, I don't get a message but the value of %angle is incorrect.

#1
10/03/2011 (4:44 pm)
isn't it mAtan(y,x)? I've not seen a single case in any math library and technology where it does not expect it to be (y,x) in the inputs and not (x,y) as you used there. That would also explain the incorrect value.

(if its single value its normally x / y, but if its two its normally y,x and that it mentions rise first, I would expect it to be the case here too)
#2
10/03/2011 (4:57 pm)
I fixed my equation to "Y / X", but it still displays the error message.
By using:
%angle = 1 / mAtan(%normal.Y, %normal.X);

I get the value I needed (I was using the wrong equation).

What I gather from this is that both input types are valid, but %val gives an error message due to an oversight.
#3
10/05/2011 (12:48 am)
I use mAtan all the time, for converting analog joystick values into angles like this:

%targetAngle = mRadToDeg(mAtan(getWord(%aimVector, 1), getWord(%aimVector, 0)))  + 90;