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 | * Gion-Andri Cantieni |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "CreateStars.h" |
---|
30 | |
---|
31 | #include <OgreVector3.h> |
---|
32 | |
---|
33 | #include "core/CoreIncludes.h" |
---|
34 | #include "core/XMLPort.h" |
---|
35 | #include "graphics/Billboard.h" |
---|
36 | |
---|
37 | namespace orxonox |
---|
38 | { |
---|
39 | CreateFactory(CreateStars); |
---|
40 | |
---|
41 | static const float pi = 3.14159265359f; |
---|
42 | |
---|
43 | CreateStars::CreateStars(BaseObject* creator) : BaseObject(creator) |
---|
44 | { |
---|
45 | RegisterObject(CreateStars); |
---|
46 | this->material_ = "Examples/Flare"; |
---|
47 | this->alpha_ = 0.7f; |
---|
48 | this->alphaDiff_ = 0.5f; |
---|
49 | this->radiusDiff_ = 0.9f; |
---|
50 | this->colour_.r = 1; |
---|
51 | this->colour_.g = 1; |
---|
52 | this->colour_.b = 1; |
---|
53 | this->colourDiff_ = 0.1f; |
---|
54 | } |
---|
55 | |
---|
56 | CreateStars::~CreateStars() |
---|
57 | { |
---|
58 | while( billboards_.size()!=0 ) |
---|
59 | { |
---|
60 | billboards_.back()->destroy(); |
---|
61 | billboards_.pop_back(); |
---|
62 | |
---|
63 | } |
---|
64 | |
---|
65 | billboards_.clear(); |
---|
66 | } |
---|
67 | |
---|
68 | void CreateStars::createBillboards() |
---|
69 | { |
---|
70 | |
---|
71 | for(int i=0; i < numStars_; i++) |
---|
72 | { |
---|
73 | Billboard* bb = new Billboard(this); |
---|
74 | |
---|
75 | float r = rnd(-colourDiff_,colourDiff_); |
---|
76 | float g = rnd(-colourDiff_,colourDiff_); |
---|
77 | float b = rnd(-colourDiff_,colourDiff_); |
---|
78 | orxonox::ColourValue thisColour = colour_; |
---|
79 | float alpha = alpha_+rnd(-alphaDiff_,alphaDiff_); |
---|
80 | thisColour.r=clamp((thisColour.r+r)*alpha, 0.0f, 1.0f); |
---|
81 | thisColour.g=clamp((thisColour.g+g)*alpha, 0.0f, 1.0f); |
---|
82 | thisColour.b=clamp((thisColour.b+b)*alpha, 0.0f, 1.0f); |
---|
83 | |
---|
84 | bb->setMaterial(material_); |
---|
85 | bb->setColour(thisColour); |
---|
86 | |
---|
87 | float phi; |
---|
88 | float teta; |
---|
89 | |
---|
90 | while(1) |
---|
91 | { |
---|
92 | phi = rnd(2*pi); |
---|
93 | teta = rnd(pi); |
---|
94 | float random = rnd(1); |
---|
95 | if(sin(teta)>random) break; |
---|
96 | } |
---|
97 | float radius = rnd(radiusDiff_,1)*radius_; |
---|
98 | bb->setPosition( PolarToCartesian(phi, teta, radius) ); |
---|
99 | billboards_.push_back(bb); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | Vector3 CreateStars::PolarToCartesian(float phi, float teta, float radius) |
---|
104 | { |
---|
105 | float x = radius * cos(phi) * sin(teta); |
---|
106 | float y = radius * sin(phi) * sin(teta); |
---|
107 | float z = radius * cos(teta); |
---|
108 | return Vector3(x,y,z); |
---|
109 | } |
---|
110 | |
---|
111 | void CreateStars::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
112 | { |
---|
113 | SUPER(CreateStars, XMLPort, xmlelement, mode); |
---|
114 | |
---|
115 | XMLPortParam(CreateStars, "numStars", setNumStars, getNumStars, xmlelement, mode); |
---|
116 | XMLPortParam(CreateStars, "material", setMaterial, getMaterial, xmlelement, mode); |
---|
117 | XMLPortParam(CreateStars, "colour", setColour, getColour, xmlelement, mode); |
---|
118 | XMLPortParam(CreateStars, "alpha", setAlpha, getAlpha, xmlelement, mode); |
---|
119 | XMLPortParam(CreateStars, "colourDiff", setColourDiff, getColourDiff, xmlelement, mode); |
---|
120 | XMLPortParam(CreateStars, "alphaDiff", setAlphaDiff, getAlphaDiff, xmlelement, mode); |
---|
121 | XMLPortParam(CreateStars, "radiusDiff", setRadiusDiff, getRadiusDiff, xmlelement, mode); |
---|
122 | XMLPortParam(CreateStars, "radius", setRadius, getRadius, xmlelement, mode); |
---|
123 | } |
---|
124 | |
---|
125 | } |
---|