[7679] | 1 | /** |
---|
[8793] | 2 | * @file cloud_effect.h |
---|
[9006] | 3 | * Create clouds |
---|
[7679] | 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 | |
---|
[8793] | 14 | #include "skydome.h" |
---|
[8495] | 15 | #include "material.h" |
---|
| 16 | #include "shader.h" |
---|
[8255] | 17 | |
---|
[8793] | 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 | |
---|
[9006] | 34 | // FORWARD DECLARATION |
---|
| 35 | template <class T> |
---|
| 36 | class tAnimation; |
---|
[8793] | 37 | |
---|
[9006] | 38 | class CloudEffect : public WeatherEffect { |
---|
| 39 | |
---|
[8495] | 40 | public: |
---|
[8255] | 41 | |
---|
[9006] | 42 | CloudEffect(const TiXmlElement* root = NULL); |
---|
| 43 | virtual ~CloudEffect(); |
---|
[8255] | 44 | |
---|
[9006] | 45 | virtual void loadParams(const TiXmlElement* root); |
---|
[7679] | 46 | |
---|
[9006] | 47 | virtual void init(); |
---|
[7679] | 48 | |
---|
[9006] | 49 | virtual void activate(); |
---|
| 50 | virtual void deactivate(); |
---|
[7679] | 51 | |
---|
[9006] | 52 | void activateCloud() { |
---|
| 53 | this->activate(); |
---|
| 54 | } |
---|
| 55 | void deactivateCloud() { |
---|
| 56 | this->deactivate(); |
---|
| 57 | } |
---|
[7679] | 58 | |
---|
[9006] | 59 | void setCloudOption(const std::string& option) { |
---|
| 60 | if (option == "activate") |
---|
| 61 | this->cloudActivate = true; |
---|
| 62 | } |
---|
[7679] | 63 | |
---|
[9006] | 64 | void setAnimationSpeed(float speed) { |
---|
| 65 | this->animationSpeed = speed; |
---|
| 66 | } |
---|
[7784] | 67 | |
---|
[9006] | 68 | void setCloudScale(float scale) { |
---|
| 69 | this->scale = scale; |
---|
| 70 | } |
---|
[8793] | 71 | |
---|
[9006] | 72 | void setCloudColor(float colorX, float colorY, float colorZ) { |
---|
| 73 | this->cloudColor = Vector(colorX, colorY, colorZ); |
---|
| 74 | } |
---|
[8793] | 75 | |
---|
[9006] | 76 | void setSkyColor(float colorX, float colorY, float colorZ) { |
---|
| 77 | this->skyColor = Vector(colorX, colorY, colorZ); |
---|
| 78 | } |
---|
[8793] | 79 | |
---|
[9006] | 80 | void setPlanetRadius(float planetRadius) { |
---|
| 81 | this->planetRadius = planetRadius; |
---|
| 82 | } |
---|
[8793] | 83 | |
---|
[9006] | 84 | void setAtmosphericRadius(float atmosphericRadius) { |
---|
| 85 | this->atmosphericRadius = atmosphericRadius; |
---|
| 86 | } |
---|
[8793] | 87 | |
---|
[9006] | 88 | void setDivisions(int divs) { |
---|
| 89 | this->divs = divs; |
---|
| 90 | } |
---|
[8793] | 91 | |
---|
[9006] | 92 | virtual void draw() const; |
---|
| 93 | virtual void tick(float dt); |
---|
[8793] | 94 | |
---|
[9006] | 95 | static void changeSkyColor(Vector color, float time); |
---|
| 96 | static void changeCloudColor(Vector color, float time); |
---|
[8793] | 97 | |
---|
[9006] | 98 | void setColorSkyX(float color); |
---|
| 99 | void setColorSkyY(float color); |
---|
| 100 | void setColorSkyZ(float color); |
---|
| 101 | void setColorCloudX(float color); |
---|
| 102 | void setColorCloudY(float color); |
---|
| 103 | void setColorCloudZ(float color); |
---|
[8793] | 104 | |
---|
[9006] | 105 | static Vector cloudColor; |
---|
| 106 | static Vector skyColor; |
---|
| 107 | |
---|
| 108 | void make3DNoiseTexture(); |
---|
| 109 | void initNoise(); |
---|
| 110 | void SetNoiseFrequency(int frequency); |
---|
| 111 | double noise3(double vec[3]); |
---|
| 112 | void normalize2(double v[2]); |
---|
| 113 | void normalize3(double v[3]); |
---|
| 114 | |
---|
| 115 | void generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius, |
---|
| 116 | float hTile, float vTile); |
---|
| 117 | |
---|
| 118 | void shellSkyColor(float colorX, float colorY, float colorZ, float time); |
---|
| 119 | void shellCloudColor(float colorX, float colorY, float colorZ, float time); |
---|
| 120 | |
---|
| 121 | |
---|
[8495] | 122 | private: |
---|
[8255] | 123 | |
---|
[9006] | 124 | bool cloudActivate; |
---|
| 125 | float animationSpeed; |
---|
[7768] | 126 | |
---|
[9006] | 127 | static Vector newSkyColor; |
---|
| 128 | static Vector newCloudColor; |
---|
[8793] | 129 | |
---|
[9006] | 130 | // Material cloudMaterial; |
---|
| 131 | Skydome* skydome; |
---|
[8793] | 132 | |
---|
[9006] | 133 | tAnimation<CloudEffect>* skyColorFadeX; |
---|
| 134 | tAnimation<CloudEffect>* skyColorFadeY; |
---|
| 135 | tAnimation<CloudEffect>* skyColorFadeZ; |
---|
| 136 | tAnimation<CloudEffect>* cloudColorFadeX; |
---|
| 137 | tAnimation<CloudEffect>* cloudColorFadeY; |
---|
| 138 | tAnimation<CloudEffect>* cloudColorFadeZ; |
---|
| 139 | static bool fadeSky; |
---|
| 140 | static bool fadeCloud; |
---|
| 141 | static float fadeTime; |
---|
[8793] | 142 | |
---|
[9006] | 143 | // SHADER STUFF |
---|
| 144 | Shader* shader; |
---|
| 145 | Shader::Uniform* offset; |
---|
| 146 | Shader::Uniform* skycolor; |
---|
| 147 | Shader::Uniform* cloudcolor; |
---|
| 148 | float offsetZ; |
---|
| 149 | float scale; |
---|
| 150 | float planetRadius; |
---|
| 151 | float atmosphericRadius; |
---|
| 152 | int divs; |
---|
[8793] | 153 | |
---|
[9006] | 154 | // NOISE STUFF |
---|
| 155 | int noise3DTexSize; |
---|
| 156 | GLuint noise3DTexName; |
---|
| 157 | GLubyte *noise3DTexPtr; |
---|
| 158 | |
---|
| 159 | int p[MAXB + MAXB + 2]; |
---|
| 160 | double g3[MAXB + MAXB + 2][3]; |
---|
| 161 | double g2[MAXB + MAXB + 2][2]; |
---|
| 162 | double g1[MAXB + MAXB + 2]; |
---|
| 163 | |
---|
| 164 | int start; |
---|
| 165 | int B; |
---|
| 166 | int BM; |
---|
| 167 | |
---|
| 168 | |
---|
[7679] | 169 | }; |
---|
| 170 | |
---|
| 171 | #endif /* _CLOUD_EFFECT */ |
---|