]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/newcloud.hxx
Modified Files:
[simgear.git] / simgear / scene / sky / newcloud.hxx
1 // 3D cloud class
2 //
3 // Written by Harald JOHNSEN, started April 2005.
4 //
5 // Copyright (C) 2005  Harald JOHNSEN - hjohnsen@evc.net
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 //
22
23 #ifndef _NEWCLOUD_HXX
24 #define _NEWCLOUD_HXX
25
26 #include <plib/sg.h>
27 #include <simgear/compiler.h>
28 #include STL_STRING
29 #include <vector>
30
31 #include "bbcache.hxx"
32
33 SG_USING_STD(string);
34 SG_USING_STD(vector);
35
36 /**
37  * 3D cloud class.
38  */
39 class SGNewCloud {
40
41 public:
42         enum CLFamilly_type {
43                 CLFamilly_cu = 0,
44                 CLFamilly_cb,
45                 CLFamilly_st,
46                 CLFamilly_ns,
47                 CLFamilly_sc,
48                 CLFamilly_as,
49                 CLFamilly_ac,
50                 CLFamilly_ci,
51                 CLFamilly_cc,
52                 CLFamilly_cs,
53                 CLFamilly_nn
54         };
55         SGNewCloud(CLFamilly_type classification=CLFamilly_nn);
56         SGNewCloud(string classification);
57         ~SGNewCloud();
58
59         enum CLbox_type {
60                 CLbox_standard = 0,
61                 CLbox_sc = 1,
62                 CLbox_cumulus = 2,
63                 CLbox_stratus = 3
64         };
65
66         enum CLTexture_type {
67                 CLTexture_cumulus = 1,
68                 CLTexture_stratus = 2,
69                 CLTexture_max
70         };
71
72 private:
73
74         class spriteDef {
75         public:
76                 sgVec3          pos;
77                 float           r;
78                 CLbox_type      sprite_type;
79                 sgVec4          l0, l1, l2, l3;
80                 sgVec3          normal, n0, n1, n2, n3;
81                 int                     rank;
82                 int                     box;
83                 float           dist;           // distance used during sort
84                 bool operator<(const spriteDef &b) const {
85                         return (this->dist < b.dist);
86                 }
87         };
88
89         typedef struct {
90                 sgVec3          pos;
91                 float           r;
92                 // the type defines how the sprites can be positioned inside the box, their size, etc
93                 CLbox_type      cont_type;
94                 sgVec3          center;
95         } spriteContainer;
96
97         typedef vector<spriteDef>               list_of_spriteDef;
98         typedef vector<spriteContainer> list_of_spriteContainer;
99
100         void init(void);
101
102         void computeSimpleLight(sgVec3 eyePos);
103         void addSprite(float x, float y, float z, float r, CLbox_type type, int box);
104
105         // sort on distance to eye because of transparency
106         void sortSprite( sgVec3 eyePos );
107
108         // render the cloud on screen or on the RTT texture to build the impostor
109         void Render3Dcloud( bool drawBB, sgVec3 eyePos, sgVec3 deltaPos, float dist_center );
110
111         // compute rotations so that a quad is facing the camera
112         void CalcAngles(sgVec3 refpos, sgVec3 eyePos, float *angleY, float *angleX);
113
114         // draw a cloud but this time we use the impostor texture
115         void RenderBB(sgVec3 deltaPos, bool first_time, float dist_center);
116
117         // determine if it is a good idea to use an impostor to render the cloud
118         bool isBillboardable(float dist);
119
120         int             cloudId, bbId;
121         sgVec3  rotX, rotY;
122
123 //      int             rank;
124         sgVec3  cloudpos, center;
125         float   delta_base;
126         list_of_spriteDef               list_spriteDef;
127         list_of_spriteContainer list_spriteContainer;
128         float radius;
129         CLFamilly_type familly;
130
131         // fading data
132         bool direction, fadeActive;
133         float duration, pauseLength, fadetimer;
134         float last_step;
135
136 public:
137         // add a new box to the cloud
138         void addContainer(float x, float y, float z, float r, CLbox_type type);
139
140         // generate all sprite with defined boxes
141         void genSprites(void);
142
143         // debug only, define a cumulus
144         void new_cu(void);
145
146         // debug only
147         void drawContainers(void);
148
149         // define the new position of the cloud (inside the cloud field, not on sphere)
150         void SetPos(sgVec3 newPos);
151
152         // render the cloud, fakepos is a relative position inside the cloud field
153         void Render(sgVec3 fakepos);
154
155         // 
156         void startFade(bool direction, float duration, float pauseLength);
157         void setFade(float howMuch);
158
159         inline float getRadius() { return radius; }
160         inline sgVec3 *getCenter() { return &center; }
161         inline int getId() { return cloudId; }
162
163         inline CLFamilly_type getFamilly(void) { return familly; }
164
165         // load all textures used to draw cloud sprites
166         static void loadTextures( const string &tex_path );
167         static sgVec3 modelSunDir;
168         static sgVec3 sunlight, ambLight;
169         static bool useAnisotropic;
170         static float nearRadius;
171         static bool lowQuality;
172         static SGBbCache        *cldCache;
173 };
174
175 #endif // _NEWCLOUD_HXX