OSGShearedStereoCameraDecorator.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042
00043 #include <cstdlib>
00044 #include <cstdio>
00045
00046 #include "OSGConfig.h"
00047
00048 #include "OSGMatrixUtility.h"
00049
00050 #include "OSGPerspectiveCamera.h"
00051 #include "OSGShearedStereoCameraDecorator.h"
00052
00053 OSG_USING_NAMESPACE
00054
00055 // Documentation for this class is emited in the
00056 // OSGShearedStereoCameraDecoratorBase.cpp file.
00057 // To modify it, please change the .fcd file (OSGShearedStereoCameraDecorator.fcd) and
00058 // regenerate the base file.
00059
00060 /*----------------------- constructors & destructors ----------------------*/
00061
00062 ShearedStereoCameraDecorator::ShearedStereoCameraDecorator(void) :
00063     Inherited()
00064 {
00065 }
00066
00067 ShearedStereoCameraDecorator::ShearedStereoCameraDecorator(
00068     const ShearedStereoCameraDecorator &source) :
00069
00070     Inherited(source)
00071 {
00072 }
00073
00074 ShearedStereoCameraDecorator::~ShearedStereoCameraDecorator(void)
00075 {
00076 }
00077
00078 /*----------------------------- class specific ----------------------------*/
00079
00080 void ShearedStereoCameraDecorator::initMethod(InitPhase ePhase)
00081 {
00082     Inherited::initMethod(ePhase);
00083 }
00084
00085 void ShearedStereoCameraDecorator::changed(ConstFieldMaskArg whichField,
00086                                            UInt32            origin,
00087                                            BitVector         details)
00088 {
00089     Inherited::changed(whichField, origin, details);
00090 }
00091
00092 void ShearedStereoCameraDecorator::dump(      UInt32    ,
00093                                         const BitVector ) const
00094 {
00095     SLOG << "Dump ShearedStereoCameraDecorator NI" << std::endl;
00096 }
00097
00098
00102 void ShearedStereoCameraDecorator::getProjection(Matrix &result,
00103                                                  UInt32  width,
00104                                                  UInt32  height)
00105 {
00106     if(width == 0 || height == 0)
00107     {
00108         result.setIdentity();
00109         return;
00110     }
00111
00112     PerspectiveCamera *cam =
00113         dynamic_cast<PerspectiveCamera *>(getDecoratee());
00114
00115     if(cam == NULL)
00116     {
00117         FFATAL(("ShearedStereoCameraDecorator::getProjection: can only"
00118                 " decorate PerspectiveCameras!\n"));
00119
00120         result.setIdentity();
00121         return;
00122     }
00123
00124     Matrix trans;
00125     MatrixStereoPerspective(result, trans, cam->getFov(),
00126                             width / Real32(height) * cam->getAspect(),
00127                             cam->getNear(),
00128                             cam->getFar(),
00129                             getZeroParallaxDistance(),
00130                             getEyeSeparation(),
00131                             getLeftEye() ? 0.f : 1.f,
00132                             getOverlap());
00133
00134     result.mult(trans);
00135 }
00136
00137 void ShearedStereoCameraDecorator::getDecoration(Matrix &result,
00138                                                  UInt32  width,
00139                                                  UInt32  height)
00140 {
00141     if(width == 0 || height == 0)
00142     {
00143         result.setIdentity();
00144         return;
00145     }
00146
00147     Camera *camera = getDecoratee();
00148
00149     if(camera == NULL)
00150     {
00151         FWARNING(("TileCameraDecorator::getProjection: no decoratee!\n"));
00152
00153         result.setIdentity();
00154
00155         return;
00156     }
00157
00158     camera->getDecoration(result, width, height);
00159 }