home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / DEMOS / MEGADEMO / PASSIONP.ARJ / PASSIONP.MSA / SHADING / ROTATION.S < prev    next >
Text File  |  1997-03-05  |  6KB  |  180 lines

  1. ; *************************************************************************
  2. ; ****                       ****
  3. ; ****     Routine which rotate points around two axis.           ****
  4. ; ****                  By Alain BROBECKER.           ****
  5. ; ****        24th June 1994               ****
  6. ; ****                       ****
  7. ; *************************************************************************
  8. ; To gain speed, I have decided to make only two rotations.. The movements
  9. ; are then less various, but you can make nice moves anyway.. Another gain
  10. ; is done due to the organisation of the initial points. They are placed so
  11. ; that all the points with the same x coordinates are placed one after
  12. ; another... The exact definition for a set of point which have the same
  13. ; x coord is the following:
  14. ;   1 word      n    Number of points with the next x coord.
  15. ;   1 word      x    x coord of the n points.
  16. ;   2*n words    y(n);z(n)    y and z of all the points.
  17. ;
  18. ; For example a cube will be defined like this:
  19. ;      4    There are 4 brows with the next x.
  20. ;     40    x coord of next 4 brows.
  21. ;     40; 40    y & z coords of brow 1.
  22. ;    -40; 40    y & z coords of brow 2.
  23. ;     40;-40    y & z coords of brow 3.
  24. ;    -40;-40    y & z coords of brow 4.
  25. ;      4    There are 4 brows with the next x.
  26. ;    - 40    x coord of next 4 brows.
  27. ;     40; 40    y & z coords of brow 5.
  28. ;    -40; 40    y & z coords of brow 6.
  29. ;     40;-40    y & z coords of brow 7.
  30. ;    -40;-40    y & z coords of brow 8.
  31. ;      0    No more brows.
  32. ;
  33. ; The points after the rotation are saved "normally". This mean each point
  34. ; has its x;y;z coords saved, one after another. The depth effect is not
  35. ; done because some tridi calculations (lightsourcing...) need to have
  36. ; tridi vectors.
  37. ; Another thing, again to gain some clockcycles is that all the coords must
  38. ; be premultiplicated by 256. So, in the example above, you should have
  39. ; 40*256 instead of 40.
  40. ; *************************************************************************
  41. ; The parameters for the routine are:
  42. ;    a0.l = adress of the initial points.
  43. ;    a1.l = adress where to save the rotated points.
  44. ;    d0.w = angle around x=a. (0-255)
  45. ;    d1.w = angle around y=b. (0-255)
  46.  
  47.   movem.l    d0-a6,-(sp)
  48.  
  49. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. ; Let' s begin with the calculation of all the matricial coefficients.
  51.  
  52. .calc_coefs:
  53.   move.l    #.sinus,a2    ; Sinus table.
  54.   move.l    a2,a3
  55.   add.w    #$80,a3    ; Cosinus table.
  56.   add.w    d0,d0    ; One word per sinus.
  57.   add.w    d1,d1
  58.   move.w    (a3,d1.w),-(sp)    ; Store A=cos(b).
  59.   move.w    (a2,d1.w),-(sp)    ; Store G=sin(b).
  60.   move.w    (a3,d0.w),-(sp)    ; Store E=cos(a).
  61.   move.w    (a2,d0.w),-(sp)    ; Store F=sin(a).
  62.   move.w    #$1ff,d7    ; A mask for (a+-b mod(256))*2.
  63.   move.w    d0,d2
  64.   add.w    d1,d2    ; d2=a+b.
  65.   and.w    d7,d2    ; Only 256 sinus.
  66.   move.w    d0,d3
  67.   sub.w    d1,d3    ; d3=a-b.
  68.   and.w    d7,d3
  69.   sub.w    d0,d1    ; d1=b-a.
  70.   and.w    d7,d1
  71.   move.w    (a3,d3.w),d0    ; d0=cos(a-b).
  72.   move.w    (a3,d2.w),d4    ; d4=cos(a+b).
  73.   move.w    (a2,d1.w),d1    ; d1=sin(b-a).
  74.   move.w    (a2,d2.w),d2    ; d2=sin(a+b).
  75.   move.w    (a2,d3.w),d3    ; d3=sin(a-b).
  76.   move.w    d4,d5
  77.   sub.w    d0,d5    ; d5=cos(a+b)-cos(a-b).
  78.   ext.l    d5
  79.   lsr.l    #$1,d5
  80.   move.w    d5,-(sp)    ; Store B=-0.5*(cos(a-b)-cos(a+b)).
  81.   add.w    d2,d1    ; d1=sin(b-a)+sin(a+b)
  82.   ext.l    d1
  83.   lsr.l    #$1,d1
  84.   move.w    d1,-(sp)    ; Store C=0.5*(sin(a+b)+sin(b-a)).
  85.   move.w    d2,d1
  86.   add.w    d3,d1    ; d1=sin(a+b)+sin(a-b).
  87.   ext.l    d1
  88.   lsr.l    #$1,d1    ; d1=H=0.5*(sin(a+b)+sin(a-b)).
  89.   add.w    d4,d0    ; d0=cos(a-b)+cos(a+b).
  90.   neg.w    d0
  91.   ext.l    d0
  92.   lsr.l    #$1,d0    ; d0=I=-0.5*(cos(a+b)+cos(a-b)).
  93.  
  94. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. ; Let' s continue with the calculations of B*C;E*F;H*I.
  96.  
  97.   move.w    (sp),d2
  98.   muls.w    d2,d5    ; d5=B*C.
  99.   swap.w    d5
  100.   move.w    d5,a2
  101.   move.w    d1,d2
  102.   muls.w    d0,d2    ; d2=H*I.
  103.   swap.w    d2
  104.   move.w    d2,a4
  105.   move.w    $4(sp),d2    ; d2=F.
  106.   muls.w    $6(sp),d2    ; d2=E*F.
  107.   swap.w    d2
  108.   move.w    d2,a3
  109.  
  110. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. ; So, here we have:
  112. ;  a2.w = B*C      a3.w = E*F     a4.w = H*I
  113. ;  d0.w = I      d1.w = H     (sp) = C
  114. ;  2(sp) = B      4(sp) = F     6(sp) = E
  115. ;  8(sp) = G      a(sp) = A.
  116. ; Now let' s go for the calculations for each point.
  117.  
  118. .one_x_coord:        ; A set of points with the same x coord.
  119.   move.w    (a0)+,d7    ; d7=nb of points with this x.
  120.   subq.w    #$1,d7    ; Beware the dbra.
  121.   bmi.s    .the_end    ; d7=0? No more points?
  122.   move.w    (a0)+,d6    ; d6=x.
  123.   move.w    $a(sp),d5    ; d5=A.
  124.   muls.w    d6,d5
  125.   swap.w    d5
  126.   move.w    d5,a5    ; a5=A*x.
  127.   muls.w    $8(sp),d6
  128.   swap.w    d6
  129.   move.w    d6,a6    ; a6=G*x.
  130. .one_point:
  131.   move.w    (a0)+,d5    ; d5=y.
  132.   move.w    (a0)+,d6    ; d6=z.
  133.   move.w    d6,d4
  134.   muls.w    d5,d4    ; d4=y*z.
  135.   swap.w    d4
  136.   move.w    (sp),d2    ; d2=C.
  137.   move.w    $2(sp),d3    ; d3=B.
  138.   add.w    d5,d2    ; d2=C+y.
  139.   add.w    d6,d3    ; d3=B+z.
  140.   muls.w    d2,d3    ; d3=(B+z)*(C+y).
  141.   swap.w    d3
  142.   sub.w    d4,d3    ; d3=..-y*z.
  143.   sub.w    a2,d3    ; d3=..-B*C.
  144.   add.w    a5,d3    ; d3=..+A*x.
  145.   move.w    d3,(a1)+    ; Save x=(B+z)*(C+y)-y*z-B*C+A*x.
  146.   move.w    $4(sp),d2    ; d2=F.
  147.   move.w    $6(sp),d3    ; d3=E.
  148.   add.w    d5,d2    ; d2=F+y.
  149.   add.w    d6,d3    ; d3=E+z.
  150.   muls.w    d2,d3    ; d3=(E+z)*(F+y).
  151.   swap.w    d3
  152.   sub.w    d4,d3    ; d3=..-y*z.
  153.   sub.w    a3,d3    ; d3=..-E*F.
  154.   move.w    d3,(a1)+    ; Save y=(E+z)*(F+y)-y*z-E*F.
  155.   add.w    d0,d5    ; d5=I+y.
  156.   add.w    d1,d6    ; d6=H+z.
  157.   muls.w    d5,d6    ; d6=(H+z)*(I+y).
  158.   swap.w    d6
  159.   sub.w    d4,d6    ; d6=..-y*z.
  160.   sub.w    a4,d6    ; d6=..-H*I.
  161.   add.w    a6,d6    ; d6=..+G*x.
  162.   neg.w    d6
  163.   move.w    d6,(a1)+    ; Save z=(H+z)*(I+y)-y*z-H*I+G*x.
  164.   dbra    d7,.one_point    ; Next point.
  165.   bra.s    .one_x_coord    ; Next x set.
  166.  
  167. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168. ; Pfiuuuu... It's the end for now.
  169.  
  170. .the_end:
  171.   add.l    #$c,sp    ; Fuck what was stored.
  172.   movem.l    (sp)+,d0-a6
  173.   rts
  174.  
  175. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  176.   Section DATA
  177.  
  178. .sinus:
  179.   incbin    'a:\shading\sinus.xxx'
  180.