Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/designtools/CreateStars.cc @ 10728

Last change on this file since 10728 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
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
[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]37namespace orxonox
38{
[9667]39    RegisterClass(CreateStars);
[6861]40
[9667]41    CreateStars::CreateStars(Context* context) : BaseObject(context)
[6861]42    {
43        RegisterObject(CreateStars);
[6936]44        this->material_ = "Examples/Flare";
[7028]45        this->alpha_ = 0.7f;
46        this->alphaDiff_ = 0.5f;
47        this->radiusDiff_ = 0.9f;
[6936]48        this->colour_.r = 1;
49        this->colour_.g = 1;
50        this->colour_.b = 1;
[7028]51        this->colourDiff_ = 0.1f;
[6861]52    }
53
54    CreateStars::~CreateStars()
55    {
[7077]56        while( billboards_.size()!=0 )
[6861]57        {
[7077]58            billboards_.back()->destroy();
[6861]59            billboards_.pop_back();
60
61        }
62
63        billboards_.clear();
64    }
65
66    void CreateStars::createBillboards()
67    {
68
[7077]69        for(int i=0; i < numStars_; i++)
[6861]70        {
[9667]71            Billboard* bb = new Billboard(this->getContext());
[6861]72
[6936]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_);
[6972]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);
[6936]81
82            bb->setMaterial(material_);
83            bb->setColour(thisColour);
84
85            float phi;
86            float teta;
87
[7077]88            while(1)
[6936]89            {
[8351]90                phi = rnd(math::twoPi);
[7184]91                teta = rnd(math::pi);
[6936]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);
[6861]98        }
99    }
100
[7077]101    Vector3 CreateStars::PolarToCartesian(float phi, float teta, float radius)
[6861]102    {
[6936]103        float x = radius * cos(phi) * sin(teta);
104        float y = radius * sin(phi) * sin(teta);
105        float z = radius * cos(teta);
[6861]106        return Vector3(x,y,z);
107    }
108
109    void CreateStars::XMLPort(Element& xmlelement, XMLPort::Mode mode)
110    {
[6936]111        SUPER(CreateStars, XMLPort, xmlelement, mode);
112
[6861]113        XMLPortParam(CreateStars, "numStars", setNumStars, getNumStars, xmlelement, mode);
114        XMLPortParam(CreateStars, "material", setMaterial, getMaterial, xmlelement, mode);
[6936]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);
[6861]120        XMLPortParam(CreateStars, "radius", setRadius, getRadius, xmlelement, mode);
[7039]121    }
[6861]122
123}
Note: See TracBrowser for help on using the repository browser.