| 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 |  *      remartin | 
|---|
| 24 |  *   Co-authors: | 
|---|
| 25 |  *      ... | 
|---|
| 26 |  * | 
|---|
| 27 |  */ | 
|---|
| 28 |  | 
|---|
| 29 | /** | 
|---|
| 30 |  | 
|---|
| 31 |     @file  | 
|---|
| 32 |     @author remartin | 
|---|
| 33 |     @brief Asteroid belt with lots of parameters. Derived from asteroidField.lua | 
|---|
| 34 |  | 
|---|
| 35 |     Generates a ring of asteroids by calling SpicedAsteroidField multiple times.  | 
|---|
| 36 |     It's in the xy-plane at default, orientation can be changed with tiltAt  | 
|---|
| 37 |     (angle where it gets elevated/lowered the most) and TiltBy (angle at z-axis).  | 
|---|
| 38 |     This doesn't work very well and could probably implemented differently with  | 
|---|
| 39 |     relative coordinates (attach etc, stuff in WorldEntity).  | 
|---|
| 40 |  | 
|---|
| 41 |     It is required to wait until all XML-arguments are set. That's why the actual  | 
|---|
| 42 |     generation happens when tick() gets called for the first time.  | 
|---|
| 43 |      | 
|---|
| 44 | */ | 
|---|
| 45 |  | 
|---|
| 46 |  | 
|---|
| 47 | #include "SpicedAsteroidBelt.h" | 
|---|
| 48 | #include "SpicedAsteroidField.h" | 
|---|
| 49 |  | 
|---|
| 50 | #include <algorithm> | 
|---|
| 51 |  | 
|---|
| 52 | #include "core/CoreIncludes.h" | 
|---|
| 53 | #include "core/XMLPort.h" | 
|---|
| 54 | #include "util/Math.h" | 
|---|
| 55 |  | 
|---|
| 56 | namespace orxonox{ | 
|---|
| 57 |  | 
|---|
| 58 |     RegisterClass(SpicedAsteroidBelt); | 
|---|
| 59 |  | 
|---|
| 60 |     SpicedAsteroidBelt::SpicedAsteroidBelt(Context* context) : BaseObject(context) { | 
|---|
| 61 |  | 
|---|
| 62 |         RegisterObject(SpicedAsteroidBelt); | 
|---|
| 63 |  | 
|---|
| 64 |         // Default Values: | 
|---|
| 65 |         this->count = 250;  | 
|---|
| 66 |         this->position = Vector3(0,0,0); | 
|---|
| 67 |         this->segments = 30; | 
|---|
| 68 |         this->minSize = 1; | 
|---|
| 69 |         this->maxSize = 50; | 
|---|
| 70 |         this->radius0 = 7190; | 
|---|
| 71 |         this->radius1 = 7800; | 
|---|
| 72 |  | 
|---|
| 73 |         this->mDensity = 0.3; | 
|---|
| 74 |         this->foggy = true; | 
|---|
| 75 |         this->fogDensity = 0.5; | 
|---|
| 76 |  | 
|---|
| 77 |         this->tiltAt = 0.0;  | 
|---|
| 78 |         this->tiltBy = 0.0;   | 
|---|
| 79 |  | 
|---|
| 80 |     } | 
|---|
| 81 |  | 
|---|
| 82 |     SpicedAsteroidBelt::~SpicedAsteroidBelt(){ | 
|---|
| 83 |  | 
|---|
| 84 |     } | 
|---|
| 85 |  | 
|---|
| 86 |     void SpicedAsteroidBelt::create(){ | 
|---|
| 87 |  | 
|---|
| 88 |         float myPi = math::pi; | 
|---|
| 89 |         float width = fabs(this->radius1 - this->radius0); | 
|---|
| 90 |         float radius = (this->radius1 + this->radius0) / 2.0f; | 
|---|
| 91 |         int segmentCount = (int)roundf(this->count / this->segments); | 
|---|
| 92 |  | 
|---|
| 93 |         float dPhi = (2 * myPi) / this->segments; | 
|---|
| 94 |         float dTheta = 4.0f*this->tiltBy/this->segments; | 
|---|
| 95 |         float sepp = -this->tiltAt; | 
|---|
| 96 |         float globi = (myPi/2.0f) + this->tiltBy; | 
|---|
| 97 |  | 
|---|
| 98 |         for(int s = 0; s<segments; ++s){ | 
|---|
| 99 |             sepp = sepp + dPhi; | 
|---|
| 100 |             if(s<segments/2){             | 
|---|
| 101 |                 globi = globi - dTheta;  | 
|---|
| 102 |             }else{ | 
|---|
| 103 |                 globi = globi + dTheta;  | 
|---|
| 104 |             } | 
|---|
| 105 |              | 
|---|
| 106 |             Vector3 pos(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi)); | 
|---|
| 107 |  | 
|---|
| 108 |             SpicedAsteroidField* field = new SpicedAsteroidField(this->getContext()); | 
|---|
| 109 |             field->setPosition(this->position + pos); | 
|---|
| 110 |             field->setMinSize(this->minSize); | 
|---|
| 111 |             field->setMaxSize(this->maxSize); | 
|---|
| 112 |             field->setRadius(width); | 
|---|
| 113 |             field->setCount(segmentCount); | 
|---|
| 114 |             field->setFog(this->foggy); | 
|---|
| 115 |             field->setMineralDensity(this->mDensity); | 
|---|
| 116 |             field->setFogDensity(this->fogDensity); | 
|---|
| 117 |         } | 
|---|
| 118 |     } | 
|---|
| 119 |  | 
|---|
| 120 |     void SpicedAsteroidBelt::XMLPort(Element& xmlelement, XMLPort::Mode mode){ | 
|---|
| 121 |  | 
|---|
| 122 |         SUPER(SpicedAsteroidBelt, XMLPort, xmlelement, mode);  | 
|---|
| 123 |  | 
|---|
| 124 |         XMLPortParam(SpicedAsteroidBelt, "count", setCount, getCount, xmlelement, mode); | 
|---|
| 125 |         XMLPortParam(SpicedAsteroidBelt, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode); | 
|---|
| 126 |         XMLPortParam(SpicedAsteroidBelt, "position", setPosition, getPosition, xmlelement, mode); | 
|---|
| 127 |         XMLPortParam(SpicedAsteroidBelt, "segments", setSegments, getSegments, xmlelement, mode); | 
|---|
| 128 |  | 
|---|
| 129 |         XMLPortParam(SpicedAsteroidBelt, "maxSize", setMaxSize, getMaxSize, xmlelement, mode); | 
|---|
| 130 |         XMLPortParam(SpicedAsteroidBelt, "minSize", setMinSize, getMinSize, xmlelement, mode); | 
|---|
| 131 |         XMLPortParam(SpicedAsteroidBelt, "radius0", setRadius0, getRadius0, xmlelement, mode); | 
|---|
| 132 |         XMLPortParam(SpicedAsteroidBelt, "radius1", setRadius1, getRadius1, xmlelement, mode); | 
|---|
| 133 |         XMLPortParam(SpicedAsteroidBelt, "foggy", setFog, isFoggy, xmlelement, mode); | 
|---|
| 134 |         XMLPortParam(SpicedAsteroidBelt, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode); | 
|---|
| 135 |  | 
|---|
| 136 |         XMLPortParam(SpicedAsteroidBelt, "tiltAt", setTiltAt, getTiltAt, xmlelement, mode); | 
|---|
| 137 |         XMLPortParam(SpicedAsteroidBelt, "tiltBy", setTiltBy, getTiltBy, xmlelement, mode);  | 
|---|
| 138 |  | 
|---|
| 139 |     } | 
|---|
| 140 |  | 
|---|
| 141 |     void SpicedAsteroidBelt::tick(float dt){ | 
|---|
| 142 |  | 
|---|
| 143 |         this->create(); | 
|---|
| 144 |         this->destroyLater(); | 
|---|
| 145 |  | 
|---|
| 146 |     } | 
|---|
| 147 |  | 
|---|
| 148 | } | 
|---|
| 149 |  | 
|---|
| 150 |  | 
|---|