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