| [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 "OrxonoxStableHeaders.h" | 
|---|
 | 30 | #include "BillboardSet.h" | 
|---|
 | 31 |  | 
|---|
 | 32 | #include <sstream> | 
|---|
| [2087] | 33 | #include <cassert> | 
|---|
| [1505] | 34 |  | 
|---|
 | 35 | #include <OgreSceneManager.h> | 
|---|
| [2087] | 36 | #include <OgreBillboard.h> | 
|---|
| [1505] | 37 |  | 
|---|
| [2171] | 38 | #include "core/Core.h" | 
|---|
| [2087] | 39 | #include "util/Convert.h" | 
|---|
 | 40 | #include "util/String.h" | 
|---|
| [1505] | 41 |  | 
|---|
 | 42 | namespace orxonox | 
|---|
 | 43 | { | 
|---|
 | 44 |     unsigned int BillboardSet::billboardSetCounter_s = 0; | 
|---|
 | 45 |  | 
|---|
 | 46 |     BillboardSet::BillboardSet() | 
|---|
 | 47 |     { | 
|---|
 | 48 |         this->billboardSet_ = 0; | 
|---|
 | 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 |     { | 
|---|
| [2087] | 68 |         assert(scenemanager); | 
|---|
 | 69 |         this->destroyBillboardSet(); | 
|---|
 | 70 |  | 
|---|
 | 71 |         try | 
|---|
 | 72 |         { | 
|---|
| [2171] | 73 |             if (Core::showsGraphics()) | 
|---|
 | 74 |             { | 
|---|
 | 75 |                 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + convertToString(BillboardSet::billboardSetCounter_s++), count); | 
|---|
 | 76 |                 this->billboardSet_->createBillboard(position); | 
|---|
 | 77 |                 this->billboardSet_->setMaterialName(file); | 
|---|
 | 78 |             } | 
|---|
| [2087] | 79 |         } | 
|---|
 | 80 |         catch (...) | 
|---|
 | 81 |         { | 
|---|
 | 82 |             COUT(1) << "Error: Couln't load billboard \"" << file << "\"" << std::endl; | 
|---|
| [2171] | 83 |             this->billboardSet_ = 0; | 
|---|
| [2087] | 84 |         } | 
|---|
 | 85 |  | 
|---|
 | 86 |         this->scenemanager_ = scenemanager; | 
|---|
| [1505] | 87 |     } | 
|---|
 | 88 |  | 
|---|
| [2087] | 89 |     void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, const Vector3& position, int count) | 
|---|
| [1505] | 90 |     { | 
|---|
| [2087] | 91 |         assert(scenemanager); | 
|---|
 | 92 |         this->destroyBillboardSet(); | 
|---|
 | 93 |  | 
|---|
 | 94 |         try | 
|---|
 | 95 |         { | 
|---|
| [2171] | 96 |             if (Core::showsGraphics()) | 
|---|
 | 97 |             { | 
|---|
 | 98 |                 this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + convertToString(BillboardSet::billboardSetCounter_s++), count); | 
|---|
 | 99 |                 this->billboardSet_->createBillboard(position, colour); | 
|---|
 | 100 |                 this->billboardSet_->setMaterialName(file); | 
|---|
 | 101 |             } | 
|---|
| [2087] | 102 |         } | 
|---|
 | 103 |         catch (...) | 
|---|
 | 104 |         { | 
|---|
 | 105 |             COUT(1) << "Error: Couln't load billboard \"" << file << "\"" << std::endl; | 
|---|
| [2171] | 106 |             this->billboardSet_ = 0; | 
|---|
| [2087] | 107 |         } | 
|---|
 | 108 |  | 
|---|
 | 109 |         this->scenemanager_ = scenemanager; | 
|---|
 | 110 |     } | 
|---|
 | 111 |  | 
|---|
 | 112 |     void BillboardSet::destroyBillboardSet() | 
|---|
 | 113 |     { | 
|---|
 | 114 |         if (this->billboardSet_ && this->scenemanager_) | 
|---|
 | 115 |             this->scenemanager_->destroyBillboardSet(this->billboardSet_); | 
|---|
| [2171] | 116 |         this->billboardSet_ = 0; | 
|---|
| [2087] | 117 |     } | 
|---|
 | 118 |  | 
|---|
 | 119 |     const std::string& BillboardSet::getName() const | 
|---|
 | 120 |     { | 
|---|
| [1505] | 121 |         if (this->billboardSet_) | 
|---|
| [2087] | 122 |             return this->billboardSet_->getName(); | 
|---|
 | 123 |         else | 
|---|
 | 124 |             return BLANKSTRING; | 
|---|
| [1505] | 125 |     } | 
|---|
| [2087] | 126 |  | 
|---|
 | 127 |     void BillboardSet::setVisible(bool visible) | 
|---|
 | 128 |     { | 
|---|
 | 129 |         if (this->billboardSet_) | 
|---|
 | 130 |             this->billboardSet_->setVisible(visible); | 
|---|
 | 131 |     } | 
|---|
 | 132 |  | 
|---|
 | 133 |     bool BillboardSet::getVisible() const | 
|---|
 | 134 |     { | 
|---|
 | 135 |         if (this->billboardSet_) | 
|---|
 | 136 |             return this->billboardSet_->getVisible(); | 
|---|
 | 137 |         else | 
|---|
 | 138 |             return false; | 
|---|
 | 139 |     } | 
|---|
 | 140 |  | 
|---|
 | 141 |     void BillboardSet::setColour(const ColourValue& colour) | 
|---|
 | 142 |     { | 
|---|
 | 143 |         if (this->billboardSet_) | 
|---|
 | 144 |         { | 
|---|
 | 145 |             for (int i = 0; i < this->billboardSet_->getNumBillboards(); ++i) | 
|---|
 | 146 |                 this->billboardSet_->getBillboard(i)->setColour(colour); | 
|---|
 | 147 |         } | 
|---|
 | 148 |     } | 
|---|
 | 149 |  | 
|---|
 | 150 |     const ColourValue& BillboardSet::getColour() const | 
|---|
 | 151 |     { | 
|---|
 | 152 |         if (this->billboardSet_ && this->billboardSet_->getNumBillboards() > 0) | 
|---|
 | 153 |         { | 
|---|
 | 154 |             return this->billboardSet_->getBillboard(0)->getColour(); | 
|---|
 | 155 |         } | 
|---|
 | 156 |         else | 
|---|
 | 157 |             return ColourValue::White; | 
|---|
 | 158 |     } | 
|---|
 | 159 |  | 
|---|
 | 160 |     void BillboardSet::setMaterial(const std::string& material) | 
|---|
 | 161 |     { | 
|---|
 | 162 |         if (this->billboardSet_) | 
|---|
 | 163 |             this->billboardSet_->setMaterialName(material); | 
|---|
 | 164 |     } | 
|---|
 | 165 |  | 
|---|
 | 166 |     const std::string& BillboardSet::getMaterial() const | 
|---|
 | 167 |     { | 
|---|
 | 168 |         if (this->billboardSet_) | 
|---|
 | 169 |             return this->billboardSet_->getMaterialName(); | 
|---|
 | 170 |         else | 
|---|
 | 171 |             return BLANKSTRING; | 
|---|
 | 172 |     } | 
|---|
| [1505] | 173 | } | 
|---|