| [2053] | 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 | |
|---|
| 38 | #include <OgreEntity.h> |
|---|
| 39 | #include <OgreMesh.h> |
|---|
| 40 | #include <OgreHardwareVertexBuffer.h> |
|---|
| 41 | #include <OgreMeshManager.h> |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | namespace orxonox |
|---|
| 45 | { |
|---|
| 46 | CreateFactory(Planet); |
|---|
| 47 | |
|---|
| 48 | /** |
|---|
| 49 | * @brief Constructor |
|---|
| 50 | */ |
|---|
| 51 | Planet::Planet() |
|---|
| 52 | { |
|---|
| 53 | RegisterObject(Planet); |
|---|
| 54 | registerAllVariables(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | /** |
|---|
| 58 | * @brief Destructor |
|---|
| 59 | */ |
|---|
| 60 | Planet::~Planet() |
|---|
| 61 | { |
|---|
| 62 | if (this->isInitialized() && (this->meshSrc_ != "") && (this->meshSrc_.size() > 0)) |
|---|
| 63 | this->detachObject(this->mesh_.getEntity()); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | void Planet::init(){ |
|---|
| 67 | //std::vector<Real> newList; |
|---|
| 68 | //this->distList = &newList; |
|---|
| 69 | |
|---|
| 70 | //this->distList.push_back(3000.0); |
|---|
| 71 | //this->distList.push_back(6000.0); |
|---|
| 72 | //this->distList.push_back(48000.0); |
|---|
| 73 | this->distList.push_back(100000.0); |
|---|
| 74 | this->distList.push_back(125000.0); |
|---|
| 75 | this->distList.push_back(150000.0); |
|---|
| 76 | this->distList.push_back(175000.0); |
|---|
| 77 | this->distList.push_back(200000.0); |
|---|
| 78 | |
|---|
| 79 | Real reductionValue = 0.1; |
|---|
| 80 | |
|---|
| 81 | this->mesh_.getEntity()->getMesh()->generateLodLevels(distList, Ogre::ProgressiveMesh::VRQ_PROPORTIONAL, reductionValue); |
|---|
| 82 | //billboard_.setBillboardSet("Orxonox/Atmosphere", this->getPosition(), 1); |
|---|
| 83 | //this->getNode()->attachObject(this->billboard_.getBillboardSet()); |
|---|
| 84 | //this->billboard_.getBillboardSet()->setDefaultDimensions(Real(30000), Real(30000)); |
|---|
| 85 | |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | /** |
|---|
| 89 | @brief XML loading and saving. |
|---|
| 90 | @param xmlelement The XML-element |
|---|
| 91 | @param loading Loading (true) or saving (false) |
|---|
| 92 | @return The XML-element |
|---|
| 93 | */ |
|---|
| 94 | void Planet::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
|---|
| 95 | { |
|---|
| 96 | SUPER(Planet, XMLPort, xmlelement, mode); |
|---|
| 97 | |
|---|
| 98 | XMLPortParam(Planet, "mesh", setMesh, getMesh, xmlelement, mode); |
|---|
| 99 | |
|---|
| 100 | Planet::create(); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | bool Planet::create(){ |
|---|
| 104 | if(!WorldEntity::create()) |
|---|
| 105 | return false; |
|---|
| 106 | if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0)) |
|---|
| 107 | { |
|---|
| 108 | this->mesh_.setMesh(meshSrc_); |
|---|
| 109 | this->attachObject(this->mesh_.getEntity()); |
|---|
| 110 | |
|---|
| 111 | COUT(2) << "Loader (Planet.cc): Created model" << std::endl; |
|---|
| 112 | } |
|---|
| 113 | Planet::init(); |
|---|
| 114 | if(this->isExactlyA(Class(Planet))) |
|---|
| 115 | setObjectFrequency(300); //sync all 10 seconds (this only applies to asteroids and other isExactlyA(Model)'s |
|---|
| 116 | return true; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | void Planet::registerAllVariables(){ |
|---|
| 120 | // WorldEntity::registerAllVariables(); |
|---|
| 121 | COUT(5) << "Planet.cc:registering new meshsrc with size: " << meshSrc_.length()+1 << " this: " << this << std::endl; |
|---|
| 122 | registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | void Planet::changedVisibility() |
|---|
| 126 | { |
|---|
| 127 | SUPER(Planet, changedVisibility); |
|---|
| 128 | if (this->isInitialized()) |
|---|
| 129 | this->mesh_.setVisible(this->isVisible()); |
|---|
| 130 | this->billboard_.setVisible(this->isVisible()); |
|---|
| 131 | } |
|---|
| 132 | } |
|---|