All pastes #252471 Raw Edit

Anonymous

public text v1 · immutable
#252471 ·published 2006-11-19 16:20 UTC
rendered paste body
SYNC ON:SYNC RATE 0:AUTOCAM OFF:HIDE MOUSE

`Set the random seed to make sure everything is truly random
RANDOMIZE TIMER()

`Make 300 randomly sized, randomly coloured, randomly positioned boxes.
FOR x = 1 TO 300
   MAKE OBJECT BOX x, 10+RND(100),10+RND(100),10+RND(100)
   POSITION OBJECT x, -400 + RND(800), -400 + RND(800), -400 + RND(800)
   COLOR OBJECT x, RGB(RND(255),RND(255),RND(255))
NEXT x

`The range that objects begin ghosting.
range# = 100

`Setup our math system
math_setup()

`Main loop
DO

   MOVE CAMERA (UPKEY() - DOWNKEY())*0.5
   ROTATE CAMERA WRAPVALUE(CAMERA ANGLE X()+(MOUSEMOVEY()*0.1)), WRAPVALUE(CAMERA ANGLE Y()+(MOUSEMOVEX()*0.1)),0

   `Store the cam's position for use with the distance calculations.
   x1# = CAMERA POSITION X()
   y1# = CAMERA POSITION Y()
   z1# = CAMERA POSITION Z()

   FOR x = 1 TO 300
      `Calculate distance to each object
      x2# = OBJECT POSITION X(x)
      y2# = OBJECT POSITION Y(x)
      z2# = OBJECT POSITION Z(x)
      distance# = math_getDist3D(x1#,y1#,z1#,x2#,y2#,z2#)
      `If distance# is greater than range#, ghost the object.
      IF distance# > 1000
         GHOST OBJECT ON x
      ELSE
         GHOST OBJECT OFF x
      ENDIF
   `Repeat
   NEXT x

   `Display some info text
   TEXT 0,0,"FPS: "+STR$(SCREEN FPS())
   TEXT 0,15,"Move with the arrow keys."
   TEXT 0,30,"Turn with the mouse"

   `Refresh the screen
   SYNC

`Repeat
LOOP

`Call this before using the math function.
FUNCTION math_setup()
   `setup required vectors for distance calculations
   null = MAKE VECTOR3(1)
   null = MAKE VECTOR2(2)
   #CONSTANT vecDist3D = 1
   #CONSTANT vecDist2D = 2
ENDFUNCTION

`Math functin for getting 3D distance between 2 points.
FUNCTION math_getDist3D(X1#,Y1#,Z1#,X2#,Y2#,Z2#)
   SET VECTOR3 vecDist3D,X1#-X2#,Y1#-Y2#,Z1#-Z2#
   dist# = LENGTH VECTOR3(vecDist3D)
ENDFUNCTION dist#