Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/worldentities/Planet.cc @ 3099

Last change on this file since 3099 was 2896, checked in by landauf, 16 years ago

Merged gui branch back to trunk.

I did 2 small changes in IngameManager.cc on line 777 and 888 (yes, really), because const_reverse_iterator strangely doesn't work on MinGW.

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