OSGTileCameraDecorator.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 "OSGTileCameraDecorator.h"
00049
00050 OSG_USING_NAMESPACE
00051
00052 // Documentation for this class is emited in the
00053 // OSGTileCameraDecoratorBase.cpp file.
00054 // To modify it, please change the .fcd file (OSGTileCameraDecorator.fcd) and
00055 // regenerate the base file.
00056
00057 /***************************************************************************\
00058  *                           Class methods                                 *
00059 \***************************************************************************/
00060
00061 void TileCameraDecorator::initMethod(InitPhase ePhase)
00062 {
00063     Inherited::initMethod(ePhase);
00064 }
00065
00066 /***************************************************************************\
00067  *                           Instance methods                              *
00068 \***************************************************************************/
00069
00070 /*------------- constructors & destructors --------------------------------*/
00071
00072 TileCameraDecorator::TileCameraDecorator(void) :
00073     Inherited()
00074 {
00075 }
00076
00077 TileCameraDecorator::TileCameraDecorator(const TileCameraDecorator &source) :
00078     Inherited(source)
00079 {
00080 }
00081
00082 TileCameraDecorator::~TileCameraDecorator(void)
00083 {
00084 }
00085
00086 void TileCameraDecorator::changed(ConstFieldMaskArg whichField,
00087                                   UInt32            origin,
00088                                   BitVector         details)
00089 {
00090     Inherited::changed(whichField, origin, details);
00091 }
00092
00098 void TileCameraDecorator::setSize(Real32 left,
00099                                   Real32 bottom,
00100                                   Real32 right,
00101                                   Real32 top   )
00102 {
00103     setLeft  (left  );
00104     setRight (right );
00105     setBottom(bottom);
00106     setTop   (top   );
00107 }
00108
00109 void TileCameraDecorator::getProjection(Matrix &result,
00110                                         UInt32  width,
00111                                         UInt32  height)
00112 {
00113     if(width == 0 || height == 0)
00114     {
00115         result.setIdentity();
00116         return;
00117     }
00118
00119     Camera *camera = getDecoratee();
00120
00121     if(camera == NULL)
00122     {
00123         FWARNING(("TileCameraDecorator::getProjection: no decoratee!\n"));
00124
00125         result.setIdentity();
00126
00127         return;
00128     }
00129
00130     if(getFullWidth() != 0)
00131         width = getFullWidth();
00132
00133     if(getFullHeight() != 0)
00134         height = getFullHeight();
00135
00136     camera->getProjection(result, width, height);
00137
00138     Real32 left   = getLeft  ();
00139     Real32 right  = getRight ();
00140     Real32 top    = getTop   ();
00141     Real32 bottom = getBottom();
00142
00143     if(left < 0)
00144         left = -left / width;
00145
00146     if(right < 0)
00147         right = -right / width;
00148
00149     if(top < 0)
00150         top = -top / height;
00151
00152     if(bottom < 0)
00153         bottom = -bottom / height;
00154
00155     // scale the wanted part from the projection matrix
00156     Real32 xs = 1.f / (right - left  );
00157     Real32 ys = 1.f / (top   - bottom);
00158
00159     Matrix sm(xs,  0, 0, -(left*2-1)*xs-1,
00160                0, ys, 0, -(bottom*2-1)*ys-1,
00161                0,  0, 1, 0,
00162                0,  0, 0, 1);
00163
00164     result.multLeft(sm);
00165 }
00166
00171 void TileCameraDecorator::getDecoration(Matrix &result,
00172                                         UInt32  width,
00173                                         UInt32  height)
00174 {
00175     if(width == 0 || height == 0)
00176     {
00177         result.setIdentity();
00178         return;
00179     }
00180
00181     Camera *camera = getDecoratee();
00182
00183     if(camera == NULL)
00184     {
00185         FWARNING(("TileCameraDecorator::getDecoration: no decoratee!\n"));
00186
00187         result.setIdentity();
00188
00189         return;
00190     }
00191
00192     if(getFullWidth() != 0)
00193         width = getFullWidth();
00194
00195     if(getFullHeight() != 0)
00196         height = getFullHeight();
00197
00198     // this is the only difference to getProjection()
00199     camera->getDecoration(result, width, height);
00200
00201     Real32 left   = getLeft  ();
00202     Real32 right  = getRight ();
00203     Real32 top    = getTop   ();
00204     Real32 bottom = getBottom();
00205
00206     if(left < 0)
00207         left = -left / width;
00208
00209     if(right < 0)
00210         right = -right / width;
00211
00212     if(top < 0)
00213         top = -top / height;
00214
00215     if(bottom < 0)
00216         bottom = -bottom / height;
00217
00218     // scale the wanted part from the decoration matrix
00219     Real32 xs = 1.f / (right - left);
00220     Real32 ys = 1.f / (top - bottom);
00221
00222     Matrix sm(  xs,  0, 0, -(left   * 2 - 1) * xs - 1,
00223                  0, ys, 0, -(bottom * 2 - 1) * ys - 1,
00224                  0,  0, 1, 0,
00225                  0,  0, 0, 1);
00226
00227     result.multLeft(sm);
00228 }
00229
00230 /*------------------------------- dump ----------------------------------*/
00231
00232 void TileCameraDecorator::dump(      UInt32    OSG_CHECK_ARG(uiIndent),
00233                                const BitVector OSG_CHECK_ARG(bvFlags )) const
00234 {
00235     SLOG << "Dump TileCameraDecorator NI" << std::endl;
00236 }
00237
00238 Vec2u TileCameraDecorator::tileGetFullSize(void) const
00239 {
00240     return Vec2u(_sfFullWidth.getValue(), _sfFullHeight.getValue());
00241 }
00242
00243 Vec4f TileCameraDecorator::tileGetRegion(void) const
00244 {
00245     return Vec4f(_sfLeft  .getValue(),
00246                  _sfRight .getValue(),
00247                  _sfBottom.getValue(),
00248                  _sfTop   .getValue());
00249 }
00250