| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- /*
- -----------------------------------------------------------------------------
- This source file is part of OGRE
- (Object-oriented Graphics Rendering Engine)
- For the latest info, see http://www.ogre3d.org/
- Copyright (c) 2000-2011 Torus Knot Software Ltd
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- -----------------------------------------------------------------------------
- */
- #include "OgreViewport.h"
- #include "OgreException.h"
- #include "OgreRenderTarget.h"
- #include "OgreMath.h"
- #include "OgreRenderSystem.h"
- #include "CmRenderSystemManager.h"
- namespace Ogre {
- OrientationMode Viewport::mDefaultOrientationMode = OR_DEGREE_0;
- //---------------------------------------------------------------------
- Viewport::Viewport(RenderTarget* target, Real left, Real top, Real width, Real height, int ZOrder)
- :mTarget(target)
- , mRelLeft(left)
- , mRelTop(top)
- , mRelWidth(width)
- , mRelHeight(height)
- // Actual dimensions will update later
- , mZOrder(ZOrder)
- , mBackColour(ColourValue::Black)
- , mClearEveryFrame(true)
- , mClearBuffers(FBT_COLOUR | FBT_DEPTH)
- , mUpdated(false)
- , mShowOverlays(true)
- , mShowSkies(true)
- , mShowShadows(true)
- , mVisibilityMask(0xFFFFFFFF)
- , mMaterialSchemeName("NotUsedInPort")
- , mIsAutoUpdated(true)
- {
- // Set the default orientation mode
- mOrientationMode = mDefaultOrientationMode;
- // Calculate actual dimensions
- _updateDimensions();
- }
- //---------------------------------------------------------------------
- Viewport::~Viewport()
- {
- }
- //---------------------------------------------------------------------
- bool Viewport::_isUpdated(void) const
- {
- return mUpdated;
- }
- //---------------------------------------------------------------------
- void Viewport::_clearUpdatedFlag(void)
- {
- mUpdated = false;
- }
- //---------------------------------------------------------------------
- void Viewport::_updateDimensions(void)
- {
- Real height = (Real) mTarget->getHeight();
- Real width = (Real) mTarget->getWidth();
- mActLeft = (int) (mRelLeft * width);
- mActTop = (int) (mRelTop * height);
- mActWidth = (int) (mRelWidth * width);
- mActHeight = (int) (mRelHeight * height);
- mUpdated = true;
- }
- //---------------------------------------------------------------------
- int Viewport::getZOrder(void) const
- {
- return mZOrder;
- }
- //---------------------------------------------------------------------
- RenderTarget* Viewport::getTarget(void) const
- {
- return mTarget;
- }
- //---------------------------------------------------------------------
- Real Viewport::getLeft(void) const
- {
- return mRelLeft;
- }
- //---------------------------------------------------------------------
- Real Viewport::getTop(void) const
- {
- return mRelTop;
- }
- //---------------------------------------------------------------------
- Real Viewport::getWidth(void) const
- {
- return mRelWidth;
- }
- //---------------------------------------------------------------------
- Real Viewport::getHeight(void) const
- {
- return mRelHeight;
- }
- //---------------------------------------------------------------------
- int Viewport::getActualLeft(void) const
- {
- return mActLeft;
- }
- //---------------------------------------------------------------------
- int Viewport::getActualTop(void) const
- {
- return mActTop;
- }
- //---------------------------------------------------------------------
- int Viewport::getActualWidth(void) const
- {
- return mActWidth;
- }
- //---------------------------------------------------------------------
- int Viewport::getActualHeight(void) const
- {
- return mActHeight;
- }
- //---------------------------------------------------------------------
- void Viewport::setDimensions(Real left, Real top, Real width, Real height)
- {
- mRelLeft = left;
- mRelTop = top;
- mRelWidth = width;
- mRelHeight = height;
- _updateDimensions();
- }
- //---------------------------------------------------------------------
- void Viewport::update(void)
- {
- }
- //---------------------------------------------------------------------
- void Viewport::setOrientationMode(OrientationMode orientationMode, bool setDefault)
- {
- #if OGRE_NO_VIEWPORT_ORIENTATIONMODE != 0
- OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
- "Setting Viewport orientation mode is not supported",
- __FUNCTION__);
- #endif
- mOrientationMode = orientationMode;
- if (setDefault)
- {
- setDefaultOrientationMode(orientationMode);
- }
- // Update the render system config
- RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
- if(mOrientationMode == OR_LANDSCAPELEFT)
- rs->setConfigOption("Orientation", "Landscape Left");
- else if(mOrientationMode == OR_LANDSCAPERIGHT)
- rs->setConfigOption("Orientation", "Landscape Right");
- else if(mOrientationMode == OR_PORTRAIT)
- rs->setConfigOption("Orientation", "Portrait");
- }
- //---------------------------------------------------------------------
- OrientationMode Viewport::getOrientationMode() const
- {
- #if OGRE_NO_VIEWPORT_ORIENTATIONMODE != 0
- OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
- "Getting Viewport orientation mode is not supported",
- __FUNCTION__);
- #endif
- return mOrientationMode;
- }
- //---------------------------------------------------------------------
- void Viewport::setDefaultOrientationMode(OrientationMode orientationMode)
- {
- #if OGRE_NO_VIEWPORT_ORIENTATIONMODE != 0
- OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
- "Setting default Viewport orientation mode is not supported",
- __FUNCTION__);
- #endif
- mDefaultOrientationMode = orientationMode;
- }
- //---------------------------------------------------------------------
- OrientationMode Viewport::getDefaultOrientationMode()
- {
- #if OGRE_NO_VIEWPORT_ORIENTATIONMODE != 0
- OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
- "Getting default Viewport orientation mode is not supported",
- __FUNCTION__);
- #endif
- return mDefaultOrientationMode;
- }
- //---------------------------------------------------------------------
- void Viewport::setBackgroundColour(const ColourValue& colour)
- {
- mBackColour = colour;
- }
- //---------------------------------------------------------------------
- const ColourValue& Viewport::getBackgroundColour(void) const
- {
- return mBackColour;
- }
- //---------------------------------------------------------------------
- void Viewport::setClearEveryFrame(bool inClear, unsigned int inBuffers)
- {
- mClearEveryFrame = inClear;
- mClearBuffers = inBuffers;
- }
- //---------------------------------------------------------------------
- bool Viewport::getClearEveryFrame(void) const
- {
- return mClearEveryFrame;
- }
- //---------------------------------------------------------------------
- unsigned int Viewport::getClearBuffers(void) const
- {
- return mClearBuffers;
- }
- //---------------------------------------------------------------------
- void Viewport::clear(unsigned int buffers, const ColourValue& col,
- Real depth, unsigned short stencil)
- {
- RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
- if (rs)
- {
- Viewport* currentvp = rs->_getViewport();
- if (currentvp && currentvp == this)
- rs->clearFrameBuffer(buffers, col, depth, stencil);
- else if (currentvp)
- {
- rs->_setViewport(this);
- rs->clearFrameBuffer(buffers, col, depth, stencil);
- rs->_setViewport(currentvp);
- }
- }
- }
- //---------------------------------------------------------------------
- void Viewport::getActualDimensions(int &left, int&top, int &width, int &height) const
- {
- left = mActLeft;
- top = mActTop;
- width = mActWidth;
- height = mActHeight;
- }
- //---------------------------------------------------------------------
- void Viewport::setAutoUpdated(bool inAutoUpdated)
- {
- mIsAutoUpdated = inAutoUpdated;
- }
- //---------------------------------------------------------------------
- bool Viewport::isAutoUpdated() const
- {
- return mIsAutoUpdated;
- }
- //---------------------------------------------------------------------
- void Viewport::setOverlaysEnabled(bool enabled)
- {
- mShowOverlays = enabled;
- }
- //---------------------------------------------------------------------
- bool Viewport::getOverlaysEnabled(void) const
- {
- return mShowOverlays;
- }
- //---------------------------------------------------------------------
- void Viewport::setSkiesEnabled(bool enabled)
- {
- mShowSkies = enabled;
- }
- //---------------------------------------------------------------------
- bool Viewport::getSkiesEnabled(void) const
- {
- return mShowSkies;
- }
- //---------------------------------------------------------------------
- void Viewport::setShadowsEnabled(bool enabled)
- {
- mShowShadows = enabled;
- }
- //---------------------------------------------------------------------
- bool Viewport::getShadowsEnabled(void) const
- {
- return mShowShadows;
- }
- //-----------------------------------------------------------------------
- void Viewport::pointOrientedToScreen(const Vector2 &v, int orientationMode, Vector2 &outv)
- {
- pointOrientedToScreen(v.x, v.y, orientationMode, outv.x, outv.y);
- }
- //-----------------------------------------------------------------------
- void Viewport::pointOrientedToScreen(Real orientedX, Real orientedY, int orientationMode,
- Real &screenX, Real &screenY)
- {
- Real orX = orientedX;
- Real orY = orientedY;
- switch (orientationMode)
- {
- case 1:
- screenX = orY;
- screenY = Real(1.0) - orX;
- break;
- case 2:
- screenX = Real(1.0) - orX;
- screenY = Real(1.0) - orY;
- break;
- case 3:
- screenX = Real(1.0) - orY;
- screenY = orX;
- break;
- default:
- screenX = orX;
- screenY = orY;
- break;
- }
- }
- //-----------------------------------------------------------------------
- }
|