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 // notify camera 00065 cam->_notifyViewport(this); 00066 } 00067 //--------------------------------------------------------------------- 00068 Viewport::~Viewport() 00069 { 00070 00071 } 00072 //--------------------------------------------------------------------- 00073 bool Viewport::_isUpdated(void) const 00074 { 00075 return mUpdated; 00076 } 00077 //--------------------------------------------------------------------- 00078 void Viewport::_clearUpdatedFlag(void) 00079 { 00080 mUpdated = false; 00081 } 00082 //--------------------------------------------------------------------- 00083 void Viewport::_updateDimensions(void) 00084 { 00085 Real height = (Real) mTarget->getHeight(); 00086 Real width = (Real) mTarget->getWidth(); 00087 00088 mActLeft = (int) (mRelLeft * width); 00089 mActTop = (int) (mRelTop * height); 00090 mActWidth = (int) (mRelWidth * width); 00091 mActHeight = (int) (mRelHeight * height); 00092 00093 // This will check if the cameras getAutoAspectRation() property is set. 00094 // If it's true its aspect ratio is fit to the current viewport 00095 // If it's false the camera remains unchanged. 00096 // This allows cameras to be used to render to many viewports, 00097 // which can have their own dimensions and aspect ratios. 00098 00099 if (mCamera->getAutoAspectRatio()) 00100 { 00101 mCamera->setAspectRatio((Real) (mActWidth / mActHeight)); 00102 } 00103 00104 char msg[256]; 00105 00106 sprintf(msg, "Viewport for camera '%s' - actual dimensions L:%d,T:%d,W:%d,H:%d", 00107 mCamera->getName().c_str(), mActLeft, mActTop, mActWidth, mActHeight); 00108 LogManager::getSingleton().logMessage(msg); 00109 00110 mUpdated = true; 00111 } 00112 //--------------------------------------------------------------------- 00113 int Viewport::getZOrder(void) const 00114 { 00115 return mZOrder; 00116 } 00117 //--------------------------------------------------------------------- 00118 RenderTarget* Viewport::getTarget(void) const 00119 { 00120 return mTarget; 00121 } 00122 //--------------------------------------------------------------------- 00123 Camera* Viewport::getCamera(void) const 00124 { 00125 return mCamera; 00126 } 00127 //--------------------------------------------------------------------- 00128 Real Viewport::getLeft(void) const 00129 { 00130 return mRelLeft; 00131 } 00132 //--------------------------------------------------------------------- 00133 Real Viewport::getTop(void) const 00134 { 00135 return mRelTop; 00136 } 00137 //--------------------------------------------------------------------- 00138 Real Viewport::getWidth(void) const 00139 { 00140 return mRelWidth; 00141 } 00142 //--------------------------------------------------------------------- 00143 Real Viewport::getHeight(void) const 00144 { 00145 return mRelHeight; 00146 } 00147 //--------------------------------------------------------------------- 00148 int Viewport::getActualLeft(void) const 00149 { 00150 return mActLeft; 00151 } 00152 //--------------------------------------------------------------------- 00153 int Viewport::getActualTop(void) const 00154 { 00155 return mActTop; 00156 } 00157 //--------------------------------------------------------------------- 00158 int Viewport::getActualWidth(void) const 00159 { 00160 return mActWidth; 00161 } 00162 //--------------------------------------------------------------------- 00163 int Viewport::getActualHeight(void) const 00164 { 00165 return mActHeight; 00166 } 00167 //--------------------------------------------------------------------- 00168 void Viewport::setDimensions(Real left, Real top, Real width, Real height) 00169 { 00170 mRelLeft = left; 00171 mRelTop = top; 00172 mRelWidth = width; 00173 mRelHeight = height; 00174 _updateDimensions(); 00175 } 00176 //--------------------------------------------------------------------- 00177 void Viewport::update(void) 00178 { 00179 if (mCamera) 00180 { 00181 // Tell Camera to render into me 00182 mCamera->_renderScene(this, mShowOverlays); 00183 } 00184 } 00185 //--------------------------------------------------------------------- 00186 void Viewport::setBackgroundColour(const ColourValue& colour) 00187 { 00188 mBackColour = colour; 00189 } 00190 //--------------------------------------------------------------------- 00191 const ColourValue& Viewport::getBackgroundColour(void) const 00192 { 00193 return mBackColour; 00194 } 00195 //--------------------------------------------------------------------- 00196 void Viewport::setClearEveryFrame(bool clear) 00197 { 00198 mClearEveryFrame = clear; 00199 } 00200 //--------------------------------------------------------------------- 00201 bool Viewport::getClearEveryFrame(void) const 00202 { 00203 return mClearEveryFrame; 00204 } 00205 //--------------------------------------------------------------------- 00206 void Viewport::getActualDimensions(int &left, int&top, int &width, int &height) const 00207 { 00208 left = mActLeft; 00209 top = mActTop; 00210 width = mActWidth; 00211 height = mActHeight; 00212 00213 } 00214 //--------------------------------------------------------------------- 00215 unsigned int Viewport::_getNumRenderedFaces(void) const 00216 { 00217 return mCamera->_getNumRenderedFaces(); 00218 } 00219 //--------------------------------------------------------------------- 00220 void Viewport::setCamera(Camera* cam) 00221 { 00222 mCamera = cam; 00223 00224 } 00225 //--------------------------------------------------------------------- 00226 void Viewport::setOverlaysEnabled(bool enabled) 00227 { 00228 mShowOverlays = enabled; 00229 } 00230 //--------------------------------------------------------------------- 00231 bool Viewport::getOverlaysEnabled(void) const 00232 { 00233 return mShowOverlays; 00234 } 00235 }
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:51 2004