flat assembler
Message board for the users of flat assembler.

Index > Windows > Normal vectors generation from an arbitrary geometry

Thread Post new topic Reply to topic

Joined: 30 Apr 2005
Posts: 1
Location: argentina

I am trying to write a code to calculate normal vectors from an arbitrary 3d model. Actually, I am a newbie in assembler and SIMD programming Wink, so, I can't find the errors in the following piece of code:


   v1 dd 1.0,1.0,0.0,0.0
   v2 dd 1.0,0.0,0.0,0.0
   v3 dd 0.0,1.0,0.0,0.0
   movups xmm0,dqword [v1]
   movups xmm1,dqword [v2]
   movups xmm2,dqword [v3]
   subps xmm1,xmm0              ;xmm1: v1-v2 = A = Ax Ay Az Aw
   subps xmm2,xmm0              ;xmm2: v1-v3 = B = Bx By Bz Bw
   movups xmm0,xmm2             ;xmm0: B = Bx By Bz Bw
   shufps xmm0,xmm2,10011101b   ;xmm0: By Bz Bx Bz
   shufps xmm1,xmm1,01100111b   ;xmm1: Az Ay Az Ax
   mulps xmm0,xmm1              ;xmm0: [By*Az] [Bz*Ay] [Bx*Az] [Bz*Ax]
   shufps xmm1,xmm1,00000010b   ;xmm1: Ax Ax Ax Ay
   shufps xmm2,xmm2,00011011b   ;xmm2: Bw Bz By Bx
   mulps xmm1,xmm2              ;xmm1: [?]     [?]     [Ax*By] [Ay*Bx]
   movups xmm2,xmm0             ;xmm2: [By*Az] [Bz*Ay] [Bx*Az] [Bz*Ax]
   shufps xmm0,xmm1,00011101b   ;xmm0: [Ay*Bx] [Ax*By] [By*Az] [Bx*Az]
   shufps xmm2,xmm1,00001000b   ;xmm2: [Ay*Bx] [Ay*Bx] [Bz*Ay] [Bz*Ax]
   subps xmm2,xmm0              ;xmm2: [0] [Ax*By - Ay*Bx] [By*Az - Bz*Ay] [Bx*Az - Bz*Ax]
   shufps xmm2,xmm2,11100001b   ;xmm2: [0] [Ax*By - Ay*Bx] [Bx*Az - Bz*Ax] [By*Az - Bz*Ay]  (w,z,y,x)

v1,v2,v3 are three vertices of a triangle. I want to obtain the normal vector of the triangle.

Thanks in advance!

Lord Ciriuz
Post 30 Apr 2005, 00:31
View user's profile Send private message Visit poster's website 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.