| [6861] | 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 |  | 
|---|
| [7028] | 31 | #include <OgreVector3.h> | 
|---|
|  | 32 |  | 
|---|
| [6861] | 33 | #include "core/CoreIncludes.h" | 
|---|
|  | 34 | #include "core/XMLPort.h" | 
|---|
|  | 35 | #include "graphics/Billboard.h" | 
|---|
| [7077] | 36 |  | 
|---|
| [6861] | 37 | namespace orxonox | 
|---|
|  | 38 | { | 
|---|
|  | 39 | CreateFactory(CreateStars); | 
|---|
|  | 40 |  | 
|---|
| [7028] | 41 | static const float pi = 3.14159265359f; | 
|---|
|  | 42 |  | 
|---|
| [6861] | 43 | CreateStars::CreateStars(BaseObject* creator) : BaseObject(creator) | 
|---|
|  | 44 | { | 
|---|
|  | 45 | RegisterObject(CreateStars); | 
|---|
| [6936] | 46 | this->material_ = "Examples/Flare"; | 
|---|
| [7028] | 47 | this->alpha_ = 0.7f; | 
|---|
|  | 48 | this->alphaDiff_ = 0.5f; | 
|---|
|  | 49 | this->radiusDiff_ = 0.9f; | 
|---|
| [6936] | 50 | this->colour_.r = 1; | 
|---|
|  | 51 | this->colour_.g = 1; | 
|---|
|  | 52 | this->colour_.b = 1; | 
|---|
| [7028] | 53 | this->colourDiff_ = 0.1f; | 
|---|
| [6861] | 54 | } | 
|---|
|  | 55 |  | 
|---|
|  | 56 | CreateStars::~CreateStars() | 
|---|
|  | 57 | { | 
|---|
| [7077] | 58 | while( billboards_.size()!=0 ) | 
|---|
| [6861] | 59 | { | 
|---|
| [7077] | 60 | billboards_.back()->destroy(); | 
|---|
| [6861] | 61 | billboards_.pop_back(); | 
|---|
|  | 62 |  | 
|---|
|  | 63 | } | 
|---|
|  | 64 |  | 
|---|
|  | 65 | billboards_.clear(); | 
|---|
|  | 66 | } | 
|---|
|  | 67 |  | 
|---|
|  | 68 | void CreateStars::createBillboards() | 
|---|
|  | 69 | { | 
|---|
|  | 70 |  | 
|---|
| [7077] | 71 | for(int i=0; i < numStars_; i++) | 
|---|
| [6861] | 72 | { | 
|---|
| [6936] | 73 | Billboard* bb = new Billboard(this); | 
|---|
| [6861] | 74 |  | 
|---|
| [6936] | 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_); | 
|---|
| [6972] | 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); | 
|---|
| [6936] | 83 |  | 
|---|
|  | 84 | bb->setMaterial(material_); | 
|---|
|  | 85 | bb->setColour(thisColour); | 
|---|
|  | 86 |  | 
|---|
|  | 87 | float phi; | 
|---|
|  | 88 | float teta; | 
|---|
|  | 89 |  | 
|---|
| [7077] | 90 | while(1) | 
|---|
| [6936] | 91 | { | 
|---|
| [7028] | 92 | phi = rnd(2*pi); | 
|---|
|  | 93 | teta = rnd(pi); | 
|---|
| [6936] | 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); | 
|---|
| [6861] | 100 | } | 
|---|
|  | 101 | } | 
|---|
|  | 102 |  | 
|---|
| [7077] | 103 | Vector3 CreateStars::PolarToCartesian(float phi, float teta, float radius) | 
|---|
| [6861] | 104 | { | 
|---|
| [6936] | 105 | float x = radius * cos(phi) * sin(teta); | 
|---|
|  | 106 | float y = radius * sin(phi) * sin(teta); | 
|---|
|  | 107 | float z = radius * cos(teta); | 
|---|
| [6861] | 108 | return Vector3(x,y,z); | 
|---|
|  | 109 | } | 
|---|
|  | 110 |  | 
|---|
|  | 111 | void CreateStars::XMLPort(Element& xmlelement, XMLPort::Mode mode) | 
|---|
|  | 112 | { | 
|---|
| [6936] | 113 | SUPER(CreateStars, XMLPort, xmlelement, mode); | 
|---|
|  | 114 |  | 
|---|
| [6861] | 115 | XMLPortParam(CreateStars, "numStars", setNumStars, getNumStars, xmlelement, mode); | 
|---|
|  | 116 | XMLPortParam(CreateStars, "material", setMaterial, getMaterial, xmlelement, mode); | 
|---|
| [6936] | 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); | 
|---|
| [6861] | 122 | XMLPortParam(CreateStars, "radius", setRadius, getRadius, xmlelement, mode); | 
|---|
| [7039] | 123 | } | 
|---|
| [6861] | 124 |  | 
|---|
|  | 125 | } | 
|---|