OpenWalnut  1.4.0
WGECamera.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WGECAMERA_H
00026 #define WGECAMERA_H
00027 
00028 #include <osg/Camera>
00029 
00030 /**
00031  * Class for wrapping around the OSG Camera class. It adds some utility
00032  * functions for simply setting some camera defaults.
00033  * \ingroup ge
00034  */
00035 class WGECamera: public osg::Camera
00036 {
00037 public:
00038     /**
00039      * List of possible camera modes. The TWO_D modes use a standard two dimensional orthogonal projection. TWO_D_UNOT is somewhat special. It
00040      * creates a view-cube with an edge-length of 1, centered at 0 for X and Y. For Z, it is from 0 to 1. This relates to the standard glOrtho
00041      * command.
00042      */
00043     enum ProjectionMode
00044     {
00045         ORTHOGRAPHIC,
00046         PERSPECTIVE,
00047         TWO_D,  // two dimensional ortographic projection, dimension is viewport
00048         TWO_D_UNIT // like TWO_D but size is unit-cube with proper scaling and aspect ratio. This is useful for widgets where viewport size is
00049                    // unimportant.
00050     };
00051 
00052     /**
00053      * Constructor which sets defaults
00054      *
00055      * \param width width of the viewport.
00056      * \param height height of the viewport.
00057      * \param projectionMode projection mode of the viewer.
00058      */
00059     WGECamera( int width, int height, ProjectionMode projectionMode );
00060 
00061     /**
00062      * Constructor which sets defaults
00063      */
00064     WGECamera();
00065 
00066     /**
00067      * Sets the default projection mode used for cameras getting reset.
00068      *
00069      * \param mode the mode to set.
00070      */
00071     void setDefaultProjectionMode( ProjectionMode mode );
00072 
00073     /**
00074      * Returns the current default projection mode.
00075      *
00076      * \return the currently set mode.
00077      */
00078     ProjectionMode getDefaultProjectionMode();
00079 
00080     /**
00081      * Resets the camera and activates the prior set defaults.
00082      */
00083     void reset();
00084 
00085     /**
00086      * Change camera parameters which should be changed on a resize.
00087      */
00088     void resize();
00089 
00090 protected:
00091     /**
00092      * Destructor. This desctructor is protected to avoid accidentally deleting
00093      * a instance of WGECamera.
00094      * This follows the philosophy of OSG to avoid problems in multithreaded
00095      * environments, since these camera pointers are used deep in the OSG where
00096      * an deletion could cause a segfault.
00097      */
00098     virtual ~WGECamera();
00099 
00100     /**
00101      * The projection mode used as default.
00102      */
00103     ProjectionMode m_DefProjMode;
00104 
00105 private:
00106 };
00107 
00108 #endif  // WGECAMERA_H