Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/skybox2/src/modules/designtools/CreateStars.cc @ 6861

Last change on this file since 6861 was 6861, checked in by gionc, 14 years ago

Added StarCreator

File size: 2.6 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 "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);
54    }
55
56    CreateStars::~CreateStars()
57    {
58        while( billboards_.size()!=0 ) 
59        {
60            delete(billboards_.back());
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* b = new Billboard(this);
74            b->setMaterial(material_);
75
76            float alpha = rnd(-90,90);
77            float beta = rnd(0,360);
78           
79            b->setPosition( PolarToCartesian(alpha, beta, radius_) );
80            billboards_.push_back(b);
81        }
82    }
83
84    Vector3 PolarToCartesian(float alpha, float beta, float radius) 
85    {
86        int x = radius * cos(alpha) * sin(beta);
87        int y = radius * sin(alpha) * cos(beta);
88        int z = radius * cos(beta);
89        return Vector3(x,y,z);
90    }
91
92    void CreateStars::XMLPort(Element& xmlelement, XMLPort::Mode mode)
93    {
94        XMLPortParam(CreateStars, "numStars", setNumStars, getNumStars, xmlelement, mode);
95        XMLPortParam(CreateStars, "material", setMaterial, getMaterial, xmlelement, mode);
96        XMLPortParam(CreateStars, "radius", setRadius, getRadius, xmlelement, mode);
97        }
98
99}
Note: See TracBrowser for help on using the repository browser.