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