~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/environment/caelum/include/PointStarfield.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
This file is part of Caelum.
 
3
See http://www.ogre3d.org/wiki/index.php/Caelum 
 
4
 
 
5
Copyright (c) 2008 Caelum team. See Contributors.txt for details.
 
6
 
 
7
Caelum is free software: you can redistribute it and/or modify
 
8
it under the terms of the GNU Lesser General Public License as published
 
9
by the Free Software Foundation, either version 3 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
Caelum is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU Lesser General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU Lesser General Public License
 
18
along with Caelum. If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
#ifndef CAELUM__POINT_STARFIELD_H
 
22
#define CAELUM__POINT_STARFIELD_H
 
23
 
 
24
#include "CaelumPrerequisites.h"
 
25
#include "CameraBoundElement.h"
 
26
#include <vector>
 
27
 
 
28
namespace caelum
 
29
{
 
30
    /** POD for bright star catalogue entries.
 
31
     *  Only J2000 position and magnitude included.
 
32
     */
 
33
    struct BrightStarCatalogueEntry {
 
34
        signed char rasc_hour;
 
35
        signed char rasc_min;
 
36
        float rasc_sec;
 
37
        signed char decl_deg;
 
38
        signed char decl_min;
 
39
        float decl_sec;
 
40
        float magn;
 
41
    };
 
42
 
 
43
    /// There are exactly 9110 stars in our version of the BSC.
 
44
    const int BrightStarCatalogueSize = 9110;
 
45
 
 
46
    /// Hardcoded bright star catalogue (BrightStarCatalogue.cpp)
 
47
    extern const BrightStarCatalogueEntry BrightStarCatalogue[BrightStarCatalogueSize];
 
48
 
 
49
    /** Point starfield class.
 
50
     *  An Ogre::BillboardSet is used internally; but it doesn't do much.
 
51
     *  The data is not kept inside the billboardset; but externally. Custom
 
52
     *  hardware buffers would probably work better.
 
53
     *
 
54
     *  Stars are sized in pixels; this seems to work a lot better than relative sizes.
 
55
     *  Stars could be made even smaller but it would require hinting (nudging pixel
 
56
     *  coordinates to match actual screen pixels). Points are hard.
 
57
     * 
 
58
     *  Loading a bright-star catalogue is supported but star positions are
 
59
     *  likely only correct relative to each other. External rotation is probably wrong.
 
60
     */
 
61
    class CAELUM_EXPORT PointStarfield : public CameraBoundElement
 
62
    {
 
63
            public:
 
64
                    /** Constructor.
 
65
             *  By default this loads some reasonable defaults and the
 
66
             *  bright star catalogue.
 
67
             */
 
68
                    PointStarfield (
 
69
                    Ogre::SceneManager *sceneMgr,
 
70
                                    Ogre::SceneNode *caelumRootNode,
 
71
                    bool initWithCatalogue = true);
 
72
 
 
73
                    /// Destructor.
 
74
                    virtual ~PointStarfield ();
 
75
 
 
76
            /// Struct representing one star.
 
77
            struct Star {
 
78
                Ogre::Degree RightAscension;
 
79
                Ogre::Degree Declination;
 
80
                Ogre::Real Magnitude;
 
81
            };
 
82
 
 
83
            typedef std::vector<Star> StarVector;
 
84
 
 
85
            /** Get a reference to the vector of stars.
 
86
             *  You can freely modify this; but you need to updateStars when you're done.
 
87
             */
 
88
            inline StarVector& getStarVector () { return mStars; }
 
89
 
 
90
            /** You must call this if you change the star vector by hand.
 
91
             */
 
92
            void notifyStarVectorChanged ();
 
93
 
 
94
            /// Clear any and all stars.
 
95
            void clearAllStars ();
 
96
 
 
97
            /** Add a bunch of random stars.
 
98
             */
 
99
            void addRandomStars (int count);
 
100
 
 
101
            /** Add one star from the bright star catalogue.
 
102
             */
 
103
            void addStar (const BrightStarCatalogueEntry &entry);
 
104
 
 
105
            /** Add stars from the bright star catalogue.
 
106
             *  @param count Number of stars to add (in order of brightness).
 
107
             */
 
108
            void addBrightStarCatalogue (int count = BrightStarCatalogueSize);
 
109
 
 
110
 
 
111
            private:
 
112
                    /// Node for the starfield
 
113
                    Ogre::SceneNode *mNode;
 
114
 
 
115
            Ogre::ManualObject *mManualObj;
 
116
 
 
117
            /// Billboard material
 
118
            Ogre::MaterialPtr mMaterial;
 
119
 
 
120
            /// Star data.
 
121
            std::vector<Star> mStars;
 
122
 
 
123
            Ogre::Real mMinPixelSize, mMaxPixelSize, mMag0PixelSize;
 
124
            Ogre::Real mMagnitudeScale;
 
125
 
 
126
            Ogre::Degree mObserverLatitude, mObserverLongitude;
 
127
 
 
128
            bool mValidGeometry;
 
129
                        void invalidateGeometry();
 
130
                        void ensureGeometry();
 
131
 
 
132
            public:
 
133
                    /** Update function; called from CaelumSystem::updateSubcomponents
 
134
                @param time Time of the day.
 
135
                     */
 
136
                    void _update (float time);
 
137
 
 
138
            /** Magnitude power scale.
 
139
             *  Star magnitudes are logarithming; one magnitude difference
 
140
             *  means a star is 2.512 times brighter.
 
141
             *  This property allows tweaking that value.
 
142
             */
 
143
            inline void setMagnitudeScale (Ogre::Real value) { mMagnitudeScale = value; }
 
144
            inline Ogre::Real getMagnitudeScale () { return mMagnitudeScale; }
 
145
 
 
146
            inline void setMag0PixelSize (Ogre::Real value) { mMag0PixelSize = value; }
 
147
            inline Ogre::Real getMag0PixelSize () { return mMag0PixelSize; }
 
148
 
 
149
            inline void setMinPixelSize (Ogre::Real value) { mMinPixelSize = value; }
 
150
            inline Ogre::Real getMinPixelSize () { return mMinPixelSize; }
 
151
 
 
152
            inline void setMaxPixelSize (Ogre::Real value) { mMaxPixelSize = value; }
 
153
            inline Ogre::Real getMaxPixelSize () { return mMaxPixelSize; }
 
154
 
 
155
            void setObserverLatitude (Ogre::Degree value);
 
156
            inline Ogre::Degree getObserverLatitude () { return mObserverLatitude; }
 
157
 
 
158
            void setObserverLongitude (Ogre::Degree value);
 
159
            inline Ogre::Degree getObserverLongitude () { return mObserverLongitude; }
 
160
 
 
161
                /// Material used on billboards
 
162
                    static const Ogre::String BILLBOARD_MATERIAL_NAME;
 
163
 
 
164
                    /// Handle camera change.
 
165
                    virtual void notifyCameraChanged (Ogre::Camera *cam);
 
166
 
 
167
        protected:
 
168
            /// Handle far radius.
 
169
                virtual void setFarRadius (Ogre::Real radius);
 
170
    };
 
171
}
 
172
 
 
173
#endif // CAELUM__POINT_STARFIELD_H
 
174