Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/MouseAPI_FS19/src/libraries/tools/BillboardSet.cc @ 12394

Last change on this file since 12394 was 11087, checked in by landauf, 9 years ago

removed duplicate code

  • Property svn:eol-style set to native
File size: 4.6 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 "BillboardSet.h"
30
31#include <cassert>
32#include <string>
33#include <sstream>
34#include <OgreSceneManager.h>
35#include <OgreBillboardSet.h>
36#include <OgreBillboard.h>
37
38#include "util/Convert.h"
39#include "util/Math.h"
40#include "core/GameMode.h"
41
42namespace orxonox
43{
44    unsigned int BillboardSet::billboardSetCounter_s = 0;
45
46    BillboardSet::BillboardSet()
47    {
48        this->billboardSet_ = nullptr;
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        this->setBillboardSet(scenemanager, file, ColourValue::White, position, count);
69    }
70
71    void BillboardSet::setBillboardSet(Ogre::SceneManager* scenemanager, const std::string& file, const ColourValue& colour, const Vector3& position, int count)
72    {
73        assert(scenemanager);
74        this->destroyBillboardSet();
75
76        try
77        {
78            if (GameMode::showsGraphics())
79            {
80                this->billboardSet_ = scenemanager->createBillboardSet("Billboard" + multi_cast<std::string>(BillboardSet::billboardSetCounter_s++), count);
81                this->billboardSet_->createBillboard(position, colour);
82                this->billboardSet_->setMaterialName(file);
83            }
84        }
85        catch (...)
86        {
87            orxout(internal_error) << "Couldn't load billboard \"" << file << '"' << endl;
88            this->billboardSet_ = nullptr;
89        }
90
91        this->scenemanager_ = scenemanager;
92    }
93
94    void BillboardSet::destroyBillboardSet()
95    {
96        if (this->billboardSet_ && this->scenemanager_)
97            this->scenemanager_->destroyBillboardSet(this->billboardSet_);
98        this->billboardSet_ = nullptr;
99    }
100
101    const std::string& BillboardSet::getName() const
102    {
103        if (this->billboardSet_)
104            return this->billboardSet_->getName();
105        else
106            return BLANKSTRING;
107    }
108
109    void BillboardSet::setVisible(bool visible)
110    {
111        if (this->billboardSet_)
112            this->billboardSet_->setVisible(visible);
113    }
114
115    bool BillboardSet::getVisible() const
116    {
117        if (this->billboardSet_)
118            return this->billboardSet_->getVisible();
119        else
120            return false;
121    }
122
123    void BillboardSet::setColour(const ColourValue& colour)
124    {
125        if (this->billboardSet_)
126        {
127            for (int i = 0; i < this->billboardSet_->getNumBillboards(); ++i)
128                this->billboardSet_->getBillboard(i)->setColour(colour);
129        }
130    }
131
132    const ColourValue& BillboardSet::getColour() const
133    {
134        if (this->billboardSet_ && this->billboardSet_->getNumBillboards() > 0)
135        {
136            return this->billboardSet_->getBillboard(0)->getColour();
137        }
138        else
139            return ColourValue::White;
140    }
141
142    void BillboardSet::setMaterial(const std::string& material)
143    {
144        if (this->billboardSet_)
145            this->billboardSet_->setMaterialName(material);
146    }
147
148    const std::string& BillboardSet::getMaterial() const
149    {
150        if (this->billboardSet_)
151            return this->billboardSet_->getMaterialName();
152        else
153            return BLANKSTRING;
154    }
155}
Note: See TracBrowser for help on using the repository browser.