here is the math i used:
Code:
FLD [NextWayPoint].LocationStruct.X
FSUB MyLocalPlayer.PlayerCoordX
FSTP NextWayPointDistanceX
FLD [NextWayPoint].LocationStruct.Y
FSUB MyLocalPlayer.PlayerCoordY
FSTP NextWayPointDistanceY
FLD [NextWayPoint].LocationStruct.Z
FSUB MyLocalPlayer.PlayerCoordZ
FSTP NextWayPointDistanceZ
;radian
FLD NextWayPointDistanceY
FLD NextWayPointDistanceX
FPATAN
FWAIT
FSTP NextWayPointFaceXY
;Distance per Pythagoras 2D
FLD NextWayPointDistanceX
FLD st(0)
FMUL
FLD NextWayPointDistanceY
FLD st(0)
FMUL
FADD
FSQRT
FSTP NextWayPointDistance2D
;Distance per Pythagoras 3D
FLD NextWayPointDistanceZ
FLD st(0)
FMUL
FLD NextWayPointDistance2D
FLD st(0)
FMUL
FADD
FSQRT
FSTP NextWayPointDistance3D
FLD NextWayPointDistanceZ
FLD NextWayPointDistance2D
FPATAN
FWAIT
FSTP NextWayPointFaceHoriz
could also be show as:
NextWayPointDistanceX=WaypointX-PlayerX
NextWayPointDistanceY=WaypointY-PlayerY
NextWayPointDistanceZ=WaypointZ-PlayerZ
NextWayPointFaceXY = ARCTAN(NextWayPointDistanceY/NextWayPointDistanceX)
NextWayPointDistance2D = SQRT((NextWayPointDistanceX)²+(NextWayPointDistanceY)²)
NextWayPointDistance3D = SQRT((NextWayPointDistanceZ)²+(NextWayPointDistance2D)²)
NextWayPointFaceHoriz = ARCTAN(NextWayPointDistanceZ/NextWayPointDistance2D)
And dont calc with angles, calc with radians
and for Radian2degree i used an old funtion:
(dont know if it works ,its from my old source)
Code:
Radians2Degrees proc Radian:DWORD
local ReturnValue:dword
finit
fld Radian
push 180d ;*180
fimul dword ptr[esp] ;
pop eax ;CPU stack bereinigen (push 180d)
xor eax, eax
fldpi ;load pi (3.14159...) on FPU
fdiv ;*180/pi, angle now in degrees
ftst ;check for negative angle
fstsw ax ;retrieve status word from FPU ;copy the floating point status register into the AX register
fwait ;copy the AH register into the 80x86's condition code bits
sahf ;C0 into the carry flag;C2 into the parity flag;C3 into the zero flag
jnc @F ;jump if positive number
push 360d ;if negative +360
fiadd dword ptr[esp] ;angle now 0-360
fwait
pop eax ;CPU stack bereinigen (push 180d)
@@:
fistp ReturnValue ;Von der FPU holen
mov eax, ReturnValue ;in eax returnen lassen
ret
Radians2Degrees endp