Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreViewport.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #include "OgreStableHeaders.h"
00026 #include "OgreViewport.h"
00027 
00028 #include "OgreLogManager.h"
00029 #include "OgreRenderTarget.h"
00030 #include "OgreCamera.h"
00031 #include "OgreMath.h"
00032 
00033 namespace Ogre {
00034     //---------------------------------------------------------------------
00035     Viewport::Viewport(Camera* cam, RenderTarget* target, Real left, Real top, Real width, Real height, int ZOrder)
00036     {
00037         char msg[200];
00038 
00039 
00040         sprintf(msg, "Creating viewport on target '%s', rendering from camera "
00041             "'%s', relative dimensions L:%.2f,T:%.2f,W:%.2f,H:%.2f, Z-Order:%d",
00042             target->getName().c_str(), cam->getName().c_str(),
00043             left, top, width, height, ZOrder);
00044         LogManager::getSingleton().logMessage(msg);
00045         mCamera = cam;
00046         mTarget = target;
00047 
00048         mRelLeft = left;
00049         mRelTop = top;
00050         mRelWidth = width;
00051         mRelHeight = height;
00052         mZOrder = ZOrder;
00053 
00054         mBackColour = ColourValue::Black;
00055         mClearEveryFrame = true;
00056 
00057 
00058         // Calculate actual dimensions
00059         _updateDimensions();
00060 
00061         mUpdated = true;
00062         mShowOverlays = true;
00063     }
00064     //---------------------------------------------------------------------
00065     Viewport::~Viewport()
00066     {
00067 
00068     }
00069     //---------------------------------------------------------------------
00070     bool Viewport::_isUpdated(void) const
00071     {
00072         return mUpdated;
00073     }
00074     //---------------------------------------------------------------------
00075     void Viewport::_clearUpdatedFlag(void)
00076     {
00077         mUpdated = false;
00078     }
00079     //---------------------------------------------------------------------
00080     void Viewport::_updateDimensions(void)
00081     {
00082         Real height = (Real) mTarget->getHeight();
00083         Real width = (Real) mTarget->getWidth();
00084 
00085         mActLeft = (int) (mRelLeft * width);
00086         mActTop = (int) (mRelTop * height);
00087         mActWidth = (int) (mRelWidth * width);
00088         mActHeight = (int) (mRelHeight * height);
00089 
00090         // Note that we don't propagate any changes to the Camera
00091         // This is because the Camera projects into a space with
00092         // range (-1,1), which then gets extrapolated to the viewport
00093         // dimensions. Note that if the aspect ratio of the camera
00094         // is not the same as that of the viewport, the image will
00095         // be distorted in some way.
00096 
00097         // This allows cameras to be used to render to many viewports,
00098         // which can have their own dimensions and aspect ratios.
00099 
00100 
00101         char msg[256];
00102 
00103         sprintf(msg, "Viewport for camera '%s' - actual dimensions L:%d,T:%d,W:%d,H:%d",
00104             mCamera->getName().c_str(), mActLeft, mActTop, mActWidth, mActHeight);
00105         LogManager::getSingleton().logMessage(msg);
00106 
00107         mUpdated = true;
00108     }
00109     //---------------------------------------------------------------------
00110     int Viewport::getZOrder(void) const
00111     {
00112         return mZOrder;
00113     }
00114     //---------------------------------------------------------------------
00115     RenderTarget* Viewport::getTarget(void) const
00116     {
00117         return mTarget;
00118     }
00119     //---------------------------------------------------------------------
00120     Camera* Viewport::getCamera(void) const
00121     {
00122         return mCamera;
00123     }
00124     //---------------------------------------------------------------------
00125     Real Viewport::getLeft(void) const
00126     {
00127         return mRelLeft;
00128     }
00129     //---------------------------------------------------------------------
00130     Real Viewport::getTop(void) const
00131     {
00132         return mRelTop;
00133     }
00134     //---------------------------------------------------------------------
00135     Real Viewport::getWidth(void) const
00136     {
00137         return mRelWidth;
00138     }
00139     //---------------------------------------------------------------------
00140     Real Viewport::getHeight(void) const
00141     {
00142         return mRelHeight;
00143     }
00144     //---------------------------------------------------------------------
00145     int Viewport::getActualLeft(void) const
00146     {
00147         return mActLeft;
00148     }
00149     //---------------------------------------------------------------------
00150     int Viewport::getActualTop(void) const
00151     {
00152         return mActTop;
00153     }
00154     //---------------------------------------------------------------------
00155     int Viewport::getActualWidth(void) const
00156     {
00157         return mActWidth;
00158     }
00159     //---------------------------------------------------------------------
00160     int Viewport::getActualHeight(void) const
00161     {
00162         return mActHeight;
00163     }
00164     //---------------------------------------------------------------------
00165     void Viewport::setDimensions(Real left, Real top, Real width, Real height)
00166     {
00167         mRelLeft = left;
00168         mRelTop = top;
00169         mRelWidth = width;
00170         mRelHeight = height;
00171         _updateDimensions();
00172     }
00173     //---------------------------------------------------------------------
00174     void Viewport::update(void)
00175     {
00176         if (mCamera)
00177         {
00178             // Tell Camera to render into me
00179             mCamera->_renderScene(this, mShowOverlays);
00180         }
00181     }
00182     //---------------------------------------------------------------------
00183     void Viewport::setBackgroundColour(const ColourValue& colour)
00184     {
00185         mBackColour = colour;
00186     }
00187     //---------------------------------------------------------------------
00188     const ColourValue& Viewport::getBackgroundColour(void) const
00189     {
00190         return mBackColour;
00191     }
00192     //---------------------------------------------------------------------
00193     void Viewport::setClearEveryFrame(bool clear)
00194     {
00195         mClearEveryFrame = clear;
00196     }
00197     //---------------------------------------------------------------------
00198     bool Viewport::getClearEveryFrame(void) const
00199     {
00200         return mClearEveryFrame;
00201     }
00202     //---------------------------------------------------------------------
00203     void Viewport::getActualDimensions(int &left, int&top, int &width, int &height) const
00204     {
00205         left = mActLeft;
00206         top = mActTop;
00207         width = mActWidth;
00208         height = mActHeight;
00209 
00210     }
00211     //---------------------------------------------------------------------
00212     unsigned int Viewport::_getNumRenderedFaces(void) const
00213     {
00214         return mCamera->_getNumRenderedFaces();
00215     }
00216     //---------------------------------------------------------------------
00217     void Viewport::setCamera(Camera* cam)
00218     {
00219         mCamera = cam;
00220 
00221     }
00222     //---------------------------------------------------------------------
00223     void Viewport::setOverlaysEnabled(bool enabled)
00224     {
00225         mShowOverlays = enabled;
00226     }
00227     //---------------------------------------------------------------------
00228     bool Viewport::getOverlaysEnabled(void) const
00229     {
00230         return mShowOverlays;
00231     }
00232 }

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:54 2004