[612] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
[1293] | 3 | * > www.orxonox.net < |
---|
[612] | 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
[1349] | 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
[612] | 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[1535] | 23 | * Reto Grieder |
---|
[1641] | 24 | * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007 |
---|
[612] | 25 | * Co-authors: |
---|
[1641] | 26 | * Felix Schulthess |
---|
[612] | 27 | * |
---|
| 28 | */ |
---|
[1035] | 29 | |
---|
[1638] | 30 | /** |
---|
| 31 | @file |
---|
| 32 | @brief |
---|
| 33 | Implementation of an partial interface to Ogre. |
---|
| 34 | */ |
---|
[612] | 35 | |
---|
[1021] | 36 | #include "OrxonoxStableHeaders.h" |
---|
[1039] | 37 | #include "GraphicsEngine.h" |
---|
[612] | 38 | |
---|
[1686] | 39 | #include <OgreRenderWindow.h> |
---|
[1538] | 40 | |
---|
[1293] | 41 | #include "core/CoreIncludes.h" |
---|
| 42 | #include "core/ConfigValueIncludes.h" |
---|
| 43 | #include "core/Debug.h" |
---|
[1535] | 44 | |
---|
[1563] | 45 | #include "tools/ParticleInterface.h" |
---|
[1032] | 46 | |
---|
[1625] | 47 | namespace orxonox |
---|
| 48 | { |
---|
[1686] | 49 | //SetConsoleCommand(GraphicsEngine, printScreen, true).setKeybindMode(KeybindMode::OnPress); |
---|
[1653] | 50 | |
---|
[1638] | 51 | GraphicsEngine* GraphicsEngine::singletonRef_s = 0; |
---|
[1032] | 52 | |
---|
[1638] | 53 | /** |
---|
| 54 | @brief |
---|
| 55 | Returns the singleton instance. |
---|
| 56 | @return |
---|
| 57 | The only instance of GraphicsEngine. |
---|
| 58 | */ |
---|
[1653] | 59 | /*static*/ GraphicsEngine& GraphicsEngine::getInstance() |
---|
[1638] | 60 | { |
---|
| 61 | assert(singletonRef_s); |
---|
| 62 | return *singletonRef_s; |
---|
| 63 | } |
---|
[1293] | 64 | |
---|
[1638] | 65 | /** |
---|
| 66 | @brief |
---|
| 67 | Non-initialising constructor. |
---|
| 68 | */ |
---|
| 69 | GraphicsEngine::GraphicsEngine() |
---|
| 70 | : root_(0) |
---|
| 71 | , renderWindow_(0) |
---|
| 72 | , levelSceneManager_(0) |
---|
[1640] | 73 | , viewport_(0) |
---|
[1638] | 74 | { |
---|
| 75 | RegisterObject(GraphicsEngine); |
---|
[1563] | 76 | |
---|
[1641] | 77 | assert(singletonRef_s == 0); |
---|
[1638] | 78 | singletonRef_s = this; |
---|
[612] | 79 | |
---|
[1638] | 80 | this->detailLevelParticle_ = 0; |
---|
[1563] | 81 | |
---|
[1638] | 82 | this->setConfigValues(); |
---|
| 83 | CCOUT(4) << "Constructed" << std::endl; |
---|
| 84 | } |
---|
[1563] | 85 | |
---|
[1638] | 86 | void GraphicsEngine::setConfigValues() |
---|
| 87 | { |
---|
| 88 | unsigned int old = this->detailLevelParticle_; |
---|
| 89 | SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high"); |
---|
[1032] | 90 | |
---|
[1638] | 91 | if (this->detailLevelParticle_ != old) |
---|
| 92 | for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it) |
---|
| 93 | it->detailLevelChanged(this->detailLevelParticle_); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | /** |
---|
| 97 | @brief |
---|
| 98 | Destroys all the Ogre related objects |
---|
| 99 | */ |
---|
| 100 | GraphicsEngine::~GraphicsEngine() |
---|
[1024] | 101 | { |
---|
[1638] | 102 | singletonRef_s = 0; |
---|
[1024] | 103 | } |
---|
[612] | 104 | |
---|
[1638] | 105 | /** |
---|
| 106 | @brief |
---|
| 107 | Get the width of the render window |
---|
| 108 | @return |
---|
| 109 | The width of the render window |
---|
| 110 | */ |
---|
| 111 | int GraphicsEngine::getWindowWidth() const |
---|
[1538] | 112 | { |
---|
[1638] | 113 | if (this->renderWindow_) |
---|
| 114 | return this->renderWindow_->getWidth(); |
---|
| 115 | else |
---|
| 116 | return 0; |
---|
[1538] | 117 | } |
---|
| 118 | |
---|
[1638] | 119 | /** |
---|
| 120 | @brief |
---|
| 121 | Get the height of the render window |
---|
| 122 | @return |
---|
| 123 | The height of the render window |
---|
| 124 | */ |
---|
| 125 | int GraphicsEngine::getWindowHeight() const |
---|
[1535] | 126 | { |
---|
[1638] | 127 | if (this->renderWindow_) |
---|
| 128 | return this->renderWindow_->getHeight(); |
---|
| 129 | else |
---|
| 130 | return 0; |
---|
[1535] | 131 | } |
---|
[1638] | 132 | |
---|
| 133 | /** |
---|
| 134 | @brief |
---|
| 135 | Returns the window aspect ratio height/width. |
---|
| 136 | @return |
---|
| 137 | The window aspect ratio |
---|
| 138 | */ |
---|
| 139 | float GraphicsEngine::getWindowAspectRatio() const |
---|
[1535] | 140 | { |
---|
[1638] | 141 | if (this->renderWindow_) |
---|
| 142 | return (float)this->renderWindow_->getHeight() / (float)this->renderWindow_->getWidth(); |
---|
| 143 | else |
---|
| 144 | return 1.0f; |
---|
[1535] | 145 | } |
---|
[612] | 146 | } |
---|