Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/orxonox/tools/BillboardSet.cc @ 2425

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