[7679] | 1 | /** |
---|
[8793] | 2 | * @file cloud_effect.h |
---|
| 3 | * Creates 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 | |
---|
| 34 | |
---|
| 35 | class CloudEffect : public WeatherEffect |
---|
| 36 | { |
---|
[8495] | 37 | public: |
---|
[8793] | 38 | CloudEffect(const TiXmlElement* root = NULL); |
---|
| 39 | virtual ~CloudEffect(); |
---|
[8255] | 40 | |
---|
[8793] | 41 | virtual void loadParams(const TiXmlElement* root); |
---|
[8255] | 42 | |
---|
[8793] | 43 | virtual void init(); |
---|
[7679] | 44 | |
---|
[8793] | 45 | virtual void activate(); |
---|
| 46 | virtual void deactivate(); |
---|
[7679] | 47 | |
---|
[8793] | 48 | inline void activateCloud() |
---|
| 49 | { this->activate(); } |
---|
[7679] | 50 | |
---|
[8793] | 51 | inline void deactivateCloud() |
---|
| 52 | { this->deactivate(); } |
---|
[7679] | 53 | |
---|
[8793] | 54 | inline void setCloudOption(const std::string& option) |
---|
| 55 | { |
---|
| 56 | if (option == "activate") |
---|
| 57 | this->cloudActivate = true; |
---|
| 58 | } |
---|
[7679] | 59 | |
---|
[8793] | 60 | inline void setAnimationSpeed(float speed) |
---|
| 61 | { this->animationSpeed = speed; } |
---|
[7784] | 62 | |
---|
[8793] | 63 | inline void setCloudScale(float scale) |
---|
| 64 | { this->scale = scale; } |
---|
| 65 | |
---|
| 66 | inline void setCloudColor(float colorX, float colorY, float colorZ) |
---|
| 67 | { this->cloudColor = Vector(colorX, colorY, colorZ); } |
---|
| 68 | |
---|
| 69 | inline void setSkyColor(float colorX, float colorY, float colorZ) |
---|
| 70 | { this->skyColor = Vector(colorX, colorY, colorZ); } |
---|
| 71 | |
---|
| 72 | inline void setPlanetRadius(float planetRadius) |
---|
| 73 | { this->planetRadius = planetRadius; } |
---|
| 74 | |
---|
| 75 | inline void setAtmosphericRadius(float atmosphericRadius) |
---|
| 76 | { this->atmosphericRadius = atmosphericRadius; } |
---|
| 77 | |
---|
| 78 | inline void setDivisions(int divs) |
---|
| 79 | { this->divs = divs; } |
---|
| 80 | |
---|
| 81 | virtual void draw() const; |
---|
| 82 | virtual void tick(float dt); |
---|
| 83 | |
---|
| 84 | static void changeSkyColor(Vector color); |
---|
| 85 | static void changeCloudColor(Vector color); |
---|
| 86 | |
---|
| 87 | static Vector cloudColor; |
---|
| 88 | static Vector skyColor; |
---|
| 89 | |
---|
| 90 | void make3DNoiseTexture(); |
---|
| 91 | void initNoise(); |
---|
| 92 | void SetNoiseFrequency(int frequency); |
---|
| 93 | double noise3(double vec[3]); |
---|
| 94 | void normalize2(double v[2]); |
---|
| 95 | void normalize3(double v[3]); |
---|
| 96 | |
---|
| 97 | void generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius, |
---|
| 98 | float hTile, float vTile); |
---|
[8495] | 99 | private: |
---|
[8255] | 100 | |
---|
[8793] | 101 | bool cloudActivate; |
---|
| 102 | float animationSpeed; |
---|
| 103 | float fadeTime; |
---|
| 104 | |
---|
| 105 | static Vector newSkyColor; |
---|
| 106 | static Vector newCloudColor; |
---|
[7768] | 107 | |
---|
[8793] | 108 | // Material cloudMaterial; |
---|
| 109 | Skydome* skydome; |
---|
| 110 | |
---|
| 111 | // SHADER STUFF |
---|
| 112 | Shader* shader; |
---|
| 113 | Shader::Uniform* offset; |
---|
| 114 | Shader::Uniform* skycolor; |
---|
| 115 | Shader::Uniform* cloudcolor; |
---|
| 116 | float offsetZ; |
---|
| 117 | float scale; |
---|
| 118 | float planetRadius; |
---|
| 119 | float atmosphericRadius; |
---|
| 120 | int divs; |
---|
| 121 | |
---|
| 122 | // NOISE STUFF |
---|
| 123 | int noise3DTexSize; |
---|
| 124 | GLuint noise3DTexName; |
---|
| 125 | GLubyte *noise3DTexPtr; |
---|
| 126 | |
---|
| 127 | int p[MAXB + MAXB + 2]; |
---|
| 128 | double g3[MAXB + MAXB + 2][3]; |
---|
| 129 | double g2[MAXB + MAXB + 2][2]; |
---|
| 130 | double g1[MAXB + MAXB + 2]; |
---|
| 131 | |
---|
| 132 | int start; |
---|
| 133 | int B; |
---|
| 134 | int BM; |
---|
[7679] | 135 | }; |
---|
| 136 | |
---|
| 137 | #endif /* _CLOUD_EFFECT */ |
---|