Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidField.cc @ 11800

Last change on this file since 11800 was 11781, checked in by landauf, 7 years ago

eol-style native (no changes in code)

  • Property svn:eol-style set to native
File size: 4.2 KB
RevLine 
[11610]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:
[11741]23 *      remartin
[11610]24 *   Co-authors:
[11741]25 *      ...
[11610]26 *
27 */
28
[11664]29/**
[11610]30
[11667]31    @file
32    @author remartin
[11664]33    @brief Asteroid field with lots of parameters. Derived from asteroidField.lua
[11610]34
[11667]35    Generates a bunch of asteroids that may contain some stuff.
36    It is required to wait until all XML-arguments are set. That's why the actual
37    generation happens when tick() gets called for the first time.
38   
[11610]39*/
40
41
42#include "SpicedAsteroidField.h"
[11615]43#include "AsteroidMinable.h"
[11610]44
45#include <algorithm>
46
47#include "core/CoreIncludes.h"
48#include "core/XMLPort.h"
[11615]49#include "util/Math.h"
[11610]50
[11736]51#include "graphics/Billboard.h"
[11610]52
53
[11664]54namespace orxonox{
[11615]55
[11610]56    RegisterClass(SpicedAsteroidField);
57
[11736]58    SpicedAsteroidField::SpicedAsteroidField(Context* context) : BaseObject(context) {
[11610]59
60        RegisterObject(SpicedAsteroidField);
61
[11664]62        // Default Values:
63        this->count = 30; 
64        this->mDensity = 0.5;
65        this->position = Vector3(0,0,0);
66        this->maxSize = 40; 
67        this->minSize = 1; 
68        this->radius = 1000;
[11640]69        this->foggy = true; 
70        this->fogDensity = 0.5;
[11664]71    }
[11610]72
73    SpicedAsteroidField::~SpicedAsteroidField(){
74
75    }
76
77    void SpicedAsteroidField::create(){
78
[11739]79        float size;
80        float pX;
81        float pY;
82        float pZ;
[11610]83
[11640]84        for(int gertrud = 0; gertrud<count; ++gertrud){
[11610]85
[11736]86            AsteroidMinable* a = new AsteroidMinable(this->getContext());
[11640]87
[11739]88            size = roundf(rnd(this->maxSize - this->minSize)) + this->minSize;
[11667]89            a->setSize(size); 
90
[11739]91            pX = roundf(rnd(2*this->radius)) - radius;
92            pY = roundf(rnd(2*this->radius)) - radius;
93            pZ = roundf(rnd(2*this->radius)) - radius;
[11735]94            Vector3 relPos(pX, pY, pZ);
95            a->setPosition(this->position + relPos);
[11640]96
[11667]97            bool spiced = (rnd() < (this->mDensity)); // Whether the asteroid does drop pickups etc.
[11736]98            a->setDropStuff(spiced);
[11664]99           
[11667]100            // Fog is iplemented with billboards (as in asteroidField.lua, that bloke had the idea)
[11664]101            if(this->foggy && mod(gertrud, 5) == 0){
[11736]102                Billboard* bb = new Billboard(this->getContext());
[11735]103                bb->setPosition(this->position + relPos);
[11664]104                bb->setMaterial("Smoke/Smoke");
105                bb->setScale(size);
106                bb->setColour(ColourValue(this->fogDensity, this->fogDensity, this->fogDensity));   
107            }
[11640]108        }
[11610]109    }
110
[11664]111    void SpicedAsteroidField::XMLPort(Element& xmlelement, XMLPort::Mode mode){
112
113        SUPER(SpicedAsteroidField, XMLPort, xmlelement, mode); 
114
[11615]115        XMLPortParam(SpicedAsteroidField, "count", setCount, getCount, xmlelement, mode);
116        XMLPortParam(SpicedAsteroidField, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode);
117        XMLPortParam(SpicedAsteroidField, "position", setPosition, getPosition, xmlelement, mode);
118        XMLPortParam(SpicedAsteroidField, "maxSize", setMaxSize, getMaxSize, xmlelement, mode);
119        XMLPortParam(SpicedAsteroidField, "minSize", setMinSize, getMinSize, xmlelement, mode);
120        XMLPortParam(SpicedAsteroidField, "radius", setRadius, getRadius, xmlelement, mode);
121        XMLPortParam(SpicedAsteroidField, "foggy", setFog, isFoggy, xmlelement, mode);
[11640]122        XMLPortParam(SpicedAsteroidField, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode);
[11610]123
124    }
125
[11640]126    void SpicedAsteroidField::tick(float dt){
[11610]127
[11640]128        this->create();
129        this->destroyLater();
[11610]130    }
131
[11640]132}
Note: See TracBrowser for help on using the repository browser.