Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/levelMichael/src/orxonox/graphics/Billboard.cc @ 9870

Last change on this file since 9870 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
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 *      Maurus Kaufmann
26 *
27 */
28
29#include "Billboard.h"
30
31#include "OgreBillboard.h"
32
33#include "core/CoreIncludes.h"
34#include "core/GameMode.h"
35#include "core/XMLPort.h"
36#include "Scene.h"
37
38namespace orxonox
39{
40    RegisterClass(Billboard);
41
42    Billboard::Billboard(Context* context) : StaticEntity(context)
43    {
44        RegisterObject(Billboard);
45
46        this->colour_ = ColourValue::White;
47        this->rotation_ = 0;
48
49        this->registerVariables();
50    }
51
52    Billboard::~Billboard()
53    {
54        if (this->isInitialized())
55        {
56            if (this->isInitialized() && this->billboard_.getBillboardSet())
57                this->detachOgreObject(this->billboard_.getBillboardSet());
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);
67        XMLPortParam(Billboard, "rotation", setRotation, getRotation, xmlelement, mode).defaultValues(0);
68    }
69
70    void Billboard::registerVariables()
71    {
72        registerVariable(this->material_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedMaterial));
73        registerVariable(this->colour_,   VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedColour));
74        registerVariable(this->rotation_, VariableDirection::ToClient, new NetworkCallback<Billboard>(this, &Billboard::changedRotation));
75    }
76
77    void Billboard::changedMaterial()
78    {
79        if (this->material_.empty())
80            return;
81
82        if (!this->billboard_.getBillboardSet())
83        {
84            if (this->getScene() && GameMode::showsGraphics())
85            {
86                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
87                if (this->billboard_.getBillboardSet())
88                     this->attachOgreObject(this->billboard_.getBillboardSet());
89                this->billboard_.setVisible(this->isVisible());
90                this->changedRotation();
91            }
92        }
93        else
94            this->billboard_.setMaterial(this->material_);
95    }
96
97    void Billboard::changedColour()
98    {
99        if (!this->billboard_.getBillboardSet())
100        {
101/*
102            if (this->getScene() && GameMode::showsGraphics() && !this->material_.empty())
103            {
104                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
105                if (this->billboard_.getBillboardSet())
106                    this->attachOgreObject(this->billboard_.getBillboardSet());
107                this->billboard_.setVisible(this->isVisible());
108            }
109*/
110        }
111        else
112            this->billboard_.setColour(this->colour_);
113    }
114
115
116    void Billboard::changedRotation()
117    {
118        if (this->billboard_.getBillboardSet())
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        }
128    }
129
130
131    void Billboard::changedVisibility()
132    {
133        SUPER(Billboard, changedVisibility);
134
135        this->billboard_.setVisible(this->isVisible());
136    }
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    }
173}
Note: See TracBrowser for help on using the repository browser.