I set up google page in here
http://code.google.com/p/fgameengine/Making a shadow system on a low end computer is pain in the ass. Im confused with playstation 2, my laptop GPU should be faster than that, but I cant beat the graphic system. The can make lots of realtime shadow, dynamic lighting and many more. I dot know how they did that.
I tried to create a tri-ray collision detect but I failed, I hope that someone can fix it for me.
fCheckSamClockDir proc uses esi edi lpTri:dword,norm:dword
LOCAL testi, testj, testk:real4
LOCAL dotprod:real4
LOCAL tmp,tmp2:real4
mov esi,lpTri
mov edi,norm
fld [esi].Tri.pt2.y
fsub [esi].Tri.pt1.y
fstp tmp
fld [esi].Tri.pt3.z
fsub [esi].Tri.pt1.z
fmul tmp
fstp tmp
fld [esi].Tri.pt3.y
fsub [esi].Tri.pt1.y
fstp tmp
fld [esi].Tri.pt2.z
fsub [esi].Tri.pt1.z
fmul tmp2
fstp tmp2
fld tmp
fsub tmp2
fstp testi
;--------------------------------------------------------------------------------
fld [esi].Tri.pt2.z
fsub [esi].Tri.pt1.z
fstp tmp
fld [esi].Tri.pt3.x
fsub [esi].Tri.pt1.x
fmul tmp
fstp tmp
fld [esi].Tri.pt3.z
fsub [esi].Tri.pt1.z
fstp tmp
fld [esi].Tri.pt2.x
fsub [esi].Tri.pt1.x
fmul tmp2
fstp tmp2
fld tmp
fsub tmp2
fstp testj
;--------------------------------------------------------------------------------
fld [esi].Tri.pt2.x
fsub [esi].Tri.pt1.x
fstp tmp
fld [esi].Tri.pt3.y
fsub [esi].Tri.pt1.y
fmul tmp
fstp tmp
fld [esi].Tri.pt3.x
fsub [esi].Tri.pt1.x
fstp tmp
fld [esi].Tri.pt2.y
fsub [esi].Tri.pt1.y
fmul tmp2
fstp tmp2
fld tmp
fsub tmp2
fstp testj
;--------------------------------------------------------------------------------
fld testi
fmul [edi].VERTEX.x
fstp tmp
fld testj
fmul [edi].VERTEX.y
fadd tmp
fstp tmp
fld testk
fmul [edi].VERTEX.z
fadd tmp
fstp dotprod
FCMP dotprod,FP4(0.)
.if SIGN?
xor eax,eax
.else
mov eax,1
.endif
ret
fCheckSamClockDir endp
fRayTriIntersect proc uses esi edi ebx lpRay:dword,lpTri:dword,lpIntersect:dword
LOCAL v1:VERTEX
LOCAL v2:VERTEX
LOCAL norm:VERTEX
LOCAL dotprod:real4
LOCAL t:real4
LOCAL tmp,tmp2:real4
LOCAL PCHECK:Tri
LOCAL q:qword
LOCAL buff[256]:dword
mov esi,lpTri
mov edi,lpRay
mov ebx,lpIntersect
invoke Vec_Sub,addr v1,addr [esi].Tri.pt2,addr [esi].Tri.pt1
invoke Vec_Sub,addr v2,addr [esi].Tri.pt3,addr [esi].Tri.pt2
invoke Vec_CrossProduct,addr norm,addr v1,addr v2
invoke Vec_DotProduct,addr norm,addr [edi].Ray.vector
fstp dotprod
FCMP dotprod,FP4(0.)
jl @f
xor eax,eax
ret
@@:
fld [edi].Ray.linept.x
fsub [esi].Tri.pt1.x
fmul norm.x
fstp tmp
fld [edi].Ray.linept.y
fsub [esi].Tri.pt1.y
fmul norm.y
fadd tmp
fstp tmp
fld [edi].Ray.linept.z
fsub [esi].Tri.pt1.z
fmul norm.z
fadd tmp
fchs
fstp tmp
fld norm.x
fmul [edi].Ray.vector.x
fstp tmp2
fld norm.y
fmul [edi].Ray.vector.y
fadd tmp2
fstp tmp2
fld norm.z
fmul [edi].Ray.vector.z
fadd tmp2
fstp tmp2
fld tmp
fdiv tmp2
fstp t
FCMP t,FP4(0.)
jnl @f
xor eax,eax
dec eax
ret
@@:
fld [edi].Ray.vector.x
fmul t
fadd [edi].Ray.linept.x
fstp [ebx].VERTEX.x
fld [edi].Ray.vector.y
fmul t
fadd [edi].Ray.linept.y
fstp [ebx].VERTEX.y
fld [edi].Ray.vector.z
fmul t
fadd [edi].Ray.linept.z
fstp [ebx].VERTEX.z
invoke MemCopy,lpTri,addr PCHECK,sizeof Tri
invoke MemCopy,ebx,addr PCHECK.pt3,sizeof VERTEX
invoke fCheckSamClockDir,addr PCHECK,addr norm
.if eax==1
invoke MemCopy,addr [esi].Tri.pt2,addr PCHECK.pt1,sizeof VERTEX
invoke MemCopy,addr [esi].Tri.pt3,addr PCHECK.pt2,sizeof VERTEX
invoke fCheckSamClockDir,addr PCHECK,addr norm
.if eax==1
invoke MemCopy,addr [esi].Tri.pt3,addr PCHECK.pt1,sizeof VERTEX
invoke MemCopy,addr [esi].Tri.pt1,addr PCHECK.pt2,sizeof VERTEX
invoke fCheckSamClockDir,addr PCHECK,addr norm
.if eax==1
ret
.endif
.endif
.endif
xor eax,eax
ret
fRayTriIntersect endp
fRayTriIntersect2 proc uses esi edi ebx lpRay:dword,lpTri:dword,lpIntersect:dword
LOCAL edge1[3],edge2[3],tvec[3],pvec[3],qvec[3]:real4
LOCAL det,inv_det,t,u,v:real4
LOCAL con1,con2:dword
mov esi,lpTri
mov edi,lpRay
mov ebx,lpIntersect
invoke Vec_Sub,addr edge1,addr [esi].Tri.pt2,addr [esi].Tri.pt1
invoke Vec_Sub,addr edge2,addr [esi].Tri.pt2,addr [esi].Tri.pt1
invoke Vec_CrossProduct,addr pvec,addr [edi].Ray.vector,addr edge2
invoke Vec_DotProduct,addr edge1,addr pvec
fstp det
mov con1,0
mov con2,0
FCMP det,FP4(-0.000001)
jng @f
mov con1,1
@@:
FCMP det,FP4(0.000001)
jnl @f
mov con2,1
@@:
mov eax,con1
and eax,con2
.if eax==1
dec eax
ret
.endif
fld1
fdiv det
fstp inv_det
invoke Vec_Sub,addr tvec,addr [edi].Ray.linept,addr [esi].Tri.pt1
invoke Vec_DotProduct,addr tvec,addr pvec
fmul inv_det
fstp u
mov con1,0
mov con2,0
FCMP u,FP4(0.00)
jng @f
mov con1,1
@@:
FCMP u,FP4(1.00000)
jnl @f
mov con2,1
@@:
mov eax,con1
or eax,con2
.if eax==1
dec eax
ret
.endif
fld u
fstp [ebx].VERTEX.x
invoke Vec_CrossProduct,addr qvec,addr tvec,addr edge1
invoke Vec_DotProduct,addr [edi].Ray.vector,addr qvec
fmul inv_det
fstp v
mov con1,0
mov con2,0
FCMP v,FP4(0.00)
jng @f
mov con1,1
@@:
fld u
fadd v
fstp v
FCMP v,FP4(1.00000)
jnl @f
mov con2,1
@@:
mov eax,con1
or eax,con2
.if eax==1
dec eax
ret
.endif
fld v
fstp [ebx].VERTEX.y
invoke Vec_DotProduct,addr edge2,addr qvec
fmul inv_det
fstp t
fld t
fstp [ebx].VERTEX.z
mov eax,1
ret
fRayTriIntersect2 endp
I found it here
http://www.gamedev.net/topic/202886-ray-tri-intersection/http://www.angelfire.com/fl/houseofbartlett/solutions/line2tri.html#CodeI hope by making this work I can reduce the CPU usage by 30%.
Honestly, in the end, Im not going to use my game engine to create a game, It just fun studying it. After I got the basic inner working work, I'll use the profesional one.