/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Marian Runo * Co-authors: * ... * */ #include "Planet.h" #include #include #include "core/CoreIncludes.h" #include "core/GameMode.h" #include "core/XMLPort.h" #include "Scene.h" #include "graphics/Camera.h" #include "CameraManager.h" namespace orxonox { RegisterClass(Planet); /** * @brief Constructor */ Planet::Planet(Context* context) : Model(context) { RegisterObject(Planet); this->setLodEnabled(false); this->registerVariables(); } /** * @brief Destructor */ Planet::~Planet() { } void Planet::tick(float dt) { if (!this->isVisible()) return; if (GameMode::showsGraphics()) { Camera* activeCamera = CameraManager::getInstance().getActiveCamera(); if (activeCamera && this->billboard_.getBillboardSet()) { float distance = this->getPosition().distance( activeCamera->getWorldPosition() ); // orxout(internal_warning) << distance << endl; float planetRadius = this->getScale(); float newScale = 2 * distance / sqrt(distance*distance - planetRadius*planetRadius); float tempTest = newScale*(1+float(this->atmosphereSize)/float(this->imageSize)); newScale = tempTest; this->billboard_.getBillboardSet()->setDefaultDimensions(newScale, newScale); } } SUPER(Planet, tick, dt); } void Planet::changedAtmosphere() { if( GameMode::showsGraphics() ) { if (this->getMesh().getEntity()) { this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->atmosphere_, Vector3(0,0,0)); this->attachOgreObject(this->billboard_.getBillboardSet()); this->billboard_.getBillboardSet()->setUseAccurateFacing(true); this->billboard_.getBillboardSet()->setRenderQueueGroup(this->getMesh().getEntity()->getRenderQueueGroup()); } } } void Planet::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(Planet, XMLPort, xmlelement, mode); XMLPortParam(Planet, "atmosphere", setAtmosphere, getAtmosphere, xmlelement, mode).defaultValues("planet/Atmosphere"); XMLPortParam(Planet, "atmospheresize", setAtmosphereSize, getAtmosphereSize, xmlelement,mode); XMLPortParam(Planet, "imagesize", setImageSize, getImageSize, xmlelement,mode); } void Planet::registerVariables() { registerVariable(this->atmosphere_, VariableDirection::ToClient, new NetworkCallback(this, &Planet::changedAtmosphere)); registerVariable(this->atmosphereSize, VariableDirection::ToClient); registerVariable(this->imageSize, VariableDirection::ToClient); } void Planet::changedVisibility() { SUPER(Planet, changedVisibility); this->billboard_.setVisible(this->isVisible()); } }