Title : Stereoscopic Camera
Author : Dabbede
Posted : 1+ years ago
Description : This IS the code for a stereoscopic 3d camera!
Probably you will have to set the offset of the 2 cameras in lines 6 and 9 of "CreateStereoCamera" function...
dabbede2000@...
Code :
Global Screen_Width=800
Global Screen_Height=600
Global StereoTex_Width=256 ;The width of the StereoImage
Global StereoTex_Height=256 ;The height of the StereoImage
Type StereoCamera
Field Cam,Dx,Sx,ViewDx,ViewSx,PlaneDx,PlaneSx
End Type
;--Main----------------------------------------------------------------------------------------------
Graphics3D Screen_Width,Screen_Height
SetBuffer BackBuffer()
camera.StereoCamera=CreateStereoCamera()
box=CreateCube()
FitMesh box,-1,-1.1,.5,2,2.2,1
MoveEntity box,2,2,10
If FileType("Bart.bmp")<>1 Then RuntimeError "Missing file 'Bart.bmp'"
tex=LoadTexture("Bart.bmp") ;Any texture you want
EntityTexture box,tex
While Not KeyHit(1)
If MouseDown(1) MoveEntity cameracam,0,0,.1
If MouseDown(2) MoveEntity cameracam,0,0,-.1
x#=MouseXSpeed()
y#=MouseYSpeed()
MoveMouse Screen_Width/2,Screen_Height/2
TurnEntity cameracam,y,-x,0
RotateEntity cameracam,EntityPitch(cameracam),EntityYaw(cameracam),0
ShowEntity box ;Remember to show all the objects of your world
TakeStereoWorld()
HideEntity box ;And now remember to hide all the objects of your world :)
RenderStereoWorld()
Flip
Wend
End
;--Functions-----------------------------------------------------------------------------------------
Function CreateStereoCamera.StereoCamera()
a.StereoCamera=New StereoCamera
acam=CreateCamera()
ScaleEntity acam,.1,.1,.1
adx=CreateCamera(acam)
MoveEntity adx,+.3,0,0
CameraViewport adx,0,0,StereoTex_Width,StereoTex_Height
asx=CreateCamera(acam)
MoveEntity asx,-.3,0,0
CameraViewport asx,0,0,StereoTex_Width,StereoTex_Height
aviewdx=CreateTexture(StereoTex_Width,StereoTex_Height)
aviewsx=CreateTexture(StereoTex_Width,StereoTex_Height)
aplanedx=CreateSprite(acam)
SpriteViewMode aplanedx,1
ScaleSprite aplanedx,1,.75
MoveEntity aplanedx,0,0,1.001
EntityOrder aplanedx,-1000
EntityBlend aplanedx,3
EntityTexture aplanedx,aviewdx
HideEntity aplanedx
aplanesx=CreateSprite(acam)
SpriteViewMode aplanesx,1
ScaleSprite aplanesx,1,.75
MoveEntity aplanesx,0,0,1.001
EntityOrder aplanesx,-1000
EntityBlend aplanesx,3
EntityTexture aplanesx,aviewsx
HideEntity aplanesx
Return a
End Function
Function TakeStereoWorld()
For a.StereoCamera=Each StereoCamera
;--Dx--------------------
CameraProjMode aDx,1
CameraProjMode aSx,0
CameraProjMode acam,0
AmbientLight 255,0,0
RenderWorld
CopyRect 0,0,StereoTex_Width,StereoTex_Height,0,0,BackBuffer(),TextureBuffer(aviewdx)
;--Sx--------------------
CameraProjMode aDx,0
CameraProjMode aSx,1
CameraProjMode acam,0
AmbientLight 0,255,255
RenderWorld
CopyRect 0,0,StereoTex_Width,StereoTex_Height,0,0,BackBuffer(),TextureBuffer(aviewsx)
Next
End Function
Function RenderStereoWorld()
For a.StereoCamera=Each StereoCamera
ShowEntity aplanedx
ShowEntity aplanesx
CameraProjMode aDx,0
CameraProjMode aSx,0
CameraProjMode acam,1
RenderWorld
HideEntity aplanedx
HideEntity aplanesx
Next
End Function
Comments :
Braneloc(Posted 1+ years ago)
Just in case you didn't know... if you have a NVIDIA card, you can download the 3D Glasses add-on, which works fine with Anaglyph Stereo (coloured glasses) on almost ANY 3D program or game you create/own...(Click consumer 3D stereo instead of graphics driver on the nvidia software download page)
kalimon(Posted 1+ years ago)
There are other forms of stereotopics :)but yes I have seen the info of what you say on edimensional.