Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef StereoCamera_INCLUDE_ONCE
00033 #define StereoCamera_INCLUDE_ONCE
00034
00035 #include <vlGraphics/Camera.hpp>
00036
00037 namespace vl
00038 {
00047 class StereoCamera: public Object
00048 {
00049 VL_INSTRUMENT_CLASS(vl::StereoCamera, Object)
00050
00051 public:
00052 StereoCamera()
00053 {
00054 mConvergence = 20;
00055 mEyeSeparation = 1;
00056 }
00057
00060 void setConvergence( float convergence ) { mConvergence = convergence; }
00063 float convergence() const { return mConvergence; }
00064
00066 void setEyeSeparation( float eye_separation ) { mEyeSeparation = eye_separation; }
00068 float eyeSeparation() const { return mEyeSeparation; }
00069
00072 void setMonoCamera(Camera* camera) { mMonoCamera = camera; }
00075 Camera* monoCamera() { return mMonoCamera.get(); }
00078 const Camera* monoCamera() const { return mMonoCamera.get(); }
00079
00081 void setLeftCamera(Camera* camera) { mLeftCamera = camera; }
00083 Camera* leftCamera() { return mLeftCamera.get(); }
00085 const Camera* leftCamera() const { return mLeftCamera.get(); }
00086
00088 void setRightCamera(Camera* camera) { mRightCamera = camera; }
00090 Camera* rigthCamera() { return mRightCamera.get(); }
00092 const Camera* rightCamera() const { return mRightCamera.get(); }
00093
00095 void updateLeftRightCameras()
00096 {
00097 mLeftCamera->setViewport( mMonoCamera->viewport() );
00098 mRightCamera->setViewport( mMonoCamera->viewport() );
00099
00100 float aspect_ratio = (float)mMonoCamera->viewport()->width()/mMonoCamera->viewport()->height();
00101 float near_clip = mMonoCamera->nearPlane();
00102 float far_clip = mMonoCamera->farPlane();
00103 float radians = mMonoCamera->fov()/2*fDEG_TO_RAD;
00104 float wd2 = near_clip * tan(radians);
00105 float ndfl = near_clip / mConvergence;
00106 float top, bottom, left, right;
00107 top = wd2;
00108 bottom = - wd2;
00109
00110 left = - aspect_ratio * wd2 - mEyeSeparation/2 * ndfl;
00111 right = aspect_ratio * wd2 - mEyeSeparation/2 * ndfl;
00112 mLeftCamera->setProjectionFrustum(left, right, bottom, top, near_clip, far_clip);
00113 mLeftCamera->setViewMatrix( mat4::getTranslation(-mEyeSeparation/2, 0, 0)*mMonoCamera->viewMatrix() );
00114
00115 left = - aspect_ratio * wd2 + mEyeSeparation/2 * ndfl;
00116 right = aspect_ratio * wd2 + mEyeSeparation/2 * ndfl;
00117 mRightCamera->setProjectionFrustum(left, right, bottom, top, near_clip, far_clip);
00118 mRightCamera->setViewMatrix( mat4::getTranslation(+mEyeSeparation/2, 0, 0)*mMonoCamera->viewMatrix() );
00119 }
00120
00121 private:
00122 ref<Camera> mMonoCamera;
00123 ref<Camera> mLeftCamera;
00124 ref<Camera> mRightCamera;
00125 float mConvergence;
00126 float mEyeSeparation;
00127 };
00128 }
00129
00130 #endif