| [1505] | 1 | /* | 
|---|
 | 2 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
 | 3 |  *                    > www.orxonox.net < | 
|---|
 | 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 | 
|---|
 | 11 |  *   of the License, or (at your option) any later version. | 
|---|
 | 12 |  * | 
|---|
 | 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: | 
|---|
 | 23 |  *      Fabian 'x3n' Landau | 
|---|
 | 24 |  *   Co-authors: | 
|---|
 | 25 |  *      ... | 
|---|
 | 26 |  * | 
|---|
 | 27 |  */ | 
|---|
 | 28 |  | 
|---|
 | 29 | #include "BillboardSet.h" | 
|---|
 | 30 |  | 
|---|
| [3196] | 31 | #include <cassert> | 
|---|
 | 32 | #include <string> | 
|---|
| [1505] | 33 | #include <sstream> | 
|---|
 | 34 | #include <OgreSceneManager.h> | 
|---|
| [2662] | 35 | #include <OgreBillboardSet.h> | 
|---|
| [2087] | 36 | #include <OgreBillboard.h> | 
|---|
| [1505] | 37 |  | 
|---|
| [2087] | 38 | #include "util/Convert.h" | 
|---|
| [3196] | 39 | #include "util/Math.h" | 
|---|
 | 40 | #include "core/GameMode.h" | 
|---|
| [1505] | 41 |  | 
|---|
 | 42 | namespace orxonox | 
|---|
 | 43 | { | 
|---|
 | 44 |     unsigned int BillboardSet::billboardSetCounter_s = 0; | 
|---|
 | 45 |  | 
|---|
 | 46 |     BillboardSet::BillboardSet() | 
|---|
 | 47 |     { | 
|---|
| [11071] | 48 |         this->billboardSet_ = nullptr; | 
|---|
| [1505] | 49 |     } | 
|---|
 | 50 |  | 
|---|
| [2087] | 51 |     BillboardSet::~BillboardSet() | 
|---|
| [1505] | 52 |     { | 
|---|
| [2087] | 53 |         this->destroyBillboardSet(); | 
|---|
| [1602] | 54 |     } | 
|---|
 | 55 |  | 
|---|
| [2087] | 56 |     void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, int count) | 
|---|
| [1602] | 57 |     { | 
|---|
| [2087] | 58 |         this->setBillboardSet(scenemanager, file, Vector3::ZERO, count); | 
|---|
| [1602] | 59 |     } | 
|---|
 | 60 |  | 
|---|
| [2087] | 61 |     void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, int count) | 
|---|
| [1602] | 62 |     { | 
|---|
| [2087] | 63 |         this->setBillboardSet(scenemanager, file, colour, Vector3::ZERO, count); | 
|---|
| [1602] | 64 |     } | 
|---|
 | 65 |  | 
|---|
| [2087] | 66 |     void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const Vector3& position, int count) | 
|---|
| [1602] | 67 |     { | 
|---|
| [11087] | 68 |         this->setBillboardSet(scenemanager, file, ColourValue::White, position, count); | 
|---|
| [1505] | 69 |     } | 
|---|
 | 70 |  | 
|---|
| [2087] | 71 |     void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, const Vector3& position, int count) | 
|---|
| [1505] | 72 |     { | 
|---|
| [2087] | 73 |         assert(scenemanager); | 
|---|
 | 74 |         this->destroyBillboardSet(); | 
|---|
 | 75 |  | 
|---|
 | 76 |         try | 
|---|
 | 77 |         { | 
|---|
| [2896] | 78 |             if (GameMode::showsGraphics()) | 
|---|
| [2171] | 79 |             { | 
|---|
| [3280] | 80 |                 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + multi_cast<std::string>(BillboardSet::billboardSetCounter_s++), count); | 
|---|
| [2171] | 81 |                 this->billboardSet_->createBillboard(position, colour); | 
|---|
 | 82 |                 this->billboardSet_->setMaterialName(file); | 
|---|
 | 83 |             } | 
|---|
| [2087] | 84 |         } | 
|---|
 | 85 |         catch (...) | 
|---|
 | 86 |         { | 
|---|
| [8858] | 87 |             orxout(internal_error) << "Couldn't load billboard \"" << file << '"' << endl; | 
|---|
| [11071] | 88 |             this->billboardSet_ = nullptr; | 
|---|
| [2087] | 89 |         } | 
|---|
 | 90 |  | 
|---|
 | 91 |         this->scenemanager_ = scenemanager; | 
|---|
 | 92 |     } | 
|---|
 | 93 |  | 
|---|
 | 94 |     void BillboardSet::destroyBillboardSet() | 
|---|
 | 95 |     { | 
|---|
 | 96 |         if (this->billboardSet_ && this->scenemanager_) | 
|---|
 | 97 |             this->scenemanager_->destroyBillboardSet(this->billboardSet_); | 
|---|
| [11071] | 98 |         this->billboardSet_ = nullptr; | 
|---|
| [2087] | 99 |     } | 
|---|
 | 100 |  | 
|---|
 | 101 |     const std::string& BillboardSet::getName() const | 
|---|
 | 102 |     { | 
|---|
| [1505] | 103 |         if (this->billboardSet_) | 
|---|
| [2087] | 104 |             return this->billboardSet_->getName(); | 
|---|
 | 105 |         else | 
|---|
 | 106 |             return BLANKSTRING; | 
|---|
| [1505] | 107 |     } | 
|---|
| [2087] | 108 |  | 
|---|
 | 109 |     void BillboardSet::setVisible(bool visible) | 
|---|
 | 110 |     { | 
|---|
 | 111 |         if (this->billboardSet_) | 
|---|
 | 112 |             this->billboardSet_->setVisible(visible); | 
|---|
 | 113 |     } | 
|---|
 | 114 |  | 
|---|
 | 115 |     bool BillboardSet::getVisible() const | 
|---|
 | 116 |     { | 
|---|
 | 117 |         if (this->billboardSet_) | 
|---|
 | 118 |             return this->billboardSet_->getVisible(); | 
|---|
 | 119 |         else | 
|---|
 | 120 |             return false; | 
|---|
 | 121 |     } | 
|---|
 | 122 |  | 
|---|
 | 123 |     void BillboardSet::setColour(const ColourValue& colour) | 
|---|
 | 124 |     { | 
|---|
 | 125 |         if (this->billboardSet_) | 
|---|
 | 126 |         { | 
|---|
 | 127 |             for (int i = 0; i < this->billboardSet_->getNumBillboards(); ++i) | 
|---|
 | 128 |                 this->billboardSet_->getBillboard(i)->setColour(colour); | 
|---|
 | 129 |         } | 
|---|
 | 130 |     } | 
|---|
 | 131 |  | 
|---|
 | 132 |     const ColourValue& BillboardSet::getColour() const | 
|---|
 | 133 |     { | 
|---|
 | 134 |         if (this->billboardSet_ && this->billboardSet_->getNumBillboards() > 0) | 
|---|
 | 135 |         { | 
|---|
 | 136 |             return this->billboardSet_->getBillboard(0)->getColour(); | 
|---|
 | 137 |         } | 
|---|
 | 138 |         else | 
|---|
 | 139 |             return ColourValue::White; | 
|---|
 | 140 |     } | 
|---|
 | 141 |  | 
|---|
 | 142 |     void BillboardSet::setMaterial(const std::string& material) | 
|---|
 | 143 |     { | 
|---|
 | 144 |         if (this->billboardSet_) | 
|---|
 | 145 |             this->billboardSet_->setMaterialName(material); | 
|---|
 | 146 |     } | 
|---|
 | 147 |  | 
|---|
 | 148 |     const std::string& BillboardSet::getMaterial() const | 
|---|
 | 149 |     { | 
|---|
 | 150 |         if (this->billboardSet_) | 
|---|
 | 151 |             return this->billboardSet_->getMaterialName(); | 
|---|
 | 152 |         else | 
|---|
 | 153 |             return BLANKSTRING; | 
|---|
 | 154 |     } | 
|---|
| [1505] | 155 | } | 
|---|