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

  1. ' ---------------------------------  
  2. '
  3. ' AMOSPro Compiler Example 
  4. '
  5. ' 3D dotted Ball 1 
  6. '
  7. ' By Jean-Baptiste BOLCATO 
  8. '
  9. ' (c) 1993 Europress Software Ltd. 
  10. '
  11. ' ---------------------------------  
  12. '
  13. ' ------------------------------------------------------       
  14. ' Remark: A real time calculated 3D dotted Ball. 
  15. '
  16. '         Average Acceleration:  400 % 
  17. '
  18. '         Test configuration: A1200, 6Mb   
  19. '         Original AMOS Compiler:  300 %   
  20. ' ------------------------------------------------------       
  21.  
  22.  
  23. ' ---- Variables Init ---- 
  24.  
  25. Set Buffer 30
  26. ' Lens paramenter
  27. DIST0=300 : ZOM=250
  28.  
  29. ' Radius of ball 
  30. R=100
  31.  
  32. ' Time for loops 
  33. TIME=1000
  34.  
  35. ' Options screen 
  36. Screen Open 0,320,32,2,Hires
  37. Palette 0,$FFF
  38.  
  39. ' Number of x,y steps  
  40. Input "Grid Radius subdivision (8 to 48)?:";NS1
  41. If NS1<8
  42.    NS1=8
  43. Else 
  44.    If NS1>48
  45.       NS1=48
  46.    End If 
  47. End If 
  48. Input "Grid Height subdivision (8 to 48)?:";NS2
  49. If NS2<8
  50.    NS2=8
  51. Else 
  52.    If NS2>48
  53.       NS2=48
  54.    End If 
  55. End If 
  56.  
  57. ' Init coords  
  58. On Error Goto _EXIT
  59. Degree 
  60. NP=NS1*NS2
  61. Dim X3D(NP),Y3D(NP),Z3D(NP)
  62. SJ#=2*R : SJ#=SJ#/(NS2-1)
  63. SI#=360 : SI#=SI#/NS1
  64. K=0
  65. For J#=-R To R Step SJ#
  66.    For I#=1 To 360-SI Step SI#
  67.       Inc K
  68.       X3D(K)=Sqr(R*R-(J#*J#))*Cos(I#)
  69.       Y3D(K)=Sqr(R*R-(J#*J#))*Sin(I#)
  70.       Z3D(K)=J#
  71.    Next I#
  72. Next J#
  73. _EXIT:
  74. NP=K-1
  75.  
  76. ' ---- Screen Init ----
  77.  
  78. Screen Open 0,320,200,2,Lowres
  79. Palette 0,$FFF
  80. Curs Off : Hide 
  81. Cls 0 : Ink 1
  82. Double Buffer : Autoback 0
  83.  
  84. ' ---- Main Loop ----
  85.  
  86. Timer=0
  87. Repeat 
  88.    
  89.    Cls 0
  90.    
  91.    ' Increment rotation angles
  92.    Add TETA,1,0 To 359
  93.    Add PHI,2,0 To 359
  94.    
  95.    ' Precalculation of COSs and SINs  
  96.    ' ( *256 to stay in integer mode (faster!))    
  97.    CPHI=Cos(PHI)*256
  98.    SPHI=Sin(PHI)*256
  99.    CTETA=Cos(TETA)*256
  100.    STETA=Sin(TETA)*256
  101.    
  102.    ' Modify zoom
  103.    DIST=DIST0+SPHI
  104.    
  105.    ' Draw ball backbground  
  106.    R3D=(R*ZOM)/DIST
  107.    Ink 1 : Circle 160,100,R3D-1 : Paint 160,100 : Ink 0
  108.    
  109.    For I=1 To NP
  110.       
  111.       ' Calculation of rotated 3D coords for each displayable
  112.       ' point of the ball (Z<=0) 
  113.       ' ( /256 to bring back COS and SIN beetween 0->1)    
  114.       ' Rotation (X-Z with PHI) & rotation (X-Y with TETA) 
  115.       Z=Z3D(I)*CPHI-Y3D(I)*SPHI
  116.       If Z<=0
  117.          Z=Z/256
  118.          Y=(Z3D(I)*SPHI+Y3D(I)*CPHI)/256
  119.          X=(X3D(I)*CTETA-Y*STETA)/256
  120.          Y=(X3D(I)*STETA+Y*CTETA)/256
  121.          
  122.          ' Calculation of screen coords of A,B,C,D and draw lines     
  123.          X=(X*ZOM)/(DIST+Z) : Add X,160
  124.          Y=(Y*ZOM)/(DIST+Z) : Add Y,100
  125.          Plot X,Y
  126.       End If 
  127.    Next I
  128.    
  129.    Screen Swap 
  130.    Wait Vbl 
  131.    Inc N
  132.    
  133. Until Timer>=TIME
  134. T#=Timer
  135.  
  136. ' --- Final Report --- 
  137.  
  138. Autoback 1 : Cls 0 : Paper 0 : Pen 1
  139. Print "  Needs";T#/50;" seconds for";N;" loops."
  140. V#=T#/N
  141. Print "          ( =";V#;" VBLs )"
  142. Print 
  143. Print "    Press mouse key to end"
  144. Repeat 
  145.    Multi Wait 
  146. Until Mouse Key or(Inkey$<>"")
  147. End