1 #pragma once
2 // Description:
3 //   Starfield with nebulas.
4 //
5 // Copyright (C) 2001 Frank Becker
6 //
7 // This program is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU General Public License as published by the Free Software
9 // Foundation;  either version 2 of the License,  or (at your option) any  later
10 // version.
11 //
12 // This program is distributed in the hope that it will be useful,  but  WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
15 //
16 
17 #include <Singleton.hpp>
18 #include <GLBitmapCollection.hpp>
19 
20 const int NUM_STARS = 300;
21 const int NUM_NEBULAS = 3;
22 
23 class Starfield
24 {
25 friend class Singleton<Starfield>;
26 private:
27     struct Nebula
28     {
29         float x;
30         float y;
31         float z;
32         float d;
33 
34 	float r;
35 	float g;
36 	float b;
37 
38         float sizeX;
39         float sizeY;
40         float rot;
41         float max;
42     };
43 
44     struct Star
45     {
46 	float x;
47 	float y;
48 	float z;
49 	float d;
50 
51 	float r;
52 	float g;
53 	float b;
54     };
55 
56 public:
57     void init( float z);
58     void update( void);
59     void draw( bool showStars, bool showNebulas);
bindTexture(void)60     void bindTexture( void) { _nebula->bind();}
61 
62 private:
63     ~Starfield();
64     Starfield( void);
65     Starfield( const Starfield&);
66     Starfield &operator=(const Starfield&);
67 
68     void pickSize( Nebula &n);
69     void findMax( Nebula &n);
70     void pickColor( Nebula &n);
71     void updatePrevs( void);
72 
73     GLBitmapCollection *_nebula;
74     int _nebulaIndex;
75     float _nebulaHalfWidth;
76     float _nebulaHalfHeight;
77 
78     Star _starInfo[ NUM_STARS];
79     float _prevStarInfoY[ NUM_STARS];
80 
81     Nebula _nebulaInfo[ NUM_NEBULAS];
82     float _prevNebulaInfoY[ NUM_NEBULAS];
83 };
84 
85 typedef Singleton<Starfield> StarfieldS;
86