News:

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

Main Menu

Test if a dot colliding with line

Started by Farabi, October 04, 2012, 02:27:41 PM

Previous topic - Next topic

Farabi


fIsItOnLine proc lpVLine1:dword,lpVLine2:dword,lpVTested:dword
LOCAL VNormals:VERTEX
LOCAL vDelta:VERTEX
LOCAL VNormals2:VERTEX
LOCAL vDelta2:VERTEX
LOCAL TLen:real4
LOCAL vScaled:VERTEX
; lpVLine1/2 is the Line position using Vertex as coordinate (X,Y,Z)

; First lets have the Normals first
invoke Vec_Sub,addr vDelta,lpVLine2,lpVLine1
invoke Vec_Normalize,addr VNormals,addr vDelta

; Lets have the normals and the delta of the tested vertex
invoke Vec_Sub,addr vDelta2,lpVTested,lpVLine1
invoke Vec_Normalize,addr VNormals2,addr vDelta2

invoke Vec_DotProduct,addr vDelta,addr vDelta
fsqrt
fstp TLen

invoke Vec_Copy,addr vScaled,addr VNormals2
invoke Vec_Scale,addr vScaled,TLen

invoke Vec_Sub,addr vDelta,addr vScaled,lpVTested
invoke Vec_DotProduct,addr vDelta,addr vDelta
push eax
fistp dword ptr[esp]
pop eax
; if it is zero, it mean the dot is colliding the line, if it was not, then it was not zero.
.if eax==0
mov eax,TRUE
.else
mov eas,FALSE
.endif

ret
fIsItOnLine endp


This is the fastest and shortest I can do  right now. I'll try to improve it.
Right now I only able to check wheter a dot is colliding with a line. my target is triangle with triangle collision detect.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

jj2007

#1
Good to see you are at work again ;-)


AMD Athlon(tm) Dual Core Processor 4450B (SSE3)
19 of 20 tests valid, loop overhead is approx. 238/100 cycles
198     cycles for cycles for 100 * C-style
173     cycles for cycles for 100 * test & inc
101     cycles for cycles for 100 * sete & movzx eax, al

198     cycles for cycles for 100 * C-style
173     cycles for cycles for 100 * test & inc
101     cycles for cycles for 100 * sete & movzx eax, al

198     cycles for cycles for 100 * C-style
173     cycles for cycles for 100 * test & inc
101     cycles for cycles for 100 * sete & movzx eax, al

16      bytes for C-style
9       bytes for test & inc
8       bytes for sete & movzx eax, al

Farabi

Quote from: jj2007 on October 04, 2012, 03:09:48 PM
Good to see you are at work again ;-)

  if 1
test eax, eax ; 8 bytes
sete al
movzx eax, al
  elseif 0
test eax, eax ; 9 bytes
.if Zero?
inc eax
.else
xor eax, eax
.endif
  else
.if eax==0 ; 17 bytes
mov eax,TRUE
.else
mov eax,FALSE
.endif
  endif


Hi, Thanks.
Nice optimization.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165