Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/src/modules/objects/Planet.cc @ 12100

Last change on this file since 12100 was 11795, checked in by landauf, 7 years ago

merged ogre1.9 (including cegui0.8) into new branch

  • Property svn:eol-style set to native
File size: 3.9 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 *      Marian Runo
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "Planet.h"
30
31#include <OgreEntity.h>
32#include <OgreBillboardSet.h>
33
34#include "core/CoreIncludes.h"
35#include "core/GameMode.h"
36#include "core/XMLPort.h"
37#include "Scene.h"
38#include "graphics/Camera.h"
39#include "CameraManager.h"
40
41namespace orxonox
42{
43    RegisterClass(Planet);
44
45    /**
46     * @brief Constructor
47     */
48    Planet::Planet(Context* context) : Model(context)
49    {
50        RegisterObject(Planet);
51        this->setLodEnabled(false);
52        this->registerVariables();
53    }
54
55    /**
56     * @brief Destructor
57     */
58    Planet::~Planet()
59    {
60    }
61
62    void Planet::tick(float dt)
63    {
64        if (!this->isVisible())
65            return;
66
67        if (GameMode::showsGraphics())
68        {
69            Camera* activeCamera = CameraManager::getInstance().getActiveCamera();
70            if (activeCamera && this->billboard_.getBillboardSet())
71            {
72                float distance = this->getPosition().distance( activeCamera->getWorldPosition() );
73                //             orxout(internal_warning) << distance << endl;
74                float planetRadius = this->getScale();
75
76                float newScale = 2 * distance / sqrt(distance*distance - planetRadius*planetRadius);
77                float tempTest = newScale*(1+float(this->atmosphereSize)/float(this->imageSize));
78                newScale = tempTest;
79
80                this->billboard_.getBillboardSet()->setDefaultDimensions(newScale, newScale);
81            }
82        }
83
84        SUPER(Planet, tick, dt);
85    }
86
87    void Planet::changedAtmosphere()
88    {
89        if( GameMode::showsGraphics() )
90        {
91            if (this->getMesh().getEntity())
92            {
93                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0));
94
95                this->attachOgreObject(this->billboard_.getBillboardSet());
96                this->billboard_.getBillboardSet()->setUseAccurateFacing(true);
97                this->billboard_.getBillboardSet()->setRenderQueueGroup(this->getMesh().getEntity()->getRenderQueueGroup());
98            }
99        }
100    }
101
102    void Planet::XMLPort(Element& xmlelement, XMLPort::Mode mode)
103    {
104        SUPER(Planet, XMLPort, xmlelement, mode);
105
106        XMLPortParam(Planet, "atmosphere", setAtmosphere, getAtmosphere, xmlelement, mode).defaultValues("planet/Atmosphere");
107        XMLPortParam(Planet, "atmospheresize", setAtmosphereSize, getAtmosphereSize, xmlelement,mode);
108        XMLPortParam(Planet, "imagesize", setImageSize, getImageSize, xmlelement,mode);
109    }
110
111    void Planet::registerVariables()
112    {
113        registerVariable(this->atmosphere_, VariableDirection::ToClient, new NetworkCallback<Planet>(this, &Planet::changedAtmosphere));
114        registerVariable(this->atmosphereSize, VariableDirection::ToClient);
115        registerVariable(this->imageSize, VariableDirection::ToClient);
116    }
117
118    void Planet::changedVisibility()
119    {
120        SUPER(Planet, changedVisibility);
121
122        this->billboard_.setVisible(this->isVisible());
123    }
124}
Note: See TracBrowser for help on using the repository browser.