Code archives/3D Graphics - Effects/3d Glass - Red Blue

This code has been declared by its author to be Public Domain code.

Download source code

3d Glass - Red Blue by perseus2005
the source of having 3d solution using red blue filtering
; Red Blue 3d Glasses
; 2005 Burcak Duruoz

Global red,blue,redt,bluet,black
Dim cb(8),tt(8)

Graphics3D 800,600,32,2
SetBuffer BackBuffer()
AmbientLight 0,0,0

global cam=CreateCamera()
PositionEntity cam,0,2,-12
RotateEntity cam,2,0,0

light=CreateLight(2)
PositionEntity light,10,10,-20
LightColor light,2,2,2

spht=CreateTexture(256,256)
SetBuffer TextureBuffer(spht)
For ttx=0 To 255 Step 8
    For tty=0 To 255 Step 16
        Color 255,255,255
        Rect ttx,tty,3,3
    Next
Next
SetBuffer BackBuffer()

sph=CreateSphere()
ScaleEntity sph,15,15,15
FlipMesh sph
EntityFX sph,1
EntityTexture sph,spht

sph2=CreateSphere()
ScaleEntity sph2,5.2,5.2,5.2
EntityAlpha sph2,.5
EntityFX sph2,1+16
EntityTexture sph2,spht

obj=CreateCylinder()
ScaleEntity obj,0.4,8,0.4
Entityblend obj,3

ff=CreatePivot()

For cc=1 To 8
    tt(cc)=CreatePivot(ff)
    cb(cc)=CreateCube(tt(cc))
    EntityColor cb(cc),Rnd(100,255),Rnd(0,255),Rnd(50,255)
    PositionEntity cb(cc),0,0,-6
    RotateEntity tt(cc),0,45*cc,0
Next

map=256

redt=createtexture(map,map)
bluet=createtexture(map,map)

initglass()

While not keydown(1)
    time#=time#+2
    tx#=(Sin(time*2)*0.5)+0.7
    ty#=Cos(time/2)*3
    For xx=1 to 8
        ScaleEntity cb(xx),tx,tx,tx
        TurnEntity cb(xx),ty,ty,ty
    Next
    If KeyHit(57) Then waitkey:WaitKey
    TurnEntity obj,1,1,1
    TurnEntity ff,0,1,0
    TurnEntity sph,tx/5,ty/5,0.1
    TurnEntity sph2,-tx/5,-ty/5,-0.1
    stereo(map,redt,bluet)
    UpdateWorld
    RenderWorld
    Flip
Wend

End

Function initglass()
    black=makequad()
    EntityAlpha black,1
    PositionEntity black,0,0,1.01

    red=makequad()
    EntityColor red,255,0,0
    EntityFX red,1
    EntityBlend red,3
    PositionEntity red,0,0,1
    TextureBlend redt,5
    EntityTexture red,redt

    blue=makequad()
    EntityColor blue,0,255,255
    EntityFX blue,1
    EntityBlend blue,3
    PositionEntity blue,0,0,1
    TextureBlend bluet,5
    EntityTexture blue,bluet
End Function

Function makequad()
    meshquad = CreateMesh(cam)
	srf      = CreateSurface(meshquad)

	AddVertex   srf, -1, 1, 0, 0, 0
	AddVertex   srf,  1, 1, 0, 1, 0
	AddVertex   srf, -1,-1, 0, 0, 1
	AddVertex   srf,  1,-1, 0, 1, 1
		
   	AddTriangle srf, 0, 1, 2
	AddTriangle srf, 3, 2, 1
	return meshquad
End Function

Function stereo(map,rtext,btext)
    HideEntity red
    HideEntity blue
    HideEntity black
	CameraViewport Cam, 0, 0, map, map
    ;red
    MoveEntity cam,-.1,0,0
    RenderWorld
    CopyRect 0,0,map,map,0,0,BackBuffer(),TextureBuffer(rtext)
    ;blue
    MoveEntity cam,.2,0,0
    RenderWorld
    CopyRect 0,0,map,map,0,0,BackBuffer(),TextureBuffer(btext)
	CameraViewport Cam,0,0,GraphicsWidth(),GraphicsHeight()
    MoveEntity cam,-.1,0,0
    ShowEntity red
    ShowEntity blue
    ShowEntity black
End Function

Comments

Neochrome2005
Hey that works!!
this is awsome!!!


Neochrome2005
[please delete]


RifRaf2005
hm.. now where can i get some 3dglasses :)


perseus2005
http://www.blitzbasic.com/Community/posts.php?topic=49020

[quote]
you can find the 3d glasses from this addresses

froogle.google.com/froogle?q=buy+3d+glasses&hl=en&lr=&rls=GGLD,GGLD:2005-26,GGLD:en&sa=N&tab=ff&oi=froogler
www.rainbowsymphony.com/
www.rainbowsymphony.com/nano3d.html
[quote]


Trader35642007
cool! now i can make 3D games come to life :)


Trader35642007
b.t.w. is this made for red-cyan or red-blue ??
cause im gonne order a glasses :) its just $1 each.
Would be funny to sell with your game.


Trader35642007
w00t!! today i received my 3D glass :) its awesome dude!
reallly in one word awesome! im sitting here having blocks spin around my head.


Trader35642007
after looking more closely to the code i noticed that there is no depth in the red/cyan filter. Closer objects should by wider, placed i beleive.. or narrower. Anyways, i do not see how this can be achived other than trough the use of 3 camera's.
- 1 for red
- 2 for center view
- 3 for cyan
Camera 1 and 3 should be rotated slightly to center on cam 2 as cam 1 and 3 are moved a few units to the side.


perseus2007
Hi LeeMing;

Sorry for the delayed reply cause I’m kind of busy these days. The mentality of the 3D glasses comes from the different views of each eye! That is why it doesn’t really matters red/cyan, red/blue or red/green.

In Film technologies, 3D film makers improved the techniques of shooting film. These are the cameras which they can shoot from 2 different angles and 3 different angles, just like you think! (Polarized Glasses are completely a different story)

Generally, we use 2 camera systems or 3 camera systems. If the goal is performance and the polygon count, using 2 camera systems would be much appropriate than using 3 camera systems. If the goal isn’t performance, the colors would be much better with the 3 camera system. Actually both systems work with the same principles and each system have 2 alternative usages. Human eye focuses on one thing. That’s why our eyes make angles thru inside. These angles can be measured by very small amounts. We can make these calculations by focus distance and the measures between to eyes. If we exclude the focus distance, we can produce wrong 3D scenes. But if we include these calculations thru our process, we can have no troubles with small objects’ performance but when the objects get bigger, than we will have more lack of performance. That’s why we don’t include the 0.1 degrees of angle and we pretend our eyes are parallel. Our solution will not be relied on focus distance so a person will be seeing correct phenomenon. It will also improve the performance.

If you want performance, you should use simple methods.

P.S: I also looked your example. With my glasses, the cube at the front cannot be properly filtered. If you decrease the colors, you can get much correct solution.

Take Care!


Code Archives Forum