Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. x3d equ 0
  2. y3d equ 2
  3. z3d equ 4
  4. vec_x equ 0
  5. vec_y equ 4
  6. vec_z equ 8
  7. ; 3d point - triple integer word coordinate
  8. ; vector   - triple float dword coordinate
  9. ;----------------------in: --------------------------------
  10. ;------------------------ esi - pointer to 1st 3d point ---
  11. ;------------------------ edi - pointer to 2nd 3d point ---
  12. ;------------------------ ebx - pointer to result vector --
  13. ;---------------------- out : none ------------------------
  14. if 0
  15. make_vector:
  16.         fninit
  17.         fild    word[edi+x3d]                ;edi+x3d
  18.         fisub   word[esi+x3d]                ;esi+x3d
  19.         fstp    dword[ebx+vec_x]
  20.  
  21.         fild    word[edi+y3d]
  22.         fisub   word[esi+y3d]
  23.         fstp    dword[ebx+vec_y]
  24.  
  25.         fild    word[edi+z3d]
  26.         fisub   word[esi+z3d]
  27.         fstp    dword[ebx+vec_z]
  28.  
  29. ret
  30. end if
  31. make_vector_r:
  32.         fninit
  33.         fld     dword[edi]                ;edi+x3d
  34.         fsub    dword[esi]                ;esi+x3d
  35.         fstp    dword[ebx+vec_x]
  36.  
  37.         fld     dword[edi+4]
  38.         fsub    dword[esi+4]
  39.         fstp    dword[ebx+vec_y]
  40.  
  41.         fld     dword[edi+8]
  42.         fsub    dword[esi+8]
  43.         fstp    dword[ebx+vec_z]
  44.  
  45. ret
  46. ;---------------------- in: -------------------------------
  47. ;--------------------------- esi - pointer to 1st vector --
  48. ;--------------------------- edi - pointer to 2nd vector --
  49. ;--------------------------- ebx - pointer to result vector
  50. ;---------------------- out : none
  51. cross_product:
  52.         fninit
  53.         fld     dword [esi+vec_y]
  54.         fmul    dword [edi+vec_z]
  55.         fld     dword [esi+vec_z]
  56.         fmul    dword [edi+vec_y]
  57.         fsubp   ;st1 ,st
  58.         fstp    dword [ebx+vec_x]
  59.  
  60.         fld     dword [esi+vec_z]
  61.         fmul    dword [edi+vec_x]
  62.         fld     dword [esi+vec_x]
  63.         fmul    dword [edi+vec_z]
  64.         fsubp   ;st1 ,st
  65.         fstp    dword [ebx+vec_y]
  66.  
  67.         fld     dword [esi+vec_x]
  68.         fmul    dword [edi+vec_y]
  69.         fld     dword [esi+vec_y]
  70.         fmul    dword [edi+vec_x]
  71.         fsubp   ;st1 ,st
  72.         fstp    dword [ebx+vec_z]
  73. ret
  74. ;----------------------- in: ------------------------------
  75. ;---------------------------- edi - pointer to vector -----
  76. ;----------------------- out : none
  77. normalize_vector:
  78.         fninit
  79.         fld     dword [edi+vec_x]
  80.         fmul    st, st
  81.         fld     dword [edi+vec_y]
  82.         fmul    st, st
  83.         fld     dword [edi+vec_z]
  84.         fmul    st, st
  85.         faddp   st1, st
  86.         faddp   st1, st
  87.         fsqrt
  88.  
  89.         ftst
  90.         fstsw ax
  91.         sahf
  92.         jnz     @f
  93.  
  94.         fst     dword [edi+vec_x]
  95.         fst     dword [edi+vec_y]
  96.         fstp    dword [edi+vec_z]
  97.         ret
  98.       @@:
  99.         fld st
  100.         fld st
  101.         fdivr dword [edi+vec_x]
  102.         fstp  dword [edi+vec_x]
  103.         fdivr dword [edi+vec_y]
  104.         fstp  dword [edi+vec_y]
  105.         fdivr dword [edi+vec_z]
  106.         fstp  dword [edi+vec_z]
  107. ret
  108. ;------------------in: -------------------------
  109. ;------------------ esi - pointer to 1st vector
  110. ;------------------ edi - pointer to 2nd vector
  111. ;------------------out: ------------------------
  112. ;------------------ st0 - dot-product
  113. dot_product:
  114.         fninit
  115.         fld     dword [esi+vec_x]
  116.         fmul    dword [edi+vec_x]
  117.         fld     dword [esi+vec_y]
  118.         fmul    dword [edi+vec_y]
  119.         fld     dword [esi+vec_z]
  120.         fmul    dword [edi+vec_z]
  121.         faddp
  122.         faddp
  123. ret
  124.  
  125. ; DOS version Coded by Mikolaj Felix aka Majuma
  126. ; mfelix@polbox.com
  127. ; www.majuma.xt.pl
  128. ; into FASM translation by Macgub
  129. init_sincos_tab:
  130. .counter   equ  dword [ebp-4]  ; cur angle
  131.  
  132.      push       ebp
  133.      mov        ebp,esp
  134.  
  135.      xor        eax,eax
  136.      push       eax            ; init .counter
  137.      mov        edi,cos_tab
  138.      mov        esi,sin_tab
  139.      mov        ecx,256
  140.      fninit
  141.  
  142.      fld        .counter
  143.   @@:
  144.      fld        st
  145.      fsincos
  146.      fstp       dword [edi]
  147.      fstp       dword [esi]
  148. ;     fadd       [piD180]
  149.      fadd       [piD128]
  150.      add        esi,4
  151.      add        edi,4
  152.      loop       @b
  153.      ffree      st
  154.  
  155.      mov        esp,ebp
  156.      pop        ebp
  157. ret
  158. ;------
  159. ; esi - offset (pointer) to angles, edi offset to 3x3 matrix
  160. make_rotation_matrix:
  161.    .sinx   equ dword[ebp-4]
  162.    .cosx   equ dword[ebp-8]
  163.    .siny   equ dword[ebp-12]
  164.    .cosy   equ dword[ebp-16]
  165.    .sinz   equ dword[ebp-20]
  166.    .cosz   equ dword[ebp-24]
  167.      push      ebp
  168.      mov       ebp,esp
  169.      sub       esp,24
  170.  
  171.      movzx     ebx,word[esi]
  172.      shl       ebx,2
  173.      mov       eax,dword[sin_tab+ebx]
  174.      mov       .sinx,eax
  175.      mov       edx,dword[cos_tab+ebx]
  176.      mov       .cosx,edx
  177.  
  178.      movzx     ebx,word[esi+2]
  179.      shl       ebx,2
  180.      mov       eax,dword[sin_tab+ebx]
  181.      mov       .siny,eax
  182.      mov       edx,dword[cos_tab+ebx]
  183.      mov       .cosy,edx
  184.  
  185.      movzx     ebx,word[esi+4]
  186.      shl       ebx,2
  187.      mov       eax,dword[sin_tab+ebx]
  188.      mov       .sinz,eax
  189.      mov       edx,dword[cos_tab+ebx]
  190.      mov       .cosz,edx
  191.  
  192.      fninit
  193.      fld       .cosy
  194.      fmul      .cosz
  195.      fstp      dword[edi]
  196.  
  197.      fld       .sinx
  198.      fmul      .siny
  199.      fmul      .cosz
  200.      fld       .cosx
  201.      fmul      .sinz
  202.      fchs
  203.      faddp
  204.      fstp      dword[edi+12]
  205.  
  206.      fld       .cosx
  207.      fmul      .siny
  208.      fmul      .cosz
  209.      fld       .sinx
  210.      fmul      .sinz
  211.      faddp
  212.      fstp      dword[edi+24]
  213.  
  214.      fld       .siny
  215.      fmul      .sinz
  216.      fstp      dword[edi+4]
  217.  
  218.      fld       .sinx
  219.      fmul      .siny
  220.      fmul      .sinz
  221.      fld       .cosx
  222.      fmul      .cosz
  223.      faddp
  224.      fstp      dword[edi+16]
  225.  
  226.      fld       .cosx
  227.      fmul      .siny
  228.      fmul      .sinz
  229.      fld       .sinx
  230.      fchs
  231.      fmul      .cosz
  232.      faddp
  233.      fstp      dword[edi+28]
  234.  
  235.      fld       .siny
  236.      fchs
  237.      fstp      dword[edi+8]
  238.  
  239.      fld       .cosy
  240.      fmul      .sinx
  241.      fstp      dword[edi+20]
  242.  
  243.      fld       .cosx
  244.      fmul      .cosy
  245.      fstp      dword[edi+32]
  246.  
  247.      mov       esp,ebp
  248.      pop       ebp
  249. ret
  250. ;---------------------
  251. ;  in:  esi - ptr to points(normals], each point(normal) coeficient as dword
  252. ;       edi - ptr to rotated points(normals)
  253. ;       ebx - ptr to 3x3 (9 dwords, 36 bytes) rotation matrix
  254. ;       ecx - number of points(normals)
  255. rotary:
  256. if Ext<SSE
  257.     fninit
  258.  .again:
  259.  
  260.     fld     dword[esi]
  261.     fmul    dword[ebx]
  262.     fld     dword[esi+4]
  263.     fmul    dword[ebx+12]
  264.     faddp
  265.     fld     dword[esi+8]
  266.     fmul    dword[ebx+24]
  267.     faddp
  268.     fstp    dword[edi]
  269.  
  270.  
  271.     fld     dword[esi+4]
  272.     fmul    dword[ebx+16]
  273.     fld     dword[esi]
  274.     fmul    dword[ebx+4]
  275.     faddp
  276.     fld     dword[esi+8]
  277.     fmul    dword[ebx+28]
  278.     faddp
  279.     fstp    dword[edi+4]
  280.  
  281.  
  282.     fld     dword[esi+8]
  283.     fmul    dword[ebx+32]
  284.     fld     dword[esi]
  285.     fmul    dword[ebx+8]
  286.     fld     dword[esi+4]
  287.     fmul    dword[ebx+20]
  288.     faddp
  289.     faddp
  290.     fstp    dword[edi+8]
  291.  
  292.  
  293.     add     esi,12
  294.     add     edi,12
  295.     loop    .again
  296.     mov     [edi],dword -1
  297. else
  298. ;   Copyright (C) 1999-2001  Brian Paul
  299. ;   Copyright (C)            Maciej Guba
  300. ;---------------------
  301. ;  in:  esi - ptr to points(normals], each point(normal) coeficient as dword
  302. ;       edi - ptr to rotated points(normals)
  303. ;       ebx - ptr to 3x3 (9 dwords, 36 bytes) rotation matrix
  304. ;       ecx - number of points(normals)
  305. ;align 32
  306.     movups   xmm4,[ebx]
  307.     movups   xmm5,[ebx+12]
  308.     movups   xmm6,[ebx+24]
  309. ;align 32
  310.   .again:
  311.     movss    xmm0,dword[esi]
  312.     shufps   xmm0,xmm0,0
  313.     mulps    xmm0,xmm4
  314.  
  315.     movss    xmm1,dword[esi+4]
  316.     shufps   xmm1,xmm1,0
  317.     mulps    xmm1,xmm5
  318.  
  319.     movss    xmm2,dword[esi+8]
  320.     shufps   xmm2,xmm2,0
  321.     mulps    xmm2,xmm6
  322.  
  323.     addps    xmm0,xmm1
  324.     addps    xmm0,xmm2
  325.  
  326.     movups   [edi],xmm0
  327.  
  328.     add      esi,12
  329.     add      edi,12
  330.     dec      ecx
  331.     jne      .again
  332.     mov      [edi],dword -1
  333. end if
  334. ret
  335. ;----------------------------------------------
  336. ;  esi - pointer to 3x3 matrix
  337. add_scale_to_matrix:
  338.      fninit
  339.      fld     [rsscale]
  340.      fld     dword[esi]            ;-----
  341.      fmul    st,st1
  342.      fstp    dword[esi]
  343.      fld     dword[esi+12]           ; x scale
  344.      fmul    st,st1
  345.      fstp    dword[esi+12]
  346.      fld     dword[esi+24]
  347.      fmul    st,st1
  348.      fstp    dword[esi+24]         ;------
  349.  
  350.      fld     dword[esi+4]          ;-----
  351.      fmul    st,st1
  352.      fstp    dword[esi+4]
  353.      fld     dword[esi+16]            ; y scale
  354.      fmul    st,st1
  355.      fstp    dword[esi+16]
  356.      fld     dword[esi+28]
  357.      fmul    st,st1
  358.      fstp    dword[esi+28]         ;------
  359.  
  360.  
  361.      fld     dword[esi+8]          ;-----
  362.      fmul    st,st1
  363.      fstp    dword[esi+8]
  364.      fld     dword[esi+20]              ; z scale
  365.      fmul    st,st1
  366.      fstp    dword[esi+20]
  367.      fld     dword[esi+32]
  368.      fmulp    st1,st
  369.      fstp    dword[esi+32]         ;------
  370.  
  371. ret
  372.  
  373. ;in   esi - offset to 3d points  (point as 3 dwords float)
  374. ;     edi - offset to 2d points  ( as 3 words integer)
  375. ;     ecx - number of points
  376. translate_points:  ; just convert into integer; z coord still needed
  377.     fninit
  378.   .again:
  379.     fld    dword[esi+8]
  380.  ;   fmul   [rsscale]
  381.     fist   word[edi+4]
  382.  
  383.     fisub  [zobs]
  384.     fchs
  385.  
  386.     fld    dword[esi]
  387. ;    fmul   [rsscale]
  388.     fisub  [xobs]
  389.     fimul  [zobs]
  390.     fdiv   st0,st1
  391.  
  392.     fiadd  [xobs]
  393.     fiadd  [vect_x]
  394.     fistp  word[edi]
  395.  
  396.     fld    dword[esi+4]
  397. ;    fmul   [rsscale]
  398.     fisub  [yobs]
  399.     fimul  [zobs]
  400.     fdivrp  ;   st0,st1
  401.  
  402.     fiadd  [yobs]
  403.     fiadd  [vect_y]
  404.     fistp  word[edi+2]
  405.  
  406.     add    esi,12
  407.     add    edi,6
  408.     dec    ecx
  409.     jnz    .again
  410.  
  411. ret
  412.