source: OGRE/trunk/ogrenew/OgreMain/src/OgreViewport.cpp @ 657

Revision 657, 8.0 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26#include "OgreViewport.h"
27
28#include "OgreLogManager.h"
29#include "OgreRenderTarget.h"
30#include "OgreCamera.h"
31#include "OgreMath.h"
32
33namespace Ogre {
34    //---------------------------------------------------------------------
35    Viewport::Viewport(Camera* cam, RenderTarget* target, Real left, Real top, Real width, Real height, int ZOrder)
36    {
37
38                StringUtil::StrStreamType msg;
39
40        msg << "Creating viewport on target '" << target->getName() << "'"
41                        << ", rendering from camera '" << cam->getName() << "'"
42                        << ", relative dimensions "     << std::fixed << std::setprecision(2)
43                        << "L: " << left << " T: " << top << " W: " << width << " H: " << height
44                        << " ZOrder: " << ZOrder;
45        LogManager::getSingleton().logMessage(msg.str());
46        mCamera = cam;
47        mTarget = target;
48
49        mRelLeft = left;
50        mRelTop = top;
51        mRelWidth = width;
52        mRelHeight = height;
53        mZOrder = ZOrder;
54
55        mBackColour = ColourValue::Black;
56        mClearEveryFrame = true;
57
58
59        // Calculate actual dimensions
60        _updateDimensions();
61
62        mUpdated = true;
63        mShowOverlays = true;
64
65        // notify camera
66        cam->_notifyViewport(this);
67    }
68    //---------------------------------------------------------------------
69    Viewport::~Viewport()
70    {
71
72    }
73    //---------------------------------------------------------------------
74    bool Viewport::_isUpdated(void) const
75    {
76        return mUpdated;
77    }
78    //---------------------------------------------------------------------
79    void Viewport::_clearUpdatedFlag(void)
80    {
81        mUpdated = false;
82    }
83    //---------------------------------------------------------------------
84    void Viewport::_updateDimensions(void)
85    {
86        Real height = (Real) mTarget->getHeight();
87        Real width = (Real) mTarget->getWidth();
88
89        mActLeft = (int) (mRelLeft * width);
90        mActTop = (int) (mRelTop * height);
91        mActWidth = (int) (mRelWidth * width);
92        mActHeight = (int) (mRelHeight * height);
93
94        // This will check if  the cameras getAutoAspectRation() property is set.
95        // If it's true its aspect ratio is fit to the current viewport
96        // If it's false the camera remains unchanged.
97        // This allows cameras to be used to render to many viewports,
98        // which can have their own dimensions and aspect ratios.
99
100        if (mCamera->getAutoAspectRatio())
101        {
102            mCamera->setAspectRatio((Real) mActWidth / (Real) mActHeight);
103        }
104
105                StringUtil::StrStreamType msg;
106
107        msg << "Viewport for camera '" << mCamera->getName() << "'"
108                        << ", actual dimensions "       << std::fixed << std::setprecision(2)
109                        << "L: " << mActLeft << " T: " << mActTop << " W: " << mActWidth << " H: " << mActHeight;
110
111        LogManager::getSingleton().logMessage(msg.str());
112
113        mUpdated = true;
114    }
115        //---------------------------------------------------------------------
116        int Viewport::getZOrder(void) const
117        {
118                return mZOrder;
119        }
120        //---------------------------------------------------------------------
121    RenderTarget* Viewport::getTarget(void) const
122    {
123        return mTarget;
124    }
125    //---------------------------------------------------------------------
126    Camera* Viewport::getCamera(void) const
127    {
128        return mCamera;
129    }
130    //---------------------------------------------------------------------
131    Real Viewport::getLeft(void) const
132    {
133        return mRelLeft;
134    }
135    //---------------------------------------------------------------------
136    Real Viewport::getTop(void) const
137    {
138        return mRelTop;
139    }
140    //---------------------------------------------------------------------
141    Real Viewport::getWidth(void) const
142    {
143        return mRelWidth;
144    }
145    //---------------------------------------------------------------------
146    Real Viewport::getHeight(void) const
147    {
148        return mRelHeight;
149    }
150    //---------------------------------------------------------------------
151    int Viewport::getActualLeft(void) const
152    {
153        return mActLeft;
154    }
155    //---------------------------------------------------------------------
156    int Viewport::getActualTop(void) const
157    {
158        return mActTop;
159    }
160    //---------------------------------------------------------------------
161    int Viewport::getActualWidth(void) const
162    {
163        return mActWidth;
164    }
165    //---------------------------------------------------------------------
166    int Viewport::getActualHeight(void) const
167    {
168        return mActHeight;
169    }
170    //---------------------------------------------------------------------
171    void Viewport::setDimensions(Real left, Real top, Real width, Real height)
172    {
173        mRelLeft = left;
174        mRelTop = top;
175        mRelWidth = width;
176        mRelHeight = height;
177        _updateDimensions();
178    }
179    //---------------------------------------------------------------------
180    void Viewport::update(void)
181    {
182        if (mCamera)
183        {
184            // Tell Camera to render into me
185            mCamera->_renderScene(this, mShowOverlays);
186        }
187    }
188    //---------------------------------------------------------------------
189    void Viewport::setBackgroundColour(const ColourValue& colour)
190    {
191        mBackColour = colour;
192    }
193    //---------------------------------------------------------------------
194    const ColourValue& Viewport::getBackgroundColour(void) const
195    {
196        return mBackColour;
197    }
198    //---------------------------------------------------------------------
199    void Viewport::setClearEveryFrame(bool clear)
200    {
201        mClearEveryFrame = clear;
202    }
203    //---------------------------------------------------------------------
204    bool Viewport::getClearEveryFrame(void) const
205    {
206        return mClearEveryFrame;
207    }
208    //---------------------------------------------------------------------
209    void Viewport::getActualDimensions(int &left, int&top, int &width, int &height) const
210    {
211        left = mActLeft;
212        top = mActTop;
213        width = mActWidth;
214        height = mActHeight;
215
216    }
217    //---------------------------------------------------------------------
218    unsigned int Viewport::_getNumRenderedFaces(void) const
219    {
220        return mCamera->_getNumRenderedFaces();
221    }
222    //---------------------------------------------------------------------
223    void Viewport::setCamera(Camera* cam)
224    {
225        mCamera = cam;
226
227    }
228    //---------------------------------------------------------------------
229    void Viewport::setOverlaysEnabled(bool enabled)
230    {
231        mShowOverlays = enabled;
232    }
233    //---------------------------------------------------------------------
234    bool Viewport::getOverlaysEnabled(void) const
235    {
236        return mShowOverlays;
237    }
238}
Note: See TracBrowser for help on using the repository browser.