General > The Laboratory

Determining Front Face

(1/1)

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


--- Code: ---
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

--- End code ---

Farabi:

--- Code: ---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)

--- End code ---

This code is much more accurate than the last one. Not just that, it also able to determine the front face dynamically.

Navigation

[0] Message Index

Go to full version