Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lodfinal/src/orxonox/objects/worldentities/Planet.cc @ 2395

Last change on this file since 2395 was 2395, checked in by FelixSchulthess, 15 years ago

messing up planet so it will work in client mode

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