Author Topic: Test if a dot colliding with line  (Read 3194 times)

Farabi

  • Member
  • ****
  • Posts: 969
  • Neuroscience Fans
Test if a dot colliding with line
« on: October 04, 2012, 02:27:41 PM »
Code: [Select]
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

  • Member
  • *****
  • Posts: 10536
  • Assembler is fun ;-)
    • MasmBasic
Re: Test if a dot colliding with line
« Reply #1 on: October 04, 2012, 03:09:48 PM »
Good to see you are at work again ;-)

Code: [Select]
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
« Last Edit: October 04, 2012, 09:37:18 PM by jj2007 »

Farabi

  • Member
  • ****
  • Posts: 969
  • Neuroscience Fans
Re: Test if a dot colliding with line
« Reply #2 on: October 04, 2012, 03:23:40 PM »
Good to see you are at work again ;-)

Code: [Select]
  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