Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://visualizationlibrary.org */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 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