Aerial Antics Reboost VR

Miscellaneous Forums/Blitz Showcase/Aerial Antics Reboost VR

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Great stuff. Takes me back to the days of going boggle-eyed with those stereo-scopic images. Something similar to:
Rem
	Stereo 3D Image (BlitzMax)
	==========================

	Jim Brown

	When this program is run you'll see two scenes which look
	identical but the moving objects on the Right are offset
	according to how deep in the Z field they are.

	If you stare through the screen and try to get the two RED focal
	points (at the top of each view) to merge you will end up with
	a third view which is the left and right views combined.
	When you get the third view you'll see that the objects have
	a depth to them. The brighter/bigger ones appear closer.

	TIP:
	If you have difficuly getting the images to merge then try staring
	beyond the screen to an imaginary distance. At the same time you want
	the RED focal points to meet up in the middle and converge.
	It can take a long time to master but the end result is great!
EndRem

Const MAXOBJECTS%=80						' maximum objects on screen
Const MAXDEPTH%=12						' levels of depth (1=back of screen)
Const ScreenW%=1024 , ScreenH%=768		' screen size
Const ViewW%=240 , ViewH=ScreenH%-20 	' view width & height for the images
Const loffs%=(ScreenW/2)-ViewW-10		' left image x offest
Const roffs%=ScreenW/2+10				' right image x offset
Const toffs%=(ScreenH-ViewH)/2			' images top offset


Type objType
	Global list:TList=New TList
	Field x#,y#,z% , xdir#
	'
	Method New()
		list.AddLast Self
	End Method
	' new position for object
	Method NewPos()
		x=Rnd(10.0,ViewW-10.0)
		y=-Rnd(20.0,30.0)
		z=Rand(1,MAXDEPTH)
		xdir=Rnd(-0.5,0.5)
	End Method
	' update all objects positions
	Function Update()
		For Local o:objType = EachIn objType.list
			If Rnd(50)>35.0 o.xdir:+Rnd(0.1)-Rnd(0.1)
			o.x:+o.xdir/1.5
			If o.x<-20.0 Or o.x>=ViewW+10 o.NewPos
			o.y=o.y+Float(o.z+10)/10.0
			If o.y>ViewH o.NewPos
		Next
	End Function
	' render the objects (depth-sorted.  1=furthest to back of screen)
	Function Draw()
		Const brightness#=255.0/Float(MAXDEPTH)
		Const size#=28.0/Float(MAXDEPTH)
		For Local d%=1 To MAXDEPTH
			Local osize#=d*size 	' objects size
			SetColor d*brightness,d*brightness,d*brightness ' color of object
			For Local o:objType = EachIn objType.list
				If o.z=d
					SetViewport loffs,toffs,viewW,viewH
					DrawOval loffs+o.x,toffs+o.y,osize,osize ' x is normal for left view
					SetViewport roffs,toffs,viewW,viewH
					DrawOval roffs+o.x+(MAXDEPTH-d),toffs+o.y,osize,osize ' x is offset for right view
					SetViewport 0,0,ScreenW,ScreenH
				EndIf
			Next
		Next
	End Function
End Type


' create the objects
For Local d%=1 To MAXOBJECTS
	Local o:objType=New objType
	o.NewPos
	o.y=Rnd(1.0,ViewH)
	num:+1
Next


Graphics ScreenW,ScreenH,32,50


' main loop
While Not KeyDown(KEY_ESCAPE)
	Cls
	' draw the background
	SetColor 50,70,92
	DrawRect loffs,toffs,ViewW,ViewH
	DrawRect roffs,toffs,ViewW,ViewH
	' draw the RED focal points
	SetColor 200,60,60
	DrawOval loffs+(ViewW/2),toffs+8,8,6
	DrawOval roffs+(ViewW/2),toffs+8,8,6
	' process each object
	objType.Update
	' draw each object on screen (low to high order)
	objType.Draw
	'
	SetColor 100,95,25
	DrawText "SPACEBAR = pause",20,ScreenH-90
	DrawText "Objects = "+String(MAXOBJECTS),20,30
	Flip
	While KeyDown(KEY_SPACE) ; Delay 1 ; Wend
Wend

End