home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 4: Demo 1 / almathera_demo1.bin / amos / 3dforglasses.amos / 3dforglasses.amosSourceCode next >
AMOS Source Code  |  1995-03-16  |  4KB  |  165 lines

  1. Screen Open 0,320,256,4,Lowres : Flash Off : Curs Off : Hide On : Cls 0
  2. Palette 0,$FFC : Pen 1 : Paper 0
  3. Locate 1,2 : Centre "3D Vector Graphics for 3D Glasses."
  4. Locate 1,3 : Centre "=================================="
  5. Locate 1,5 : Centre "By Dominic Ramsey"
  6. Locate 0,10 : Centre "To use this program, you  will need a"
  7. Locate 1,11 : Centre "pair of red/blue or red/green"
  8. Locate 1,12 : Centre "3D glasses. The program is currently"
  9. Locate 1,13 : Centre "set up for red/blue glasses."
  10. Locate 1,15 : Centre "For best results, adjust the"
  11. Locate 1,16 : Centre "brightness of your monitor and"
  12. Locate 1,17 : Centre " your viewing distance."
  13. Locate 1,28 : Centre "Press a key to start."
  14. Wait Key 
  15. Music 1 : Led Off 
  16. Cls 0
  17. Gr Writing 3
  18. Dim X#(20),Y#(20),Z#(20),XX(20,2),YY(20,2)
  19. Dim F1(20),F2(20)
  20. '
  21. 'set Degree mode and precalculate values for sin and cos of
  22. ' rotation angle ( 2 degrees)
  23. '
  24. Degree : CS#=Cos(2)*1.0006 : SN#=Sin(2)*1.0006
  25. '
  26. ' D = Vanishing point on Z Axis
  27. '
  28. ' Try changing D. The Lower the value, the closer the observer is to the 
  29. ' object.
  30. D=5
  31. ' Set for manual screen swapping 
  32. Double Buffer : Autoback 0
  33. M:
  34.  MN=0 : NXTOBJ=1
  35. Restore 
  36. RD:
  37. Fade 2 : Wait 30 : Cls 0 : Screen Swap 
  38. ' set palette according to 3D glasses
  39. ' For Red - blue glasses 
  40. Fade 2,$0,$A00,$A0A,$A
  41. ' For Red - reen glasses change above line to Fade 2,$0,$a00,$aa0,$0a
  42. If NXTOBJ=0 Then Goto M
  43. MN=0
  44. Read NP,NL
  45. L=NL+1 : P=NP+1
  46.  For A=1 To NP
  47.   Read X#(A),Y#(A),Z#(A)
  48.  Next 
  49. '
  50.  For A=1 To NL
  51.   Read F1(A),F2(A)
  52.  Next 
  53. Read NXTOBJ
  54. '0 if no more objs 
  55. '
  56. ' Data for ponts in 3D space (X,Y,Z) 
  57. ' must range from -1 to +1 
  58. '
  59. '
  60. CDAT:
  61. ' Cube 
  62. Data 8,12
  63. Data -1,-1,-1,1,-1,-1,1,1,-1,-1,1,-1
  64. Data -1,-1,1,1,-1,1,1,1,1,-1,1,1
  65. Data 1,2,2,3,3,4,4,1,5,6,6,7,7,8,8,5,1,5,2,6,3,7,4,8
  66. Data 1
  67. 'House 
  68. Data 9,16
  69. Data -1,-1,-1,1,-1,-1,1,1,-1,-1,1,-1
  70. Data -1,-1,0.5,1,-1,0.5,1,1,0.5,-1,1,0.5,0,0,1
  71. Data 1,2,2,3,3,4,4,1,5,6,6,7,7,8,8,5,1,5,2,6,3,7,4,8,5,9,6,9,7,9,8,9
  72. Data 1
  73. 'Pyramid 
  74. Data 5,8
  75. Data 0,1,0,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1
  76. Data 1,2,1,3,1,4,1,5,2,3,3,4,4,5,5,2
  77. Data 1
  78. 'DR
  79. Data 15,13
  80. Data -1,1,0,-0.6,1,0,-0.2,0.6,0,-0.2,-0.6,0,-0.6,-1,0,-1,-1,0
  81. Data 0,1,0,0.8,1,0,1,0.6,0,1,0.4,0,0.8,0,0,0,0,0,0,-1,0,0.6,0,0,1,-1,0
  82. Data 1,2,2,3,3,4,4,5,5,6,6,1
  83. Data 7,8,8,9,9,10,10,11,11,12,7,13,14,15
  84. Data 0
  85. ' No more objs 
  86. 'ROTATIONS 
  87. '========= 
  88. 'The simple routine below rotates around 2 of 3 axes at once.
  89. 'The formulae for rotation are simple.  See ROTX,ROTY,ROTZ 
  90. 'to see how its done.
  91. '
  92. DX=-70
  93. Repeat 
  94. ROT:
  95. Inc MN
  96. If MN>250 Then Goto RD
  97. Add R,1,1 To 100
  98. A=1 : While A<P
  99. If R<33
  100.  Gosub ROTX
  101.  Gosub ROTY
  102.  Else If R>32 and R<66
  103.   Gosub ROTZ
  104.   Gosub ROTY
  105.  Else 
  106.  Gosub ROTX
  107.  Gosub ROTZ
  108. End If 
  109. End If 
  110. Inc A
  111. Wend 
  112. 'DISPLAY OBJECT
  113. A=1
  114. While A<P
  115. 'convert Z factor of a point into x and y coords 
  116. ZZ#=Z#(A)-1
  117. ' Move object out of screen
  118. XX(A,1)=X#(A)*D/(ZZ#+D)*50
  119. YY(A,1)=Y#(A)*D/(ZZ#+D)*50
  120. 'Second image
  121. XX(A,2)=(X#(A)+(ZZ#/20)-0.3)*D/(ZZ#+D)*50
  122. YY(A,2)=Y#(A)*D/(ZZ#+D)*50
  123. ' translation to middle of screen. 
  124. XX(A,1)=XX(A,1)+170
  125. YY(A,1)=YY(A,1)+128
  126. 'Second image
  127. XX(A,2)=XX(A,2)+170
  128. YY(A,2)=YY(A,2)+128
  129. Inc A
  130. Wend 
  131. Cls 0
  132. A=1
  133. ' draw lines 
  134. While A<L
  135. F1=F1(A) : F2=F2(A)
  136. Gr Writing 0
  137. Ink 1,
  138. Draw XX(F1,1),YY(F1,1) To XX(F2,1),YY(F2,1)
  139. Gr Writing 2
  140. Draw XX(F1,2),YY(F1,2) To XX(F2,2),YY(F2,2)
  141. Inc A
  142. Wend 
  143. '
  144. Screen Swap 
  145. Until Mouse Key
  146. Music Off : End 
  147. '
  148. '
  149. ' Rotation Subroutines 
  150. '
  151. '
  152. ROTZ:
  153. X#(A)=X#(A)*CS#-Y#(A)*SN#
  154. Y#(A)=Y#(A)*CS#+X#(A)*SN#
  155. Return 
  156. '
  157. ROTY:
  158. X#(A)=X#(A)*CS#-Z#(A)*SN#
  159. Z#(A)=Z#(A)*CS#+X#(A)*SN#
  160. Return 
  161. '
  162. ROTX:
  163. Y#(A)=Y#(A)*CS#-Z#(A)*SN#
  164. Z#(A)=Z#(A)*CS#+Y#(A)*SN#
  165. Return