Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hudHS14/src/modules/designtools/CreateStars.cc @ 10239

Last change on this file since 10239 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 3.9 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 *      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
37namespace orxonox
38{
39    RegisterClass(CreateStars);
40
41    CreateStars::CreateStars(Context* context) : BaseObject(context)
42    {
43        RegisterObject(CreateStars);
44        this->material_ = "Examples/Flare";
45        this->alpha_ = 0.7f;
46        this->alphaDiff_ = 0.5f;
47        this->radiusDiff_ = 0.9f;
48        this->colour_.r = 1;
49        this->colour_.g = 1;
50        this->colour_.b = 1;
51        this->colourDiff_ = 0.1f;
52    }
53
54    CreateStars::~CreateStars()
55    {
56        while( billboards_.size()!=0 )
57        {
58            billboards_.back()->destroy();
59            billboards_.pop_back();
60
61        }
62
63        billboards_.clear();
64    }
65
66    void CreateStars::createBillboards()
67    {
68
69        for(int i=0; i < numStars_; i++)
70        {
71            Billboard* bb = new Billboard(this->getContext());
72
73            float r = rnd(-colourDiff_,colourDiff_);
74            float g = rnd(-colourDiff_,colourDiff_);
75            float b = rnd(-colourDiff_,colourDiff_);
76            orxonox::ColourValue thisColour = colour_;
77            float alpha = alpha_+rnd(-alphaDiff_,alphaDiff_);
78            thisColour.r=clamp((thisColour.r+r)*alpha, 0.0f, 1.0f);
79            thisColour.g=clamp((thisColour.g+g)*alpha, 0.0f, 1.0f);
80            thisColour.b=clamp((thisColour.b+b)*alpha, 0.0f, 1.0f);
81
82            bb->setMaterial(material_);
83            bb->setColour(thisColour);
84
85            float phi;
86            float teta;
87
88            while(1)
89            {
90                phi = rnd(math::twoPi);
91                teta = rnd(math::pi);
92                float random = rnd(1);
93                if(sin(teta)>random) break;
94            }
95            float radius = rnd(radiusDiff_,1)*radius_;
96            bb->setPosition( PolarToCartesian(phi, teta, radius) );
97            billboards_.push_back(bb);
98        }
99    }
100
101    Vector3 CreateStars::PolarToCartesian(float phi, float teta, float radius)
102    {
103        float x = radius * cos(phi) * sin(teta);
104        float y = radius * sin(phi) * sin(teta);
105        float z = radius * cos(teta);
106        return Vector3(x,y,z);
107    }
108
109    void CreateStars::XMLPort(Element& xmlelement, XMLPort::Mode mode)
110    {
111        SUPER(CreateStars, XMLPort, xmlelement, mode);
112
113        XMLPortParam(CreateStars, "numStars", setNumStars, getNumStars, xmlelement, mode);
114        XMLPortParam(CreateStars, "material", setMaterial, getMaterial, xmlelement, mode);
115        XMLPortParam(CreateStars, "colour", setColour, getColour, xmlelement, mode);
116        XMLPortParam(CreateStars, "alpha", setAlpha, getAlpha, xmlelement, mode);
117        XMLPortParam(CreateStars, "colourDiff", setColourDiff, getColourDiff, xmlelement, mode);
118        XMLPortParam(CreateStars, "alphaDiff", setAlphaDiff, getAlphaDiff, xmlelement, mode);
119        XMLPortParam(CreateStars, "radiusDiff", setRadiusDiff, getRadiusDiff, xmlelement, mode);
120        XMLPortParam(CreateStars, "radius", setRadius, getRadius, xmlelement, mode);
121    }
122
123}
Note: See TracBrowser for help on using the repository browser.