]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/newcloud.hxx
Harald Johnsen: Fix a 'terrible' bug with culling of the clouds.
[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, 59 Temple Place, Suite 330, Boston, MA 02111-1307, 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 class SGNewCloud {
37
38 public:
39         SGNewCloud();
40         ~SGNewCloud();
41
42         enum CLbox_type {
43                 CLbox_standard = 0,
44                 CLbox_sc = 1,
45                 CLbox_cumulus = 2,
46                 CLbox_stratus = 3
47         };
48
49         enum CLTexture_type {
50                 CLTexture_cumulus = 1,
51                 CLTexture_stratus = 2,
52                 CLTexture_max
53         };
54 private:
55
56         class spriteDef {
57         public:
58                 sgVec3          pos;
59                 float           r;
60                 CLbox_type      sprite_type;
61                 sgVec4          l0, l1, l2, l3;
62                 int                     rank;
63                 int                     box;
64                 float           dist;           // distance used during sort
65                 bool operator<(const spriteDef &b) const {
66                         return this->dist < b.dist;
67                 }
68         };
69
70         typedef struct {
71                 sgVec3          pos;
72                 float           r;
73                 // the type defines how the sprites can be positioned inside the box, their size, etc
74                 CLbox_type      cont_type;
75                 sgVec3          center;
76         } spriteContainer;
77
78         typedef vector<spriteDef>               list_of_spriteDef;
79         typedef vector<spriteContainer> list_of_spriteContainer;
80
81         void computeSimpleLight(sgVec3 eyePos);
82         void addSprite(float x, float y, float z, float r, CLbox_type type, int box);
83
84         // sort on distance to eye because of transparency
85         void sortSprite( sgVec3 eyePos );
86
87         // render the cloud on screen or on the RTT texture to build the impostor
88         void Render3Dcloud( bool drawBB, sgVec3 eyePos, sgVec3 deltaPos, float dist_center );
89
90         // compute rotations so that a quad is facing the camera
91         void CalcAngles(sgVec3 refpos, sgVec3 eyePos, float *angleY, float *angleX);
92
93         // draw a cloud but this time we use the impostor texture
94         void RenderBB(sgVec3 deltaPos, float angleY, float angleX, float dist_center);
95
96         // determine if it is a good idea to use an impostor to render the cloud
97         bool isBillboardable(float dist);
98
99         int             cloudId, bbId;
100 //      int             rank;
101         sgVec3  cloudpos, center;
102         list_of_spriteDef               list_spriteDef;
103         list_of_spriteContainer list_spriteContainer;
104         float minx, maxx, miny, maxy, minz, maxz;
105         float radius;
106
107         // fading data
108         bool direction, fadeActive;
109         float duration, pauseLength;
110         // need timer here
111
112 public:
113         // add a new box to the cloud
114         void addContainer(float x, float y, float z, float r, CLbox_type type);
115
116         // generate all sprite with defined boxes
117         void genSprites(void);
118
119         // debug only, define a cumulus
120         void new_cu(void);
121
122         // debug only
123         void drawContainers(void);
124
125         // define the new position of the cloud (inside the cloud field, not on sphere)
126         void SetPos(sgVec3 newPos);
127
128         // render the cloud, fakepos is a relative position inside the cloud field
129         void Render(sgVec3 fakepos);
130
131         // 
132         void startFade(bool direction, float duration, float pauseLength);
133         void setFade(float howMuch);
134
135         inline float getRadius() { return radius; }
136
137         // load all textures used to draw cloud sprites
138         static void loadTextures( const string &tex_path );
139         static sgVec3 modelSunDir;
140         static sgVec3 sunlight, ambLight;
141         static bool useAnisotropic;
142         static float nearRadius;
143         static bool lowQuality;
144         static SGBbCache        *cldCache;
145 };
146
147 #endif // _NEWCLOUD_HXX