November 25, 2020, 04:42:29 AM

Author Topic: [bb] Stereoscopic Camera by Dabbede [ 1+ years ago ]  (Read 581 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Stereoscopic Camera by Dabbede [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
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 :
Code: BlitzBasic
  1. Global Screen_Width=800        
  2. Global Screen_Height=600
  3. Global StereoTex_Width=256              ;The width of the StereoImage
  4. Global StereoTex_Height=256             ;The height of the StereoImage
  5.  
  6. Type StereoCamera
  7.         Field Cam,Dx,Sx,ViewDx,ViewSx,PlaneDx,PlaneSx
  8. End Type
  9.  
  10.  
  11. ;--Main----------------------------------------------------------------------------------------------
  12. Graphics3D Screen_Width,Screen_Height
  13. SetBuffer BackBuffer()
  14.  
  15. camera.StereoCamera=CreateStereoCamera()
  16.  
  17. box=CreateCube()
  18.         FitMesh box,-1,-1.1,.5,2,2.2,1
  19.         MoveEntity box,2,2,10
  20.         If FileType("Bart.bmp")<>1 Then RuntimeError "Missing file 'Bart.bmp'"
  21.         tex=LoadTexture("Bart.bmp") ;Any texture you want
  22.         EntityTexture box,tex
  23.        
  24. While Not KeyHit(1)
  25.  
  26.         If MouseDown(1) MoveEntity cameracam,0,0,.1
  27.         If MouseDown(2) MoveEntity cameracam,0,0,-.1
  28.        
  29.         x#=MouseXSpeed()
  30.         y#=MouseYSpeed()
  31.         MoveMouse Screen_Width/2,Screen_Height/2
  32.         TurnEntity cameracam,y,-x,0
  33.         RotateEntity cameracam,EntityPitch(cameracam),EntityYaw(cameracam),0
  34.        
  35.         ShowEntity box ;Remember to show all the objects of your world
  36.         TakeStereoWorld()
  37.        
  38.         HideEntity box ;And now remember to hide all the objects of your world :)
  39.         RenderStereoWorld()
  40.        
  41.         Flip
  42. Wend
  43. End
  44.  
  45.  
  46.  
  47. ;--Functions-----------------------------------------------------------------------------------------
  48. Function CreateStereoCamera.StereoCamera()
  49.         a.StereoCamera=New StereoCamera
  50.        
  51.         acam=CreateCamera()
  52.                 ScaleEntity acam,.1,.1,.1
  53.         adx=CreateCamera(acam)
  54.                 MoveEntity adx,+.3,0,0
  55.                 CameraViewport adx,0,0,StereoTex_Width,StereoTex_Height
  56.         asx=CreateCamera(acam)
  57.                 MoveEntity asx,-.3,0,0
  58.                 CameraViewport asx,0,0,StereoTex_Width,StereoTex_Height
  59.                
  60.         aviewdx=CreateTexture(StereoTex_Width,StereoTex_Height)
  61.         aviewsx=CreateTexture(StereoTex_Width,StereoTex_Height)
  62.        
  63.         aplanedx=CreateSprite(acam)
  64.                 SpriteViewMode aplanedx,1
  65.                 ScaleSprite aplanedx,1,.75
  66.                 MoveEntity aplanedx,0,0,1.001
  67.                 EntityOrder aplanedx,-1000
  68.                 EntityBlend aplanedx,3
  69.                 EntityTexture aplanedx,aviewdx
  70.                 HideEntity aplanedx
  71.         aplanesx=CreateSprite(acam)
  72.                 SpriteViewMode aplanesx,1
  73.                 ScaleSprite aplanesx,1,.75
  74.                 MoveEntity aplanesx,0,0,1.001
  75.                 EntityOrder aplanesx,-1000
  76.                 EntityBlend aplanesx,3
  77.                 EntityTexture aplanesx,aviewsx
  78.                 HideEntity aplanesx
  79.  
  80.         Return a
  81. End Function
  82.  
  83. Function TakeStereoWorld()     
  84.         For a.StereoCamera=Each StereoCamera
  85.                 ;--Dx--------------------
  86.                 CameraProjMode aDx,1
  87.                 CameraProjMode aSx,0
  88.                 CameraProjMode acam,0
  89.                 AmbientLight 255,0,0
  90.                 RenderWorld
  91.                 CopyRect 0,0,StereoTex_Width,StereoTex_Height,0,0,BackBuffer(),TextureBuffer(aviewdx)
  92.                 ;--Sx--------------------
  93.                 CameraProjMode aDx,0
  94.                 CameraProjMode aSx,1
  95.                 CameraProjMode acam,0
  96.                 AmbientLight 0,255,255
  97.                 RenderWorld
  98.                 CopyRect 0,0,StereoTex_Width,StereoTex_Height,0,0,BackBuffer(),TextureBuffer(aviewsx)  
  99.         Next
  100. End Function
  101.  
  102. Function RenderStereoWorld()
  103.         For a.StereoCamera=Each StereoCamera
  104.                 ShowEntity aplanedx
  105.                 ShowEntity aplanesx
  106.                
  107.                 CameraProjMode aDx,0
  108.                 CameraProjMode aSx,0
  109.                 CameraProjMode acam,1
  110.                
  111.                 RenderWorld
  112.                
  113.                 HideEntity aplanedx
  114.                 HideEntity aplanesx
  115.         Next
  116. 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.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal