/* 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: * remartin * Co-authors: * ... * */ /** @file @author remartin @brief Asteroid field with lots of parameters. Derived from asteroidField.lua Generates a bunch of asteroids that may contain some stuff. It is required to wait until all XML-arguments are set. That's why the actual generation happens when tick() gets called for the first time. */ #include "SpicedAsteroidField.h" #include "AsteroidMinable.h" #include #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "util/Math.h" #include "graphics/Billboard.h" namespace orxonox{ RegisterClass(SpicedAsteroidField); SpicedAsteroidField::SpicedAsteroidField(Context* context) : BaseObject(context) { RegisterObject(SpicedAsteroidField); // Default Values: this->count = 30; this->mDensity = 0.5; this->position = Vector3(0,0,0); this->maxSize = 40; this->minSize = 1; this->radius = 1000; this->foggy = true; this->fogDensity = 0.5; } SpicedAsteroidField::~SpicedAsteroidField(){ } void SpicedAsteroidField::create(){ float size; float pX; float pY; float pZ; for(int gertrud = 0; gertrudgetContext()); size = roundf(rnd(this->maxSize - this->minSize)) + this->minSize; a->setSize(size); pX = roundf(rnd(2*this->radius)) - radius; pY = roundf(rnd(2*this->radius)) - radius; pZ = roundf(rnd(2*this->radius)) - radius; Vector3 relPos(pX, pY, pZ); a->setPosition(this->position + relPos); bool spiced = (rnd() < (this->mDensity)); // Whether the asteroid does drop pickups etc. a->setDropStuff(spiced); // Fog is iplemented with billboards (as in asteroidField.lua, that bloke had the idea) if(this->foggy && mod(gertrud, 5) == 0){ Billboard* bb = new Billboard(this->getContext()); bb->setPosition(this->position + relPos); bb->setMaterial("Smoke/Smoke"); bb->setScale(size); bb->setColour(ColourValue(this->fogDensity, this->fogDensity, this->fogDensity)); } } } void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode){ SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "position", setPosition, getPosition, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "maxSize", setMaxSize, getMaxSize, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "minSize", setMinSize, getMinSize, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode); XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode); } void SpicedAsteroidField::tick(float dt){ this->create(); this->destroyLater(); } }