News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Determining Front Face

Started by Farabi, June 18, 2012, 06:30:51 PM

Previous topic - Next topic

Farabi

Im trying to determine front face and back face from a Tri-mesh Vertex. So far it is good. It is unoptimized yet.



fIsFront proc uses esi edi lpV1:dword,lpV2:dword,lpV3:dword
LOCAL tmp,tmp2,tmp3:dword
;(A.x * B.y - B.x * A.y) + (B.x * C.y - C.x * B.y) + (C.x * A.y - A.x * C.y)
mov esi,lpV1
mov edi,lpV2

fld [esi].VERTEX.x
fmul [edi].VERTEX.y
fld [edi].VERTEX.x
fmul [esi].VERTEX.y
fsubp st(1),st
fstp tmp

mov esi,lpV2
mov edi,lpV3

fld [esi].VERTEX.x
fmul [edi].VERTEX.y
fld [edi].VERTEX.x
fmul [esi].VERTEX.y
fsubp st(1),st
fstp tmp2

mov esi,lpV3
mov edi,lpV1

fld [esi].VERTEX.x
fmul [edi].VERTEX.y
fld [edi].VERTEX.x
fmul [esi].VERTEX.y
fsubp st(1),st
fstp tmp3

fld tmp
fadd tmp2
fadd tmp3
fistp tmp
mov eax,tmp

ret
fIsFront endp
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi


fIsFront proc uses edi esi lpV1:dword,lpV2:dword,lpV3:dword,lpSourceVertex:dword
LOCAL DVert:VERTEX
LOCAL q:qword
LOCAL AB:VERTEX
LOCAL CB:VERTEX
LOCAL facenormal:VERTEX

invoke Vec_Sub,addr DVert,lpSourceVertex,lpV1

invoke Vec_Sub,addr AB, lpV2, lpV1
invoke Vec_Sub,addr CB, lpV2, lpV3

invoke Vec_CrossProduct,addr facenormal,addr CB,addr AB
invoke Vec_DotProduct,addr DVert,addr facenormal
; fstp q
; FCMP q,FP4(0.)

ret
fIsFront endp ; Return Value at St(0)


This code is much more accurate than the last one. Not just that, it also able to determine the front face dynamically.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165