Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ogre1.9/src/modules/objects/Planet.cc @ 11128

Last change on this file since 11128 was 11128, checked in by landauf, 8 years ago

let Planet inherit from Model to avoid code duplication (especially lod levels).
since model is a static entity, all planets with rotation and/or dynamic physics need to be attached to a movableentity now.

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