Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/objects/Planet.cc @ 5916

Last change on this file since 5916 was 5781, checked in by rgrieder, 15 years ago

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

  • Property svn:eol-style set to native
File size: 5.9 KB
RevLine 
[2380]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>
[2459]32#include <OgreBillboardSet.h>
[3196]33#include <OgreProgressiveMesh.h>
[2380]34
[2435]35#include "core/CoreIncludes.h"
[3196]36#include "core/GameMode.h"
[2435]37#include "core/XMLPort.h"
[5735]38#include "Scene.h"
[5737]39#include "graphics/Camera.h"
[2435]40#include "CameraManager.h"
[2380]41
42namespace orxonox
43{
[5730]44    CreateFactory(Planet);
[2380]45
46    /**
47     * @brief Constructor
48     */
49    Planet::Planet(BaseObject* creator): MovableEntity(creator)
50    {
51        RegisterObject(Planet);
52        this->registerVariables();
53    }
54
55    /**
56     * @brief Destructor
57     */
58    Planet::~Planet()
59    {
60        if (this->isInitialized() && this->mesh_.getEntity())
[2459]61            this->detachOgreObject(this->mesh_.getEntity());
[5730]62    }
[2435]63
[2380]64    void Planet::tick(float dt)
65    {
66        if(!this->isVisible())
67            return;
[2435]68
[3196]69        if (GameMode::showsGraphics())
[2435]70        {
[3196]71            Camera* activeCamera = CameraManager::getInstance().getActiveCamera();
72            if(activeCamera)
73            {
74                float distance = this->getPosition().distance( activeCamera->getWorldPosition() );
75                //             COUT(2) << distance << std::endl;
76                float planetRadius = this->getScale();
[2435]77
[3196]78                float newScale = 2 * distance / sqrt(distance*distance - planetRadius*planetRadius);
79                float tempTest = newScale*(1+float(this->atmosphereSize)/float(this->imageSize));
80                newScale = tempTest;
[2435]81
[3196]82                this->billboard_.getBillboardSet()->setDefaultDimensions(newScale, newScale);
83            }
[2435]84        }
85
[2380]86        SUPER(Planet, tick, dt);
87    }
[2435]88
89    void Planet::init()
90    {
[2710]91        float scaleFactor = this->getScale();
[2435]92
[3196]93        this->distList.push_back(10.0f*scaleFactor);
94        this->distList.push_back(19.0f*scaleFactor);
95        this->distList.push_back(27.0f*scaleFactor);
96        this->distList.push_back(34.0f*scaleFactor);
97        this->distList.push_back(40.0f*scaleFactor);
98        this->distList.push_back(45.0f*scaleFactor);
99        this->distList.push_back(49.0f*scaleFactor);
100        this->distList.push_back(52.0f*scaleFactor);
101        this->distList.push_back(54.0f*scaleFactor);
102        this->distList.push_back(55.0f*scaleFactor);
[2435]103
[3196]104        float reductionValue = 0.2f;
[2435]105
[2380]106        this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue);
107        billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0));
[2435]108
[5730]109        this->attachOgreObject(this->billboard_.getBillboardSet());
[2380]110        this->billboard_.getBillboardSet()->setUseAccurateFacing(true);
111        this->setCastShadows(true);
112        this->billboard_.getBillboardSet()->setRenderQueueGroup(this->mesh_.getEntity()->getRenderQueueGroup());
113        this->mesh_.setCastShadows(true);
114    }
[2435]115
[2380]116    void Planet::changedMesh()
117    {
118        if (this->mesh_.getEntity())
[2459]119            this->detachOgreObject(this->mesh_.getEntity());
[2380]120
121        this->mesh_.setMeshSource(this->getScene()->getSceneManager(), this->meshSrc_);
122
123        if (this->mesh_.getEntity())
124        {
[2459]125            this->attachOgreObject(this->mesh_.getEntity());
[2380]126            this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
127            this->mesh_.setVisible(this->isVisible());
128        }
129        this->init();
130    }
131
132    void Planet::changedShadows()
133    {
134        this->mesh_.setCastShadows(this->bCastShadows_);
135    }
136
137    /**
138        @brief XML loading and saving.
139        @param xmlelement The XML-element
140        @param loading Loading (true) or saving (false)
141        @return The XML-element
142    */
143    void Planet::XMLPort(Element& xmlelement, XMLPort::Mode mode)
144    {
145        SUPER(Planet, XMLPort, xmlelement, mode);
[2435]146
[3196]147        if (GameMode::showsGraphics())
148        {
149            XMLPortParam(Planet, "atmosphere", setAtmosphere, getAtmosphere, xmlelement, mode).defaultValues("planet/Atmosphere");
[5730]150            XMLPortParam(Planet, "atmospheresize", setAtmosphereSize, getAtmosphereSize, xmlelement,mode);
151            XMLPortParam(Planet, "imagesize", setImageSize, getImageSize, xmlelement,mode);
[3196]152            XMLPortParam(Planet, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
153            XMLPortParam(Planet, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
154        }
[2380]155    }
156
[2435]157    void Planet::registerVariables()
158    {
[3280]159        registerVariable(this->atmosphere_, VariableDirection::ToClient);
160        registerVariable(this->meshSrc_, VariableDirection::ToClient, new NetworkCallback<Planet>(this, &Planet::changedMesh));
161        registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Planet>(this, &Planet::changedShadows));
162        registerVariable(this->atmosphereSize, VariableDirection::ToClient);
163        registerVariable(this->imageSize, VariableDirection::ToClient);
[2380]164    }
165
166    void Planet::changedVisibility()
167    {
168        SUPER(Planet, changedVisibility);
169        if (this->isInitialized())
[2435]170        {
[2380]171            this->mesh_.setVisible(this->isVisible());
172            this->billboard_.setVisible(this->isVisible());
[2435]173        }
[2380]174    }
175}
Note: See TracBrowser for help on using the repository browser.