SYNC ON:SYNC RATE 0:AUTOCAM OFF:HIDE MOUSE
`Set the random seed to make sure everything is truly random
RANDOMIZE TIMER()
DIM Clouds(300,3)
`Make 300 randomly sized, randomly positioned spheres
FOR x = 1 TO 300
MAKE OBJECT SPHERE x,RND(100)
POSITION OBJECT x, -400 + RND(800), -400 + RND(800), -400 + RND(800)
GHOST OBJECT ON x
`Here's where we store the cloud's movement angle. Basically the array Clouds() has 3 slots for each cloud,
`these 3 slots are used to store the cloud's xyz angle. This xyz angle is a value inbetween 0 and 360. This
`angle is the angle we'll move the clouds at.
Clouds(x,1) = RND(360)
Clouds(x,2) = RND(360)
Clouds(x,3) = RND(360)
NEXT x
`vector method variable
`maxDist# = 500
`non-vector method variables
xRange# = 500
yRange# = 500
zRange# = 500
`setup math (only for vector method)
`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
`Use a loop going from 1 to 300, checking each cloud object.
FOR x = 1 TO 300
`Store the clouds starting angle
xA# = OBJECT ANGLE X(x)
yA# = OBJECT ANGLE Y(x)
zA# = OBJECT ANGLE Z(x)
`Rotate the cloud to it's movement angle previously calculated
ROTATE OBJECT x,Clouds(x,1),Clouds(x,2),Clouds(x,3)
`Move the cloud a bit
MOVE OBJECT x,0.5
`Non vector method
x# = OBJECT POSITION X(x)
y# = OBJECT POSITION Y(x)
z# = OBJECT POSITION Z(x)
IF ABS(x#) > xRange#
MOVE OBJECT x,-xRange#*2
ENDIF
IF ABS(y#) > yRange#
MOVE OBJECT x,-yRange#*2
ENDIF
IF ABS(z#) > zRange#
MOVE OBJECT x,-zRange#*2
ENDIF
`Vector method
REMSTART
dist# = math_getDist3D(x#,0,y#,0,z#,0)
IF dist# > maxDist#
MOVE OBJECT x,-maxDist#
ENDIF
REMEND
`Rotate the cloud back to it's original angle
ROTATE OBJECT x,xA#,yA#,zA#
`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#