Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Presentation_HS17_merge/src/modules/asteroidmining/SpicedAsteroidBelt.cc @ 11734

Last change on this file since 11734 was 11732, checked in by landauf, 7 years ago

[AsteroidMining_HS17] fixed a bunch of compile- and run-time errors due to illegal usage of arrays

File size: 6.1 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        float dPhi = (2 * myPi) / this->segments;
103        float dTheta = 4.0*this->tiltBy/this->segments; 
104        float sepp = -this->tiltAt;
105        float globi = (myPi/2.0) + this->tiltBy;
106
107        for(int s = 0; s<segments; ++s){
108            sepp = sepp + dPhi;
109            if(s<segments/2){           
110                globi = globi - dTheta; 
111            }else{
112                globi = globi + dTheta; 
113            }
114           
115            Vector3* pos = new Vector3(radius*cos(sepp)*sin(globi), radius*sin(sepp)*sin(globi), radius*cos(globi)); 
116            new SpicedAsteroidField(this->context, this->position + *pos, this->minSize, this->maxSize, width, segmentCount, this->foggy, this->mDensity, this->fogDensity);
117           
118        }
119       
120    }
121
122    void SpicedAsteroidBelt::XMLPort(Element& xmlelement, XMLPort::Mode mode){
123
124        SUPER(SpicedAsteroidBelt, XMLPort, xmlelement, mode); 
125
126        XMLPortParam(SpicedAsteroidBelt, "count", setCount, getCount, xmlelement, mode);
127        XMLPortParam(SpicedAsteroidBelt, "mDensity", setMineralDensity, getMineralDensity, xmlelement, mode);
128        XMLPortParam(SpicedAsteroidBelt, "position", setPosition, getPosition, xmlelement, mode);
129        XMLPortParam(SpicedAsteroidBelt, "segments", setSegments, getSegments, xmlelement, mode);
130
131        XMLPortParam(SpicedAsteroidBelt, "maxSize", setMaxSize, getMaxSize, xmlelement, mode);
132        XMLPortParam(SpicedAsteroidBelt, "minSize", setMinSize, getMinSize, xmlelement, mode);
133        XMLPortParam(SpicedAsteroidBelt, "radius0", setRadius0, getRadius0, xmlelement, mode);
134        XMLPortParam(SpicedAsteroidBelt, "radius1", setRadius1, getRadius1, xmlelement, mode);
135        XMLPortParam(SpicedAsteroidBelt, "foggy", setFog, isFoggy, xmlelement, mode);
136        XMLPortParam(SpicedAsteroidBelt, "fogDensity", setFogDensity, getFogDensity, xmlelement, mode);
137
138        XMLPortParam(SpicedAsteroidBelt, "tiltAt", setTiltAt, getTiltAt, xmlelement, mode);
139        XMLPortParam(SpicedAsteroidBelt, "tiltBy", setTiltBy, getTiltBy, xmlelement, mode); 
140
141    }
142
143    void SpicedAsteroidBelt::XMLEventPort(Element& xmlelement, XMLPort::Mode mode){
144
145    }
146
147    void SpicedAsteroidBelt::registerVariables(){
148
149        registerVariable(this->count, VariableDirection::ToClient);
150        registerVariable(this->mDensity, VariableDirection::ToClient);
151        registerVariable(this->position, VariableDirection::ToClient);
152        registerVariable(this->segments, VariableDirection::ToClient);
153
154        registerVariable(this->maxSize, VariableDirection::ToClient);
155        registerVariable(this->minSize, VariableDirection::ToClient);
156        registerVariable(this->radius0, VariableDirection::ToClient);
157        registerVariable(this->radius1, VariableDirection::ToClient);
158        registerVariable(this->foggy, VariableDirection::ToClient);
159        registerVariable(this->fogDensity, VariableDirection::ToClient);
160
161        registerVariable(this->tiltAt, VariableDirection::ToClient);
162        registerVariable(this->tiltBy, VariableDirection::ToClient);
163
164    }
165
166    void SpicedAsteroidBelt::tick(float dt){
167
168        this->create();
169        this->bAlive_ = false;
170        this->destroyLater();
171
172    }
173
174}
175
176
Note: See TracBrowser for help on using the repository browser.