Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/Backlight.cc @ 1702

Last change on this file since 1702 was 1608, checked in by landauf, 16 years ago
  • added a backlight to all SpaceShips, leaving a trail behind (configurable)
  • changed some lines in SpaceShipAI, AI seems to be more fair now…
  • fixed a bug in Math.cc algorithms to calculate radar positions and AI movement (division by zero and acos of 1.000001)
  • added destroy() and destroydelay to ParticleSpawner, so the smoketrail of a destroyed enemy stays visible for some seconds
  • added 2 lines to Orxonox.cc to make the length of the backlight-trail independend of the gamespeed

########################
# !!! MEDIA UPDATE !!! #
########################

  • Property svn:eol-style set to native
File size: 5.5 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 "Backlight.h"
31
32#include <OgreBillboard.h>
33#include <OgreRibbonTrail.h>
34
35#include "core/CoreIncludes.h"
36#include "core/ConfigValueIncludes.h"
37#include "core/Executor.h"
38#include "util/Math.h"
39#include "GraphicsEngine.h"
40#include "Orxonox.h"
41
42namespace orxonox
43{
44    CreateFactory(Backlight);
45
46    float Backlight::timeFactor_s = 1.0;
47
48    Backlight::Backlight(float maxspeed, float brakingtime, float scale)
49    {
50        RegisterObject(Backlight);
51
52        this->setConfigValues();
53        this->traillength_ = 1;
54
55        this->getNode()->setInheritScale(false);
56
57        this->billboard_.setBillboardSet("Flares/backlightflare");
58        this->attachObject(this->billboard_.getBillboardSet());
59
60        this->ribbonTrail_ = GraphicsEngine::getSingleton().getSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail");
61        this->ribbonTrailNode_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode");
62        this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
63        this->ribbonTrail_->addNode(this->getNode());
64
65        this->configure(maxspeed, brakingtime, scale);
66
67        this->ribbonTrail_->setTrailLength(this->maxTraillength_);
68        this->ribbonTrail_->setMaterialName("Trail/backlighttrail");
69
70        this->setTimeFactor(Orxonox::getSingleton()->getTimeFactor());
71    }
72
73    Backlight::~Backlight()
74    {
75        if (this->isInitialized())
76        {
77            this->detachObject(this->billboard_.getBillboardSet());
78            GraphicsEngine::getSingleton().getSceneManager()->destroySceneNode(this->getName() + "RibbonTrailNode");
79            GraphicsEngine::getSingleton().getSceneManager()->destroyRibbonTrail(this->ribbonTrail_);
80        }
81    }
82
83    void Backlight::setConfigValues()
84    {
85        SetConfigValue(maxLifeTime_, 4.0).description("The maximal amount of seconds the trail behind a SpaceShip stays visible");
86        SetConfigValue(trailSegmentLength_, 50).description("The length of one segment of the trail behind a SpaceShip (lower values make it more smooth)");
87        SetConfigValue(width_, 7.0).description("The width of the trail");
88    }
89
90    void Backlight::setTimeFactor(float factor)
91    {
92        Backlight::timeFactor_s = factor;
93        float change = Backlight::timeFactor_s / this->maxLifeTime_;
94        this->ribbonTrail_->setWidthChange(0, this->width_ * change);
95        this->updateColourChange();
96    }
97
98    void Backlight::updateColourChange()
99    {
100        this->ribbonTrail_->setColourChange(0, ColourValue(0, 0, 0, this->maxTraillength_ / this->traillength_ / this->maxLifeTime_ * Backlight::timeFactor_s));
101    }
102
103    void Backlight::tick(float dt)
104    {
105        WorldEntity::tick(dt);
106
107        if (this->isActive())
108        {
109            if (this->traillength_ < this->maxTraillength_)
110            {
111                this->traillength_ = min<float>(this->maxTraillength_, this->traillength_ + dt * this->maxTraillength_ / this->maxLifeTime_);
112                this->updateColourChange();
113            }
114        }
115        else
116        {
117            if (this->traillength_ > 1)
118            {
119                this->traillength_ = max<float>(1, this->traillength_ - this->brakefactor_ * dt * this->maxTraillength_ / this->maxLifeTime_);
120                this->updateColourChange();
121            }
122        }
123
124        this->ribbonTrail_->setTrailLength(this->traillength_);
125    }
126
127    void Backlight::setColour(const ColourValue& colour)
128    {
129        this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
130        this->ribbonTrail_->setInitialColour(0, ColourValue(colour.r / 4 + 0.75, colour.g / 4 + 0.75, colour.b / 4 + 0.75));
131    }
132
133    void Backlight::configure(float maxspeed, float brakingtime, float scale)
134    {
135        this->maxTraillength_ = this->maxLifeTime_ * maxspeed;
136        this->maxTrailsegments_ = (size_t)(this->maxTraillength_ / this->trailSegmentLength_);
137        this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_);
138        this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_);
139
140        this->brakefactor_ = this->maxLifeTime_ / brakingtime;
141
142        this->scale(scale);
143        this->ribbonTrail_->setInitialWidth(0, this->width_ * scale);
144        this->ribbonTrail_->setWidthChange(0, this->width_ * scale / this->maxLifeTime_ * Backlight::timeFactor_s);
145    }
146
147    void Backlight::changedVisibility()
148    {
149        WorldEntity::changedVisibility();
150
151        this->billboard_.setVisible(this->isVisible());
152        this->ribbonTrail_->setVisible(this->isVisible());
153    }
154}
Note: See TracBrowser for help on using the repository browser.