math programing

Blitz3D Forums/Blitz3D Programming/math programing

Craig H. Nisbet(Posted 2007) [#1]
Hey guys, I'm not a huge math guy.

I need to make a "manual" alignToVector function. "manual" meaning it uses just math instead of blitz's entity system.
It needs to take a vector and pump out Pitch and Yaw values. how do I do this?


Vertigo(Posted 2007) [#2]
The tangent commands like Atan2 are your friends here... Im bad with efficient math, so I wont bother writing a slow routine for you, but im sure someone here is able to do so.


caff_(Posted 2007) [#3]
Unverified - but it looks about right:

Function Point_Entity(entity,x#,y#,z#)
    xdiff# = EntityX(entity)-x#
    ydiff# = EntityY(entity)-y#
    zdiff# = EntityZ(entity)-z#
    dist#=Sqr#((xdiff#*xdiff#)+(zdiff#*zdiff#))
    pitch# = ATan2(ydiff#,dist#)
    yaw# = ATan2(xdiff#,-zdiff#)
    RotateEntity entity,pitch#,yaw#,0
End Function