home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Amos / amproe2x.dms / in.adf / Compiler_Examples / AMOS_versions / DotBall2.AMOS / DotBall2.amosSourceCode
Encoding:
AMOS Source Code  |  1993-06-16  |  3.2 KB  |  158 lines

  1. ' ---------------------------------  
  2. '
  3. ' AMOSPro Compiler Example 
  4. '
  5. ' 3D dotted Ball 2 
  6. '
  7. ' By Jean-Baptiste BOLCATO 
  8. '
  9. ' (c) 1993 Europress Software Ltd. 
  10. '
  11. ' ---------------------------------  
  12. '
  13. ' ------------------------------------------------------       
  14. ' Remark: Here is a precalculated smooth-topped    
  15. '         3D dotted Ball.      
  16. '
  17. '         Average Acceleration:  260 % 
  18. '
  19. '         Test configuration: A1200, 6Mb 
  20. '
  21. '         Original AMOS Compiler:  240 % 
  22. ' ------------------------------------------------------       
  23.  
  24.  
  25. ' ---- Variables Init ---- 
  26.  
  27. Set Buffer 30
  28.  
  29. ' Lens paramenter
  30. DIST0=512 : ZOM=256
  31.  
  32. ' Radius and resolution of ball  
  33. R=64
  34. NS1=16 : NS2=16
  35.  
  36. ' Init coords  
  37. On Error Goto _EXIT
  38. Degree 
  39. NP=256
  40. Dim X3D(NP),Y3D(NP),Z3D(NP)
  41. SJ#=2*R : SJ#=SJ#/15
  42. SI#=360 : SI#=SI#/16
  43. K=0
  44. For J#=-R To R Step SJ#
  45.    For I#=1 To 360-SI Step SI#
  46.       Inc K
  47.       X3D(K)=Sqr(R*R-(J#*J#))*Cos(I#)
  48.       Y3D(K)=Sqr(R*R-(J#*J#))*Sin(I#)
  49.       Z3D(K)=J#
  50.    Next I#
  51. Next J#
  52. _EXIT:
  53. NP=K-1
  54.  
  55. ' ---- Screen Init ----
  56.  
  57. Screen Open 0,320,200,4,Lowres
  58. Flash Off : Curs Off : Hide : Cls 0
  59. Palette 0,$FFF,$777,$555
  60. For I=0 To 3
  61.    Colour 17+I*4,$FCC
  62.    Colour 18+I*4,$D22
  63.    Colour 19+I*4,$A11
  64. Next I
  65. Double Buffer : Autoback 0
  66. If Chip Free>150000 Then STP=10 Else STP=5
  67.  
  68. ' ---- Main Loop ----
  69.  
  70. Timer=0
  71. For PHI=0 To 359 Step STP
  72.    
  73.    Cls 0
  74.    
  75.    ' Increment rotation angles
  76.    Add TETA,1,0 To 359
  77.    
  78.    ' Precalculation of COSs and SINs  
  79.    ' ( *256 to stay in integer mode (faster!))    
  80.    CPHI=Cos(PHI)*256
  81.    SPHI=Sin(PHI)*256
  82.    CTETA=Cos(TETA)*256
  83.    STETA=Sin(TETA)*256
  84.    
  85.    ' Modify zoom
  86.    DIST=DIST0+SPHI
  87.    
  88.    ' Draw ball backbground  
  89.    R3D=(R*ZOM)/DIST
  90.    Ink 3 : Circle 160,100,R3D : Paint 160,100
  91.    
  92.    For I=1 To NP
  93.       
  94.       ' Calculation of rotated 3D coords for each displayable
  95.       ' point of the ball (Z>=0) 
  96.       ' ( /256 to bring back COS and SIN beetween 0->1)    
  97.       ' rotation (X-Z with PHI) & rotation (X-Y with TETA) 
  98.       Z=(Z3D(I)*CPHI-Y3D(I)*SPHI)/256
  99.       Y=(Z3D(I)*SPHI+Y3D(I)*CPHI)/256
  100.       X=(X3D(I)*CTETA-Y*STETA)/256
  101.       Y=(X3D(I)*STETA+Y*CTETA)/256
  102.       
  103.       ' Calculation of screen coords of A,B,C,D and draw lines     
  104.       X=(X*ZOM)/(DIST+Z) : Add X,160
  105.       Y=(Y*ZOM)/(DIST+Z) : Add Y,100
  106.       
  107.       ' Display point
  108.       If Z<=0 Then Ink 1 Else Ink 2
  109.       Plot X,Y
  110.       
  111.    Next I
  112.    
  113.    Inc N
  114.    Get Bob N,160-64,100-64 To 160+64,100+64
  115.    
  116.    Screen Swap 
  117.    Wait Vbl 
  118.    
  119. Next PHI
  120.  
  121. T#=Timer
  122.  
  123. ' ---- Status Report ----  
  124.  
  125. Autoback 2 : Cls 0 : Paper 0 : Pen 1
  126. Print "Needs";T#/50;"s for the whole calculation."
  127. Print "      ( =";T#/N;" VBLs per loop)"
  128. Wait 50
  129. Print "       Ready?...    ";
  130. Wait 50 : Print "Gooooo !!!"
  131. Wait 50
  132. Cls 0
  133. X1=100 : Y1=0 : VX1=1 : DF1=0
  134. X2=180 : Y2=0 : VX2=-2 : DF2=5
  135.  
  136.  
  137. ' ---- Final Fireworks!!! ---- 
  138.  
  139. Set Bob 0,1,,
  140. Set Sprite Buffer 256 : Hide 
  141.  
  142. Clear Key 
  143. Repeat 
  144.    
  145.    Add DF1,1,1 To N
  146.    Add X1,VX1 : If X1>192 or X1<0 Then VX1=-VX1
  147.    Inc VY1 : Add Y1,VY1 : If Y1>80 Then Y1=80 : VY1=-4-Rnd(8)
  148.    Bob 0,X1,Y1,DF1
  149.    
  150.    Add DF2,-1,1 To N
  151.    Add X2,VX2 : If X2>192 or X2<0 Then VX2=-VX2
  152.    Inc VY2 : Add Y2,VY2 : If Y2>80 Then Y2=80 : VY2=-4-Rnd(8)
  153.    Sprite 0,X2+128,Y2+45,DF2
  154.    
  155.    Wait Vbl 
  156.    
  157. Until Mouse Key or(Inkey$<>"")
  158. End