Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/AsteroidMining_HS17/src/modules/asteroidmining/SpicedAsteroidBelt.cc @ 11703

Last change on this file since 11703 was 11667, checked in by remartin, 7 years ago

Added tilting for the spicedAsteroidBelt. Finished commenting, polish up. Done.

File size: 6.2 KB
Line 
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 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      Simon Miescher
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 "../../orxonox/worldentities/pawns/Pawn.h"
48#include "../../orxonox/worldentities/WorldEntity.h"
49
50#include "SpicedAsteroidBelt.h"
51#include "SpicedAsteroidField.h"
52
53#include <algorithm>
54
55#include "core/CoreIncludes.h"
56#include "core/GameMode.h"
57#include "core/XMLPort.h"
58#include "core/EventIncludes.h"
59#include "network/NetworkFunction.h"
60#include "util/Math.h"
61
62namespace orxonox{
63
64    RegisterClass(SpicedAsteroidBelt);
65
66    SpicedAsteroidBelt::SpicedAsteroidBelt(Context* context) : Pawn(context) {
67
68        RegisterObject(SpicedAsteroidBelt);
69
70        this->context = context; 
71
72        // Default Values:
73        this->count = 250; 
74        this->position = Vector3(0,0,0);
75        this->segments = 30;
76        this->minSize = 1;
77        this->maxSize = 50;
78        this->radius0 = 7190;
79        this->radius1 = 7800;
80
81        this->mDensity = 0.3;
82        this->fogDensity = 0.5;
83
84        this->tiltAt = 0.0; 
85        this->tiltBy = 0.0; 
86
87        this->registerVariables();
88
89    }
90
91    SpicedAsteroidBelt::~SpicedAsteroidBelt(){
92
93    }
94
95    void SpicedAsteroidBelt::create(){
96
97        float myPi = 3.1415927410125732421875; //pi; // Math.pi ist statisch oder so.
98        float width = this->radius1 - this->radius0; if(width<0){width = -width;} // predefined abs?
99        float radius = (this->radius1 + this->radius0) / 2.0;
100        int segmentCount = round(this->count / this->segments);
101
102        SpicedAsteroidField* af[this->segments]; 
103        (void)af[0]; // avoid nasty compiler warning
104
105        float dPhi = (2 * myPi) / this->segments;
106        float dTheta = 4.0*this->tiltBy/this->segments; 
107        float sepp = -this->tiltAt;
108        float globi = (myPi/2.0) + this->tiltBy;
109
110        for(int s = 0; s<segments; ++s){
111            sepp = sepp + dPhi;
112            if(s<segments/2){           
113                globi = globi - dTheta; 
114            }else{
115                globi = globi + dTheta; 
116            }
117           
118            Vector3* pos = new Vector3(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi)); 
119            af[s] = new SpicedAsteroidField(this->context, this->position + *pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
120           
121        }
122       
123    }
124
125    void SpicedAsteroidBelt::XMLPort(Element& xmlelement, XMLPort::Mode mode){
126
127        SUPER(SpicedAsteroidBelt, XMLPort, xmlelement, mode); 
128
129        XMLPortParam(SpicedAsteroidBelt, "count", setCount, getCount, xmlelement, mode);
130        XMLPortParam(SpicedAsteroidBelt, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode);
131        XMLPortParam(SpicedAsteroidBelt, "position", setPosition, getPosition, xmlelement, mode);
132        XMLPortParam(SpicedAsteroidBelt, "segments", setSegments, getSegments, xmlelement, mode);
133
134        XMLPortParam(SpicedAsteroidBelt, "maxSize", setMaxSize, getMaxSize, xmlelement, mode);
135        XMLPortParam(SpicedAsteroidBelt, "minSize", setMinSize, getMinSize, xmlelement, mode);
136        XMLPortParam(SpicedAsteroidBelt, "radius0", setRadius0, getRadius0, xmlelement, mode);
137        XMLPortParam(SpicedAsteroidBelt, "radius1", setRadius1, getRadius1, xmlelement, mode);
138        XMLPortParam(SpicedAsteroidBelt, "foggy", setFog, isFoggy, xmlelement, mode);
139        XMLPortParam(SpicedAsteroidBelt, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode);
140
141        XMLPortParam(SpicedAsteroidBelt, "tiltAt", setTiltAt, getTiltAt, xmlelement, mode);
142        XMLPortParam(SpicedAsteroidBelt, "tiltBy", setTiltBy, getTiltBy, xmlelement, mode); 
143
144    }
145
146    void SpicedAsteroidBelt::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
147
148    }
149
150    void SpicedAsteroidBelt::registerVariables(){
151
152        registerVariable(this->count, VariableDirection::ToClient);
153        registerVariable(this->mDensity, VariableDirection::ToClient);
154        registerVariable(this->position, VariableDirection::ToClient);
155        registerVariable(this->segments, VariableDirection::ToClient);
156
157        registerVariable(this->maxSize, VariableDirection::ToClient);
158        registerVariable(this->minSize, VariableDirection::ToClient);
159        registerVariable(this->radius0, VariableDirection::ToClient);
160        registerVariable(this->radius1, VariableDirection::ToClient);
161        registerVariable(this->foggy, VariableDirection::ToClient);
162        registerVariable(this->fogDensity, VariableDirection::ToClient);
163
164        registerVariable(this->tiltAt, VariableDirection::ToClient);
165        registerVariable(this->tiltBy, VariableDirection::ToClient);
166
167    }
168
169    void SpicedAsteroidBelt::tick(float dt){
170
171        this->create();
172        this->bAlive_ = false;
173        this->destroyLater();
174
175    }
176
177}
178
179
Note: See TracBrowser for help on using the repository browser.