home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / graphics / b109_1 / !3D_Utils / Demo (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1994-01-15  |  7KB  |  259 lines

  1.  demo of 3d_utils by Michel Grimminck
  2.  vdu 16,time(10)
  3. init3Dswinames                :
  4.  Put names of swi's in variables
  5. "TD_GetInfo" 
  6.  info           :
  7.  Get info on screenmode, etc.
  8.  info!4:
  9. "TD_CurrentScreen" :
  10.  always necessary !
  11.  640,512           :
  12.  Set OS origin to quandrangle module's origin
  13.     @StartCount=info!44                :
  14.  read quadrangle counter
  15. initbankswap
  16. points
  17. rotatequad
  18.  Statistics:
  19. "TD_GetInfo" 
  20.  info
  21. "There were ";info!44-StartCount;" quadrangles drawn"
  22. "There were ";info!44;" quadrangles drawn since module startup"
  23. "There were ";info!56;" SWI's called since module startup"
  24. "TD_ClrScreen",255    :
  25.  Clear the screen, dithering white and black
  26.  data 40000           :
  27.  Space for quadrangles
  28.     X%=(T%-128)/128*640
  29.     X1%=(T%-124)/128*640
  30. 3    
  31. "TD_RGBto16bit",255-T%,255-T%,255-T% 
  32. @    
  33. "TD_Quadrangle",X%,-1000,X1%,-1000,X1%,1000,X%,1000,C%
  34. I=100:C=4
  35.  T=I 
  36. -1         
  37. AD=data+36*(I-T)
  38. $1AD!0=-C*T:AD!4=-C*T      :
  39.  Set x,y positions
  40. AD!8=C*T:AD!12=-C*T
  41. AD!16=C*T:AD!20=C*T
  42. AD!24=-C*T:AD!28=C*T
  43. (%AD!32=T*257              :
  44.  Color
  45. "TD_QuadrangleList",data,I+1  :
  46.  Draw the quadrangles
  47. points
  48.  place points at random positions with random colors
  49.  T%=0
  50. 25000:
  51.  TD_Point%,
  52. (1280)-640,
  53. (1024)-512,257*
  54. (255):
  55. rotatequad
  56. "TD_ClrScreen",1
  57.  X0(3),Y0(3),X(3),Y(3)
  58. "Basic routine:";
  59. 40,0);"Quadrangle routine:"
  60. "Each routine gets an equal fraction of the processor time"
  61. ALFA=.02:C=1:C0=1
  62. X(0)=-200:Y(0)=-200
  63. X(1)=200 :Y(1)=-200
  64. X(2)=200 :Y(2)= 200
  65. X(3)=-200:Y(3)= 200
  66. X0()=X():Y0()=Y()
  67. (ALFA):CA=
  68. (ALFA)
  69.  U%=1
  70.  TD_Quadrangle%,X0(0)+300,Y0(0),X0(1)+300,Y0(1),X0(2)+300,Y0(2),X0(3)+300,Y0(3),C0*257          :
  71.  Draw a quadrangle
  72. C;     X=X0(I%)*CA-Y0(I%)*SA      :
  73.  Rotate corner points
  74.      Y=X0(I%)*SA+Y0(I%)*CA
  75.      X0(I%)=X:Y0(I%)=Y
  76.   C0=(C0+1)
  77.  C/4 
  78.  64*(C 
  79.  X(0)-300,Y(0):
  80.  X(1)-300,Y(1)
  81. 85,X(3)-300,Y(3):
  82. 85,X(2)-300,Y(2)
  83.      X=X(I%)*CA-Y(I%)*SA
  84.      Y=X(I%)*SA+Y(I%)*CA
  85.      X(I%)=X:Y(I%)=Y
  86.   C=(C+1)
  87. initbackground
  88. "TD_ClrScreen",&8A8B:Tcount=0
  89. steps%=24
  90.  Object 2*12*steps%,XYZ% 2*12*steps%,Matrix 9*4,quad 6*2*steps%
  91.  Make a cilinder
  92.  T%=0
  93.  steps%-1
  94.     A=(T%/steps%)*2*
  95. `&    X=1024*
  96. (A):Y=1024*
  97. (A):Z=1024
  98. a>    Object!(12*T%)=X:Object!(12*T%+4)=Y:Object!(12*T%+8)=Z
  99. bZ    Object!(12*(T%+steps%))=X:Object!(12*(T%+steps%)+4)=Y:Object!(12*(T%+steps%)+8)=-Z
  100.  Set the quadrangles, first the inside, than the outside of the object
  101.  steps%-1
  102. f5    T1%=(T%+1)
  103.  steps%:
  104.  T%>=steps% 
  105.  T1%+=steps%
  106.     T2%=T%+steps%
  107. h        :
  108.  inside
  109. j        :
  110. kO    AD=quad+6*T%                                :
  111.  address of current quad.
  112. l<    AD?0=T%:AD?1=T2%:AD?2=(T2%+1)
  113. steps%+steps%:AD?3=T1%
  114.     J%=
  115. *T%/steps%)*64
  116. nG    
  117. "TD_RGBto16bit",J%+64,J%+64,J%+64 
  118.  C%  :
  119.  calc a nice colour
  120. o;    AD?4=C% >>8:AD?5=C% 
  121. 255                  :
  122.  Colour
  123. p        :
  124. q*    
  125.  outside:corners in reverse order
  126. r        :
  127.     AD2=AD+6*steps%
  128. t3    AD2?0=AD?3:AD2?1=AD?2:AD2?2=AD?1:AD2?3=AD?0
  129.     J%=
  130. *T%/steps%)*80
  131. v5    
  132. "TD_RGBto16bit",2*J%+118,J%+118,J%+118 
  133. w"    AD2?4=C% >>8:AD2?5=C% 
  134. y9RX=3:RY=1:RZ=1:S=0       :
  135.  RX,RY,RZ = rotation angle
  136. bankswap
  137. makematrix(RX,RY,RZ,1000,500)   :
  138.  create a rotation matrix
  139. "TD_QuadrangleList",background,back :
  140.  draw background
  141. 0,1);"Framerate:";
  142. (1000/(
  143. -time(Tcount))+.5):time(Tcount)=
  144. :Tcount=(Tcount+1)
  145. "TD_Rotate",Object,XYZ%,Matrix,steps%*2,12     :
  146.  rotate the points in space
  147. >300 
  148. 0,0)"And now a little perspective ..."
  149. >300 
  150. "TD_Perspective",XYZ%,steps%*2,21,300*
  151. (S),300*
  152. (1.3*S+1)          :
  153.  Add perspective and move over the screen.
  154. <600 
  155. !    
  156.  draw wireframe in basic
  157.  T%=0
  158. 2*steps%-1
  159. 9        T1%=(T%+1)
  160.  steps%:
  161.  T%>=steps% 
  162.  T1%+=steps%
  163.         T2%=T%+steps%
  164. U        
  165.  TD_Line%,XYZ%!(12*T%),XYZ%!(12*T%+4),XYZ%!(12*T1%),XYZ%!(12*T1%+4),255
  166. b        
  167.  T%<steps% :
  168.  TD_Line%,XYZ%!(12*T%),XYZ%!(12*T%+4),XYZ%!(12*T2%),XYZ%!(12*T2%+4),255
  169.         
  170.         
  171. C    
  172.  draw solid object, note this is faster than the wireframe
  173. ,    
  174. "TD_DrawSimple",XYZ%,quad,steps%*2
  175.         
  176. 8RY+=.05:RX+=.025:RZ-=.01:S+=.05   :
  177.  increase angles
  178. >1600
  179. initbackground
  180.  Set up a list of quadrangles, to be used as background.
  181.  background 32*36
  182. back=0
  183.     Y%=(T%-128)/128*512
  184.     Y1%=(T%-120)/128*512
  185. (    
  186. "TD_RGBto16bit",T%,T%,255 
  187.     ad=background+36*back
  188.     ad!0=-1000:ad!4=Y%
  189.     ad!8=1000:ad!12=Y%
  190.     ad!16=1000:ad!20=Y1%
  191.     ad!24=-1000:ad!28=Y1%
  192.     ad!32=C%
  193.     back+=1
  194. makematrix(RX,RY,RZ,SCA,SCZ)
  195.  SCA is scaling in x and y direction, SCZ is scaling in z direction
  196.  RX:SD=
  197.  RX:CC=
  198.  RY:SC=
  199.  RY:CG=
  200.  RY:SG=
  201. UMatrix!0=(CD*CC-SD*SG*SC)*SCA :Matrix!4=(SD*SG*CC+CD*SC)*SCA :Matrix!8=-SD*CG*SCA
  202. UMatrix!12=(SD*CC+CD*SG*SC)*SCA:Matrix!16=(SD*SC-CD*SG*CC)*SCA:Matrix!20=CD*CG*SCA
  203. RMatrix!24=-(CG*SC)*SCZ        :Matrix!28=CC*CG*SCZ           :Matrix!32=SG*SCZ
  204. init3Dswinames
  205.  Defines variables for use in basic for fast access to the SWI's
  206. TD_ScreenAddress%=&0CCB40
  207. TD_QuadrangleList%=&0CCB41
  208. TD_Rotate%=&0CCB42
  209. TD_ClrScreen%=&0CCB43
  210. TD_Quadrangle%=&0CCB44
  211. TD_Point%=&0CCB45
  212. TD_Perspective%=&0CCB46
  213. TD_DrawSimple%=&0CCB47
  214. TD_CurrentScreen%=&0CCB48
  215. TD_GetInfo%=&0CCB49
  216. TD_PointList%=&0CCB4A
  217. TD_RGBto16bit%=&0CCB4B
  218. TD_Decompress%=&0CCB4C
  219. TD_DrawSorted%=&0CCB4D
  220. TD_SetWindow%=&0CCB4E
  221. TD_Line%=&0CCB4F
  222. bankswap
  223.  bankswapper for 1, 2 or 3 banks. If using 3 banks, there is no need for
  224.  the WAIT statement, saving 10 millisecs on average.
  225.  BankMax%=1 
  226.                   :
  227.  just one bank
  228.  BankMax%<3 
  229.                      :
  230.  just two banks
  231. 8NB%=bank%+1:
  232.  NB%>BankMax% 
  233.  NB%=1      :
  234.  next bank
  235. 6,112,NB%:
  236. 6,113,bank%
  237.  "TD_ScreenAddress",StartScreen%+ScrMem%*(NB%-1)
  238. bank%=NB%
  239. initbankswap
  240. vdu!0=149:vdu!4=-1
  241. "OS_ReadVduVariables",vdu,vdu+8
  242. StartScreen%=vdu!8
  243. .ScrMem%=info!32              :
  244.  screensize
  245.  count the amount of screenmemory.
  246.  (There must be a swi for it, but I don't know it)
  247. *ScrMax%=0:CH%=&2000:AD%=&2000000-CH%:
  248. "OS_ValidateAddress",AD%,AD% 
  249.  ;C%:C%=C% 
  250. 2:AD%-=CH%
  251.  C%=0 
  252.  ScrMax%+=CH%
  253.  C%=2
  254.  Now takes as many banks as possible
  255. 6BankMax%=ScrMax%/ScrMem%:
  256.  BankMax%>3 
  257.  BankMax%=3
  258. bank%=1
  259.