News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Angle Between 2 Vector

Started by Farabi, February 25, 2012, 06:37:30 AM

Previous topic - Next topic

Farabi





FPGetAngles proc uses esi edi lpPos:dword,lpRotation:dword
LOCAL signX,signY:dword
LOCAL rslt:VERTEX
LOCAL q:dword
LOCAL t:qword
;++ = 0-90
;+- = 91-180
;-- = 181=270
;-+ = 271-360

mov esi,lpPos
mov edi,lpRotation
; X = Y,Z
; Y = X,Z
; Z = X,Y
invoke Vec_Normalize,addr rslt,lpPos
; invoke Vec_Copy,addr rslt,lpPos

fld rslt.y
invoke FpuArcsin,0,0,129
fstp [edi].VERTEX.x

fld rslt.x
fld rslt.z
fpatan
fstp q
invoke Vec_RadToDeg,q
fchs
fstp [edi].VERTEX.y

ret
FPGetAngles endp

FPGetAnglesFromPosv proc uses esi edi lpVertexFrom:dword,lpVertexOrigin:Dword,lpRotationEulerAngleResult:dword
LOCAL v1:VERTEX
LOCAL vnorm:VERTEX
LOCAL q:dword

mov edi,lpRotationEulerAngleResult

invoke Vec_Sub,addr v1,lpVertexFrom,lpVertexOrigin
invoke Vec_Normalize,addr vnorm,addr v1

fld vnorm.y
invoke FpuArcsin,0,0,129
fstp [edi].VERTEX.x

fld vnorm.x
fld vnorm.z
fpatan
fstp q
invoke Vec_RadToDeg,q
fchs
fstp [edi].VERTEX.y

ret
FPGetAnglesFromPosv endp

FPGetAnglesFromPos proc uses edi esi x1From:dword,y1From:dword,z1From:dword,x2Origin:dword,y2Origin:dword,z2Origin:dword,lpRotationEulerAngleResult:dword
LOCAL v1:VERTEX
LOCAL v2:VERTEX

fld x1From
fstp v1.x
fld y1From
fstp v1.y
fld z1From
fstp v1.z

fld x2Origin
fstp v2.x
fld y2Origin
fstp v2.y
fld z2Origin
fstp v2.z

invoke FPGetAnglesFromPosv,addr v1,addr v2,lpRotationEulerAngleResult

ret
FPGetAnglesFromPos endp


Finally get it working. It was a waste of time figuring this thing out.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Which worked on yours? Mine is this


FPGetAnglesFromPosv proc uses esi edi lpVertexFrom:dword,lpVertexOrigin:Dword,lpRotationEulerAngleResult:dword
LOCAL v1:VERTEX
LOCAL vnorm:VERTEX
LOCAL q:dword
LOCAL vFrom:VERTEX

mov edi,lpRotationEulerAngleResult

invoke MemCopy,lpVertexFrom,addr vFrom,sizeof VERTEX
fld vFrom.x
fchs
fstp vFrom.x
fld vFrom.y
fchs
fstp vFrom.y
fld vFrom.z
fchs
fstp vFrom.z

invoke Vec_Sub,addr v1,addr vFrom,lpVertexOrigin
invoke Vec_Normalize,addr vnorm,addr v1

fld vnorm.y
invoke FpuArcsin,0,0,129
fstp [edi].VERTEX.x

fld vnorm.x
fld vnorm.z
fpatan
fstp q
invoke Vec_RadToDeg,q
fchs
fstp [edi].VERTEX.y

ret
FPGetAnglesFromPosv endp


It worked on mine, but it is different than the teory suggested. The teory one is this one:

FPGetAnglesFromPosv proc uses esi edi lpVertexFrom:dword,lpVertexOrigin:Dword,lpRotationEulerAngleResult:dword
LOCAL v1:VERTEX
LOCAL vnorm:VERTEX
LOCAL q:dword

mov edi,lpRotationEulerAngleResult

invoke Vec_Sub,addr v1,lpVertexFrom,lpVertexOrigin
invoke Vec_Normalize,addr vnorm,addr v1

fld vnorm.y
invoke FpuArcsin,0,0,129
fstp [edi].VERTEX.x

fld vnorm.x
fld vnorm.z
fpatan
fstp q
invoke Vec_RadToDeg,q
fchs
fstp [edi].VERTEX.y

ret
FPGetAnglesFromPosv endp


But did not worked on mine
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"