| [2072] | 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: | 
|---|
| [8706] | 25 |  *      Maurus Kaufmann | 
|---|
| [2072] | 26 |  * | 
|---|
 | 27 |  */ | 
|---|
 | 28 |  | 
|---|
 | 29 | #include "Billboard.h" | 
|---|
 | 30 |  | 
|---|
| [7491] | 31 | #include "OgreBillboard.h" | 
|---|
 | 32 |  | 
|---|
| [2072] | 33 | #include "core/CoreIncludes.h" | 
|---|
| [3196] | 34 | #include "core/GameMode.h" | 
|---|
| [2072] | 35 | #include "core/XMLPort.h" | 
|---|
| [5735] | 36 | #include "Scene.h" | 
|---|
| [2072] | 37 |  | 
|---|
 | 38 | namespace orxonox | 
|---|
 | 39 | { | 
|---|
| [9667] | 40 |     RegisterClass(Billboard); | 
|---|
| [2072] | 41 |  | 
|---|
| [9667] | 42 |     Billboard::Billboard(Context* context) : StaticEntity(context) | 
|---|
| [2072] | 43 |     { | 
|---|
 | 44 |         RegisterObject(Billboard); | 
|---|
 | 45 |  | 
|---|
| [2662] | 46 |         this->colour_ = ColourValue::White; | 
|---|
| [8706] | 47 |         this->rotation_ = 0; | 
|---|
| [2662] | 48 |  | 
|---|
| [2072] | 49 |         this->registerVariables(); | 
|---|
 | 50 |     } | 
|---|
 | 51 |  | 
|---|
 | 52 |     Billboard::~Billboard() | 
|---|
 | 53 |     { | 
|---|
 | 54 |         if (this->isInitialized()) | 
|---|
 | 55 |         { | 
|---|
 | 56 |             if (this->isInitialized() && this->billboard_.getBillboardSet()) | 
|---|
| [2662] | 57 |                 this->detachOgreObject(this->billboard_.getBillboardSet()); | 
|---|
| [2072] | 58 |         } | 
|---|
 | 59 |     } | 
|---|
 | 60 |  | 
|---|
 | 61 |     void Billboard::XMLPort(Element& xmlelement, XMLPort::Mode mode) | 
|---|
 | 62 |     { | 
|---|
 | 63 |         SUPER(Billboard, XMLPort, xmlelement, mode); | 
|---|
 | 64 |  | 
|---|
 | 65 |         XMLPortParam(Billboard, "material", setMaterial, getMaterial, xmlelement, mode); | 
|---|
 | 66 |         XMLPortParam(Billboard, "colour",   setColour,   getColour,   xmlelement, mode).defaultValues(ColourValue::White); | 
|---|
| [8706] | 67 |         XMLPortParam(Billboard, "rotation", setRotation, getRotation, xmlelement, mode).defaultValues(0); | 
|---|
| [2072] | 68 |     } | 
|---|
 | 69 |  | 
|---|
 | 70 |     void Billboard::registerVariables() | 
|---|
 | 71 |     { | 
|---|
| [3280] | 72 |         registerVariable(this->material_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedMaterial)); | 
|---|
 | 73 |         registerVariable(this->colour_,   VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedColour)); | 
|---|
| [8706] | 74 |         registerVariable(this->rotation_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedRotation)); | 
|---|
| [2072] | 75 |     } | 
|---|
 | 76 |  | 
|---|
 | 77 |     void Billboard::changedMaterial() | 
|---|
 | 78 |     { | 
|---|
| [6417] | 79 |         if (this->material_.empty()) | 
|---|
| [2662] | 80 |             return; | 
|---|
 | 81 |  | 
|---|
| [2072] | 82 |         if (!this->billboard_.getBillboardSet()) | 
|---|
 | 83 |         { | 
|---|
| [2896] | 84 |             if (this->getScene() && GameMode::showsGraphics()) | 
|---|
| [2072] | 85 |             { | 
|---|
 | 86 |                 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1); | 
|---|
| [2171] | 87 |                 if (this->billboard_.getBillboardSet()) | 
|---|
| [2662] | 88 |                      this->attachOgreObject(this->billboard_.getBillboardSet()); | 
|---|
| [2072] | 89 |                 this->billboard_.setVisible(this->isVisible()); | 
|---|
| [8706] | 90 |                 this->changedRotation(); | 
|---|
| [2072] | 91 |             } | 
|---|
 | 92 |         } | 
|---|
 | 93 |         else | 
|---|
 | 94 |             this->billboard_.setMaterial(this->material_); | 
|---|
 | 95 |     } | 
|---|
 | 96 |  | 
|---|
 | 97 |     void Billboard::changedColour() | 
|---|
 | 98 |     { | 
|---|
 | 99 |         if (!this->billboard_.getBillboardSet()) | 
|---|
 | 100 |         { | 
|---|
| [2662] | 101 | /* | 
|---|
| [6417] | 102 |             if (this->getScene() && GameMode::showsGraphics() && !this->material_.empty()) | 
|---|
| [2072] | 103 |             { | 
|---|
 | 104 |                 this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1); | 
|---|
| [2171] | 105 |                 if (this->billboard_.getBillboardSet()) | 
|---|
| [2662] | 106 |                     this->attachOgreObject(this->billboard_.getBillboardSet()); | 
|---|
| [2072] | 107 |                 this->billboard_.setVisible(this->isVisible()); | 
|---|
 | 108 |             } | 
|---|
| [2662] | 109 | */ | 
|---|
| [2072] | 110 |         } | 
|---|
 | 111 |         else | 
|---|
 | 112 |             this->billboard_.setColour(this->colour_); | 
|---|
 | 113 |     } | 
|---|
| [5735] | 114 |  | 
|---|
| [8706] | 115 |  | 
|---|
| [3053] | 116 |     void Billboard::changedRotation() | 
|---|
 | 117 |     { | 
|---|
 | 118 |         if (this->billboard_.getBillboardSet()) | 
|---|
| [7491] | 119 |         { | 
|---|
 | 120 |             Ogre::BillboardSet* set = this->billboard_.getBillboardSet(); | 
|---|
 | 121 |             set->setBillboardRotationType(Ogre::BBR_VERTEX); | 
|---|
 | 122 |             unsigned int size = set->getPoolSize(); | 
|---|
 | 123 |             for(unsigned int i = 0; i < size; i++) | 
|---|
 | 124 |             { | 
|---|
 | 125 |                 set->getBillboard(i)->setRotation(this->rotation_); | 
|---|
 | 126 |             } | 
|---|
 | 127 |         } | 
|---|
| [3053] | 128 |     } | 
|---|
| [2072] | 129 |  | 
|---|
| [8706] | 130 |  | 
|---|
| [2072] | 131 |     void Billboard::changedVisibility() | 
|---|
 | 132 |     { | 
|---|
 | 133 |         SUPER(Billboard, changedVisibility); | 
|---|
 | 134 |  | 
|---|
 | 135 |         this->billboard_.setVisible(this->isVisible()); | 
|---|
 | 136 |     } | 
|---|
| [8706] | 137 |      | 
|---|
 | 138 |     void Billboard::setBillboardType(Ogre::BillboardType bbt) | 
|---|
 | 139 |     { | 
|---|
 | 140 |         Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); | 
|---|
 | 141 |         if( bSet != NULL ) | 
|---|
 | 142 |         { | 
|---|
 | 143 |             bSet->setBillboardType(bbt); | 
|---|
 | 144 |         } | 
|---|
 | 145 |     } | 
|---|
 | 146 |      | 
|---|
 | 147 |     void Billboard::setCommonDirection(Vector3 vec) | 
|---|
 | 148 |     { | 
|---|
 | 149 |         Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); | 
|---|
 | 150 |         if( bSet != NULL ) | 
|---|
 | 151 |         { | 
|---|
 | 152 |             bSet->setCommonDirection( vec ); | 
|---|
 | 153 |         } | 
|---|
 | 154 |     } | 
|---|
 | 155 |              | 
|---|
 | 156 |     void Billboard::setCommonUpVector(Vector3 vec) | 
|---|
 | 157 |     { | 
|---|
 | 158 |         Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); | 
|---|
 | 159 |         if( bSet != NULL ) | 
|---|
 | 160 |         { | 
|---|
 | 161 |             bSet->setCommonUpVector( vec ); | 
|---|
 | 162 |         } | 
|---|
 | 163 |     } | 
|---|
 | 164 |      | 
|---|
 | 165 |     void Billboard::setDefaultDimensions(float width, float height) | 
|---|
 | 166 |     { | 
|---|
 | 167 |         Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet(); | 
|---|
 | 168 |         if( bSet != NULL ) | 
|---|
 | 169 |         { | 
|---|
 | 170 |             bSet->setDefaultDimensions(width, height); | 
|---|
 | 171 |         } | 
|---|
 | 172 |     } | 
|---|
| [2072] | 173 | } | 
|---|