Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/src/modules/designtools/CreateStars.cc @ 7015

Last change on this file since 7015 was 6994, checked in by scheusso, 14 years ago

merged skybox2 branch to presentation merger branch

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