OSGOrthographicCamera.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 <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047 #include "OSGMatrixUtility.h"
00048
00049 #include "OSGOrthographicCamera.h"
00050
00051 OSG_USING_NAMESPACE
00052
00053 /***************************************************************************\
00054  *                            Description                                  *
00055 \***************************************************************************/
00056
00061 /***************************************************************************\
00062  *                           Class variables                               *
00063 \***************************************************************************/
00064
00065 /***************************************************************************\
00066  *                           Class methods                                 *
00067 \***************************************************************************/
00068
00069 void OrthographicCamera::initMethod(InitPhase ePhase)
00070 {
00071     Inherited::initMethod(ePhase);
00072 }
00073
00074
00075 /***************************************************************************\
00076  *                           Instance methods                              *
00077 \***************************************************************************/
00078
00079 /*-------------------------------------------------------------------------*\
00080  -  private                                                                 -
00081 \*-------------------------------------------------------------------------*/
00082
00083 /*----------------------- constructors & destructors ----------------------*/
00084
00085 OrthographicCamera::OrthographicCamera(void) :
00086     Inherited()
00087 {
00088 }
00089
00090 OrthographicCamera::OrthographicCamera(const OrthographicCamera &source) :
00091     Inherited(source)
00092 {
00093 }
00094
00095 OrthographicCamera::~OrthographicCamera(void)
00096 {
00097 }
00098
00099 /*----------------------------- class specific ----------------------------*/
00100
00101 void OrthographicCamera::changed(ConstFieldMaskArg whichField,
00102                                  UInt32            origin,
00103                                  BitVector         details)
00104 {
00105     Inherited::changed(whichField, origin, details);
00106 }
00107
00108 /*-------------------------- your_category---------------------------------*/
00109
00110 void OrthographicCamera::getProjection(Matrixr &result,
00111                                        UInt32   width,
00112                                        UInt32   height)
00113 {
00114     Real32 vs = getVerticalSize  () / 2;
00115     Real32 hs = getHorizontalSize() / 2;
00116
00117     // catch some illegal cases
00118     if(((vs <= 0) && (hs <= 0)) || width == 0 || height == 0)
00119     {
00120         result.setIdentity();
00121         return;
00122     }
00123
00124     Real32 winAspect = width / Real32(height) * getAspect();
00125     if (vs <= 0)
00126     {
00127         vs = hs / winAspect;
00128     }
00129     else if (hs <= 0)
00130     {
00131         hs = vs * winAspect;
00132     }
00133     else
00134     {
00135         Real32 camAspect = hs / vs;
00136
00137         if (winAspect < camAspect)
00138         {
00139             vs = hs / winAspect;
00140         }
00141         else
00142         {
00143             hs = vs * winAspect;
00144         }
00145     }
00146
00147     MatrixOrthogonal(result, -hs, hs,
00148                              -vs, vs,
00149                              getNear(), getFar());
00150 }
00151
00152
00153 void OrthographicCamera::dump(      UInt32    ,
00154                          const BitVector ) const
00155 {
00156     SLOG << "Dump OrthographicCamera NI" << std::endl;
00157 }
00158
00159