20.12.2010, 00:37
pawn Код:
stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y)
{
new Float:DX, Float:DY;
new Float:angle;
DX = floatabs(floatsub(x2,X));
DY = floatabs(floatsub(y2,Y));
if (DY == 0.0 || DX == 0.0)
{
if(DY == 0 && DX > 0) angle = 0.0;
else if(DY == 0 && DX < 0) angle = 180.0;
else if(DY > 0 && DX == 0) angle = 90.0;
else if(DY < 0 && DX == 0) angle = 270.0;
else if(DY == 0 && DX == 0) angle = 0.0;
}
else
{
angle = atan(DX/DY);
if(X > x2 && Y <= y2) angle += 90.0;
else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
else if(X < x2 && Y >= y2) angle -= 90.0;
else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
}
return floatadd(angle, 90.0);
}