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

  1. ' ---------------------------------  
  2. '
  3. ' AMOSPro Compiler Example 
  4. '
  5. ' Texture mapped Face  
  6. '
  7. ' By Jean-Baptiste BOLCATO 
  8. '
  9. ' (c) 1993 Europress Software Ltd. 
  10. '
  11. ' ---------------------------------  
  12. '
  13. '
  14. ' --------------------------------------------       
  15. ' Remark: Texture Mapped onto 1 rectangular face 
  16. '         (similar effect to Dpaint's Anim-Move command) 
  17. '
  18. '         Average Acceleration:  450 % 
  19. '
  20. '         Test configuration: A1200, 6Mb   
  21. '
  22. '         Original AMOS Compiler:  220 %   
  23. ' --------------------------------------------       
  24.  
  25. ' ---- Variables Init ---- 
  26.  
  27. DIST=500 : ZOM=600
  28.  
  29. ' Number of loops
  30. NL=1
  31.  
  32. ' Coord source 
  33. XS1=0 : YS1=0
  34. XS2=320 : YS2=256
  35.  
  36. ' Coord face limites 
  37. XF1=-100 : YF1=-100
  38. XF2=100 : YF2=100
  39. ZD=0
  40.  
  41. Degree 
  42. Limit Mouse 0,0 To 359,359
  43.  
  44. ' ---- Load Screen ----
  45.  
  46. Load Iff "AMOSPro_Extras:Compiler_Examples/Graphics/demo_pic.iff",1
  47. Screen Hide 1
  48.  
  49. ' ---- Info ---- 
  50.  
  51. Screen Open 0,320,256,2,Lowres
  52. Palette 0,$FFF : Curs Off 
  53. Locate 0,14 : Centre "Move the Mouse:"
  54. Locate 0,16 : Centre "Horizontally: to rotate"
  55. Locate 0,17 : Centre "Vertically:   to zoom  "
  56. Locate 0,19 : Centre "Click key to begin mapping!"
  57. Wait 150
  58.  
  59. Do 
  60.    
  61.    ' ---- Preview placement ----  
  62.    
  63.    Screen Open 0,320,256,2,Lowres
  64.    Curs Off : Hide 
  65.    Palette 0,$FFF
  66.    Paper 0 : Pen 1 : Ink 1 : Cls 0
  67.    Double Buffer : Autoback 0
  68.    
  69.    Repeat 
  70.       
  71.       Cls 0
  72.       Home : Print "Angle:";PHI;"�  Zoom:";ZOM
  73.       
  74.       PHI=X Mouse
  75.       ZOM=10+Y Mouse*3
  76.       
  77.       ' Precalculation of COSs and SINs  
  78.       ' ( *128 to stay in integer mode (so faster!))     
  79.       CPHI=Cos(PHI)*128
  80.       SPHI=Sin(PHI)*128
  81.       
  82.       
  83.       ' Calculation of 3D proj coords corners
  84.       ZP1=(ZD*CPHI-XF1*SPHI)/128
  85.       XP1=(ZD*SPHI+XF1*CPHI)/128
  86.       ZP2=(ZD*CPHI-XF2*SPHI)/128
  87.       XP2=(ZD*SPHI+XF2*CPHI)/128
  88.       
  89.       ' Calculation of screen coords of corners  
  90.       X1=160+(XP1*ZOM)/(DIST+ZP1)
  91.       Y1=128+(YF1*ZOM)/(DIST+ZP1)
  92.       X2=X1
  93.       Y2=128+(YF2*ZOM)/(DIST+ZP1)
  94.       X3=160+(XP2*ZOM)/(DIST+ZP2)
  95.       Y3=128+(YF2*ZOM)/(DIST+ZP2)
  96.       X4=X3
  97.       Y4=128+(YF1*ZOM)/(DIST+ZP2)
  98.       
  99.       ' Draw the preview square
  100.       Circle X1,Y1,2
  101.       Draw X1,Y1 To X2,Y2
  102.       Draw To X3,Y3
  103.       Draw To X4,Y4
  104.       Draw To X1,Y1
  105.       
  106.       Screen Swap 
  107.       Wait Vbl 
  108.       
  109.    Until Mouse Click
  110.    
  111.    ' Remember extreme coordinates 
  112.    X0=Min(X1,X3) : If X0<0 Then X0=0
  113.    X1=Max(X1,X3) : If X1>320 Then X1=320
  114.    Y0=Min(Y1,Y4) : If Y0<0 Then Y0=0
  115.    Y1=Max(Y2,Y3) : If Y1>256 Then Y1=256
  116.    
  117.    ' ---- Mapping! ---- 
  118.    
  119.    ' Init screen
  120.    Screen 1
  121.    Screen Open 0,Screen Width,Screen Height,Screen Colour,Lowres
  122.    Flash Off : Curs Off : Cls 0 : Hide 
  123.    Get Palette 1
  124.    
  125.    Timer=0
  126.    
  127.    For N=1 To NL
  128.       
  129.       Cls 0
  130.       
  131.       ' Precalculation of COSs and SINs  
  132.       ' ( *128 to stay in integer mode (so faster!))     
  133.       CPHI=Cos(PHI)*128
  134.       SPHI=Sin(PHI)*128
  135.       
  136.       For Y=Y0 To Y1
  137.          For X=X0 To X1
  138.             
  139.             ' Reversed calculation 2D -> 3D (for Z=ZD and only PHI rotation)   
  140.             ZDC=ZD*CPHI
  141.             DIST2=128*DIST
  142.             X3=160*DIST2+160*ZDC+ZOM*ZD*SPHI-X*(DIST2+ZDC)
  143.             X3=X3/(160*SPHI-X*SPHI-ZOM*CPHI)
  144.             Y3=Y*(DIST+(ZDC-X3*SPHI)/128)-DIST2-ZDC+X3*SPHI
  145.             Y3=Y3/ZOM
  146.             
  147.             ' If inside the face then calculate source pixel's ink 
  148.             If X3>XF1 and X3<XF2 and Y3>YF1 and Y3<YF2
  149.                X2=XS1+((XS2-XS1)*(X3-XF1))/(XF2-XF1)
  150.                Y2=YS1+((YS2-YS1)*(Y3-YF1))/(YF2-YF1)
  151.                Screen 1 : IK=Point(X2,Y2)
  152.                ' draw!
  153.                Screen 0 : Plot X,Y,IK
  154.             End If 
  155.             
  156.          Next X
  157.       Next Y
  158.       
  159.       ' Increment rotation angles
  160.       Add PHI,10,0 To 359
  161.       
  162.    Next N
  163.    T#=Timer
  164.    
  165.    ' --- Final Report --- 
  166.    
  167.    Paper 0 : Pen 1 : Home 
  168.    Print "   Needs";T#/50;" seconds for";NL;" loops."
  169.    Print "           ( =";T#/NL;" VBLs )"
  170.    Print "  Right button to quit, left to restart."
  171.    Repeat 
  172.       Multi Wait 
  173.       MC=Mouse Click
  174.    Until MC
  175.    Exit If MC=2
  176.    
  177. Loop 
  178.  
  179. End