Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/mountain_lake/src/lib/graphics/effects/cloud_effect.h @ 8930

Last change on this file since 8930 was 8911, checked in by amaechler, 19 years ago

branches/moutnain_lake: lightning hacking, skycolor not working yet

File size: 4.4 KB
Line 
1/**
2 * @file cloud_effect.h
3 * Create clouds
4*/
5
6#ifndef _CLOUD_EFFECT
7#define _CLOUD_EFFECT
8
9#include "weather_effect.h"
10
11#include "sound_buffer.h"
12#include "sound_source.h"
13
14#include "skydome.h"
15#include "material.h"
16#include "shader.h"
17
18#define MAXB 0x100
19#define N 0x1000
20#define NP 12   /* 2^N */
21#define NM 0xfff
22
23#define s_curve(t) ( t * t * (3. - 2. * t) )
24#define lerp(t, a, b) ( a + t * (b - a) )
25#define setup(i,b0,b1,r0,r1)\
26        t = vec[i] + N;\
27        b0 = ((int)t) & BM;\
28        b1 = (b0+1) & BM;\
29        r0 = t - (int)t;\
30        r1 = r0 - 1.;
31#define at2(rx,ry) ( rx * q[0] + ry * q[1] )
32#define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] )
33
34// FORWARD DECLARATION
35template <class T>
36class tAnimation;
37
38class CloudEffect : public WeatherEffect {
39
40public:
41
42    CloudEffect(const TiXmlElement* root = NULL);
43    virtual ~CloudEffect();
44
45    virtual void loadParams(const TiXmlElement* root);
46
47    virtual void init();
48
49    virtual void activate();
50    virtual void deactivate();
51
52    inline void activateCloud() {
53        this->activate();
54    }
55
56    inline void deactivateCloud() {
57        this->deactivate();
58    }
59
60    inline void setCloudOption(const std::string& option) {
61        if (option == "activate")
62            this->cloudActivate = true;
63    }
64
65    inline void setAnimationSpeed(float speed) {
66        this->animationSpeed = speed;
67    }
68
69    inline void setCloudScale(float scale) {
70        this->scale = scale;
71    }
72
73    inline void setCloudColor(float colorX, float colorY, float colorZ) {
74        this->cloudColor = Vector(colorX, colorY, colorZ);
75    }
76
77    inline void setSkyColor(float colorX, float colorY, float colorZ) {
78        this->skyColor = Vector(colorX, colorY, colorZ);
79    }
80
81    inline void setPlanetRadius(float planetRadius) {
82        this->planetRadius = planetRadius;
83    }
84
85    inline void setAtmosphericRadius(float atmosphericRadius) {
86        this->atmosphericRadius = atmosphericRadius;
87    }
88
89    inline void setDivisions(int divs) {
90        this->divs = divs;
91    }
92
93    virtual void draw() const;
94    virtual void tick(float dt);
95
96    static void changeSkyColor(Vector color, float time);
97    static void changeCloudColor(Vector color, float time);
98
99    void setColorSkyX(float color);
100    void setColorSkyY(float color);
101    void setColorSkyZ(float color);
102    void setColorCloudX(float color);
103    void setColorCloudY(float color);
104    void setColorCloudZ(float color);
105
106    static Vector cloudColor;
107    static Vector skyColor;
108
109    void make3DNoiseTexture();
110    void initNoise();
111    void SetNoiseFrequency(int frequency);
112    double noise3(double vec[3]);
113    void normalize2(double v[2]);
114    void normalize3(double v[3]);
115
116    void generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius,
117                          float hTile, float vTile);
118
119    void shellSkyColor(float colorX, float colorY, float colorZ, float time);
120    void shellCloudColor(float colorX, float colorY, float colorZ, float time);
121
122    static void flashSky(float time);
123
124private:
125
126    bool                    cloudActivate;
127    float                   animationSpeed;
128
129    static Vector           newSkyColor;
130    static Vector           newCloudColor;
131
132    // Material             cloudMaterial;
133    Skydome*                 skydome;
134
135    tAnimation<CloudEffect>*  skyColorFadeX;
136    tAnimation<CloudEffect>*  skyColorFadeY;
137    tAnimation<CloudEffect>*  skyColorFadeZ;
138    tAnimation<CloudEffect>*  cloudColorFadeX;
139    tAnimation<CloudEffect>*  cloudColorFadeY;
140    tAnimation<CloudEffect>*  cloudColorFadeZ;
141    static bool fadeSky;
142    static bool fadeCloud;
143    static float fadeTime;
144
145    // SHADER STUFF
146    Shader*          shader;
147    Shader::Uniform* offset;
148    Shader::Uniform* skycolor;
149    Shader::Uniform* cloudcolor;
150    float            offsetZ;
151    float            scale;
152    float            planetRadius;
153    float            atmosphericRadius;
154    int              divs;
155
156    // NOISE STUFF
157    int              noise3DTexSize;
158    GLuint           noise3DTexName;
159    GLubyte          *noise3DTexPtr;
160
161    int              p[MAXB + MAXB + 2];
162    double           g3[MAXB + MAXB + 2][3];
163    double           g2[MAXB + MAXB + 2][2];
164    double           g1[MAXB + MAXB + 2];
165
166    int              start;
167    int              B;
168    int              BM;
169
170    static bool      flashSkyActivate;
171    static float     localTimer;
172    static float     flashTime;
173
174};
175
176#endif  /* _CLOUD_EFFECT */
Note: See TracBrowser for help on using the repository browser.