Public feed #378319

GetAngle arctan

public text v1 · immutable
Raw Edit
·published 2007-03-02 13:02 UTC
rendered paste body
global variable: 
new const arctan[19][19] = {
	{ 45, 42, 39, 35, 31, 22, 17, 11,  6,  0,354,349,343,338,329,325,321,318,315},
	{ 48,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,312},
	{ 51,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,309},
	{ 55,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,305},
	{ 59,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,301},
	{ 68,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,292},
	{ 73,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,287},
	{ 79,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,281},
	{ 84,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,276},
	{ 90,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,270},
	{ 96,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,264},
	{101,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,259},
	{107,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,253},
	{112,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,248},
	{121,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,239},
	{125,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,235},
	{129,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,231},
	{132,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,228},
	{135,138,141,145,149,158,163,169,174,180,186,191,197,202,211,215,219,222,225}
};
using it:
public GetAngle(Float:fdx, Float:fdy) {
	new Float:scale;
	if (floatabs(fdx) > floatabs(fdy))
		scale = floatabs(floatdiv(9.0, fdx));
	else
	    scale = floatabs(floatdiv(9.0, fdy));
	return arctan[Round(floatmul(fdx, scale)) + 9][Round(floatmul(fdy, scale)) + 9] - 90;
}
using GetAngle:
        GetPlayerPos(playerid, px, py, pz);
        playerAngle[playerid] = GetAngle(lastpos[playerid][0] - px, lastpos[playerid][1] - py);
The angle a player is facing when moving from lastpos to this position.