Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/tools/BillboardSet.cc @ 2092

Last change on this file since 2092 was 2087, checked in by landauf, 16 years ago

merged objecthierarchy branch back to trunk

  • Property svn:eol-style set to native
File size: 4.8 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 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "BillboardSet.h"
31
32#include <sstream>
33#include <cassert>
34
35#include <OgreSceneManager.h>
36#include <OgreBillboard.h>
37
38#include "util/Convert.h"
39#include "util/String.h"
40
41namespace orxonox
42{
43    unsigned int BillboardSet::billboardSetCounter_s = 0;
44
45    BillboardSet::BillboardSet()
46    {
47        this->billboardSet_ = 0;
48    }
49
50    BillboardSet::~BillboardSet()
51    {
52        this->destroyBillboardSet();
53    }
54
55    void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, int count)
56    {
57        this->setBillboardSet(scenemanager, file, Vector3::ZERO, count);
58    }
59
60    void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, int count)
61    {
62        this->setBillboardSet(scenemanager, file, colour, Vector3::ZERO, count);
63    }
64
65    void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const Vector3& position, int count)
66    {
67        assert(scenemanager);
68        this->destroyBillboardSet();
69
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        }
80
81        this->scenemanager_ = scenemanager;
82    }
83
84    void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, const Vector3& position, int count)
85    {
86        assert(scenemanager);
87        this->destroyBillboardSet();
88
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        }
99
100        this->scenemanager_ = scenemanager;
101    }
102
103    void BillboardSet::destroyBillboardSet()
104    {
105        if (this->billboardSet_ && this->scenemanager_)
106            this->scenemanager_->destroyBillboardSet(this->billboardSet_);
107    }
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    }
163}
Note: See TracBrowser for help on using the repository browser.