Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/tools/BillboardSet.cc @ 2858

Last change on this file since 2858 was 2848, checked in by rgrieder, 16 years ago

Exported showsGraphics, etc. to a new class named GameMode in the core.

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