' ---- WIREFRAME 3D MONITOR DEMO ----


' -- INITIALIZE WIREFRAME 3D MONITOR DEMO --

SUB INIT_DEMO_3D_MONITOR

 'LOAD 3D MONITOR
 LOADPLY("MONITOR_OPT.PLY",0)
 PLY_ADJUST_COLOR(0,50)
 PLY_RGB(0,0,5,0)

 'ADJUST POLYGON POSITION
 PLY_MOVE(0,0,0,1)
 PLY_ROT(0,163,90,0,1)

END SUB


' -- RUN 3D MONITOR DEMO --

SUB RUN_DEMO_3D_MONITOR

 LOCAL X,Y,XX,YY,T,I,DIST,SEC,SPD

 'SET INITIAL DISTANCE, SPEED AND COORDINATES
 DIST=0: SPD=0.05
 X=MAXX/2-10: Y=MAXY/2: XX=0

 'SET BUFFER PAGE
 PAGE WRITE 1
 
 'RESET TIMER
 PAUSETIMER=0:TIMENOW=0:Timer=0

 'RUN DEMO UNTIL 3.5 SECONDS
 DO WHILE SEC<3.5

  'CLEAR BUFFER PAGE
  BOX 0,0,MAXX,MAXY,0,,RGB(0,0,0)

  'SET DISTANCE
  DIST=DIST+SPD

  'FORCE 10 FPS TO KEEP A STABLE ANIMATION
  FPS(10)
  SEC=Timer/1000

  'ROTATE MONITOR
  XX=XX+40
  T=5-SPD*5
  'ROTATE UNTIL 810 DEGREE
  IF XX>810 THEN
   XX=810: SPD=SPD+0.1
   'CHANGE COLOR WITH THE DISTANCE
   T=5-SPD*5
   IF T<0 THEN T=0
   PLY_RGB(0,0,T,0)
  ENDIF
  'RENDER MONITOR UNTIL REACH MAXIMUM ZOOM
  IF T>0 THEN
   PLY_MOVE(0,X,Y+DIST*50,DIST)
   PLY_ROT(0,XX,0,1)
  ENDIF
 
  'COPY TO MAIN PAGE
  PAGE COPY 1 TO 0,I

 LOOP

END SUB

