Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shaders/src/orxonox/graphics/LensFlare.cc @ 9445

Last change on this file since 9445 was 9445, checked in by davidsa, 11 years ago

Added orxonox::LensFlare, to add LensFlare effects, this is still very much WIP, still needs more flare components, more configurability and hardware occlusion queries

File size: 2.7 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 *      Reto Grieder (physics)
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30/**
31  @file LensFlare.cc
32  @brief Implementation of the LensFlare class.
33*/
34
35#include "LensFlare.h"
36
37#include "core/XMLPort.h"
38#include "graphics/Billboard.h"
39#include "CameraManager.h"
40
41namespace orxonox
42{
43    CreateFactory(LensFlare);
44   
45    LensFlare::LensFlare(BaseObject* creator) : StaticEntity(creator)
46    {
47        RegisterObject(LensFlare);
48       
49        this->createBillboards();
50       
51        this->registerVariables();
52    }
53
54    LensFlare::~LensFlare()
55    {
56    }
57
58    void LensFlare::XMLPort(Element& xmlelement, XMLPort::Mode mode)
59    {
60        SUPER(LensFlare, XMLPort, xmlelement, mode);
61    }
62   
63    void LensFlare::registerVariables()
64    {
65     
66    }
67   
68    void LensFlare::createBillboards()
69    {
70        Billboard* burst = new Billboard(this);
71        burst->setMaterial("lensflare/burst");
72        burst->setPosition(this->getPosition());
73        burst->setVisible(false);
74        this->attach(burst);
75    }
76   
77    void LensFlare::updateBillboardPositions()
78    {
79        Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera(); //get active Ogre Camera Instance, so we can check whether the light source is visible
80        bool lightIsVisible=camera->isVisible(this->getPosition()); //is the light source visible from our point of view?
81        int scale=camera->getPosition().distance(this->getPosition());
82       
83        Billboard* burst=static_cast<Billboard*>(getAttachedObject(0));
84        burst->setPosition(this->getPosition());
85        burst->setVisible(lightIsVisible);
86        burst->setDefaultDimensions(scale,scale);
87    }
88
89    void LensFlare::tick(float dt)
90    {
91        if(this->isVisible())
92        {
93            updateBillboardPositions();
94        }
95    }
96
97    void LensFlare::changedVisibility()
98    {
99    }
100}
Note: See TracBrowser for help on using the repository browser.