flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > 3D Point in tetrahedron.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 2132
Roman 13 Aug 2026, 10:47
Code:
macro xmVec4Sub [a,b] { common cc equ 0 ;start s xmm1 for xmCross4(using xmm0)
      forward
      rept 1 n:cc+1  \{ movaps xmm\#\n,dqword [a]
                        subps  xmm\#\n,dqword [b]
                        cc equ n
      \}  }  
macro xmDot4 [a,b] {
        mulps  xmm#a,xmm#b
        haddps xmm#a,xmm#a
        haddps xmm#a,xmm#a
}
macro xmCross4 a,b,c=0 {
    pshufd       xmm5,a,201
    pshufd       xmm0,b,210
    pshufd       a,a,210
    pshufd       b,b,201
    mulps        xmm5, xmm0
    mulps        a, b
    subps        xmm5, a    
  if c eqtype 0
    if c > 0
    movups       dqword [c],xmm5
    end if
  end if
  if c eqtype eax
  movaps c,xmm5
  end if   
}           
macro xmCNormal p0,p1,p2 {
  xmVec4Sub p1,p0,p2,p0      ;out to xmm1 i xmm2
  xmCross4  xmm1,xmm2
 } 

macro xmSign x1,r {
        xorps xmm7,xmm7
        comiss xmm#x1,xmm7
        seta r
        sbb r, 0
}

macro xmPointInTetraeder  t1,t2,t3,t4,p {
xmCNormal  t1,t2,t3
        xmVec4Sub  t4,t1
        xmDot4     1,5
        movss      xmm0,xmm1

        xmVec4Sub  p,t1
        xmDot4     1,5
        xmSign     0,al
        xmSign     1,ah
        cmp al,ah
}                  

;data
align 16
        point    dd 0,0.04,0,0

        points4     dd 1.0,0,1.0 ,0
                    dd -1.0,0,1.0  ,0
                    dd 0.6,0,-0.707 ,0
                    dd 0,1.0,0  ,0
;code
        mov esi,points4 
        mov edx,point
        xmPointInTetraeder  esi,esi+16,esi+32,\
                            esi+48,edx
        jnz  @f
     

        xmPointInTetraeder  esi+16,esi+32,esi+48,\
                            esi,edx
        jnz  @f
        

        xmPointInTetraeder  esi+32,esi+48,esi,\
                            esi+16,edx

        jnz  @f
         

        xmPointInTetraeder  esi+48,esi,esi+16,\
                            esi+32,edx
        jnz  @f
         
        invoke MessageBox,0, 'intersect !',0,0
@@:
    
Post 13 Aug 2026, 10:47
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2132
Roman 13 Aug 2026, 12:41
Optimization. We could store (calc one time normals) for 4 points tetrahedron, and in xmPointInTetraeder not do xmCNormal t1,t2,t3
Post 13 Aug 2026, 12:41
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.