[7679] | 1 | /** |
---|
| 2 | * @file cloud_effect.h |
---|
| 3 | */ |
---|
| 4 | |
---|
| 5 | #ifndef _CLOUD_EFFECT |
---|
| 6 | #define _CLOUD_EFFECT |
---|
| 7 | |
---|
| 8 | #include "weather_effect.h" |
---|
| 9 | |
---|
| 10 | #include "sound_buffer.h" |
---|
| 11 | #include "sound_source.h" |
---|
| 12 | |
---|
[8730] | 13 | #include "skydome.h" |
---|
[8495] | 14 | #include "material.h" |
---|
| 15 | #include "shader.h" |
---|
[8255] | 16 | |
---|
[8636] | 17 | #define MAXB 0x100 |
---|
| 18 | #define N 0x1000 |
---|
| 19 | #define NP 12 /* 2^N */ |
---|
| 20 | #define NM 0xfff |
---|
| 21 | |
---|
| 22 | #define s_curve(t) ( t * t * (3. - 2. * t) ) |
---|
| 23 | #define lerp(t, a, b) ( a + t * (b - a) ) |
---|
| 24 | #define setup(i,b0,b1,r0,r1)\ |
---|
| 25 | t = vec[i] + N;\ |
---|
| 26 | b0 = ((int)t) & BM;\ |
---|
| 27 | b1 = (b0+1) & BM;\ |
---|
| 28 | r0 = t - (int)t;\ |
---|
| 29 | r1 = r0 - 1.; |
---|
| 30 | #define at2(rx,ry) ( rx * q[0] + ry * q[1] ) |
---|
| 31 | #define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] ) |
---|
| 32 | |
---|
[8668] | 33 | |
---|
[8636] | 34 | class CloudEffect : public WeatherEffect |
---|
| 35 | { |
---|
[8495] | 36 | public: |
---|
[8636] | 37 | CloudEffect(const TiXmlElement* root = NULL); |
---|
| 38 | virtual ~CloudEffect(); |
---|
[8255] | 39 | |
---|
[8636] | 40 | virtual void loadParams(const TiXmlElement* root); |
---|
[8255] | 41 | |
---|
[8636] | 42 | virtual void init(); |
---|
[7679] | 43 | |
---|
[8636] | 44 | virtual void activate(); |
---|
| 45 | virtual void deactivate(); |
---|
[7679] | 46 | |
---|
[8636] | 47 | inline void activateCloud() |
---|
[8668] | 48 | { this->activate(); } |
---|
| 49 | |
---|
[8636] | 50 | inline void deactivateCloud() |
---|
[8668] | 51 | { this->deactivate(); } |
---|
| 52 | |
---|
[8663] | 53 | inline void setCloudOption(const std::string& option) |
---|
| 54 | { |
---|
| 55 | if (option == "activate") |
---|
| 56 | this->cloudActivate = true; |
---|
| 57 | } |
---|
[8668] | 58 | |
---|
[8663] | 59 | inline void setAnimationSpeed(float speed) |
---|
[8668] | 60 | { this->animationSpeed = speed; } |
---|
[7679] | 61 | |
---|
[8668] | 62 | inline void setCloudScale(float scale) |
---|
| 63 | { this->scale = scale; } |
---|
| 64 | |
---|
| 65 | inline void setPlanetRadius(float planetRadius) |
---|
| 66 | { this->planetRadius = planetRadius; } |
---|
| 67 | |
---|
| 68 | inline void setAtmosphericRadius(float atmosphericRadius) |
---|
| 69 | { this->atmosphericRadius = atmosphericRadius; } |
---|
| 70 | |
---|
| 71 | inline void setDivisions(int divs) |
---|
| 72 | { this->divs = divs; } |
---|
| 73 | |
---|
[8636] | 74 | virtual void draw() const; |
---|
| 75 | virtual void tick(float dt); |
---|
[7679] | 76 | |
---|
[8636] | 77 | void make3DNoiseTexture(); |
---|
| 78 | void initNoise(); |
---|
| 79 | void SetNoiseFrequency(int frequency); |
---|
| 80 | double noise3(double vec[3]); |
---|
| 81 | void normalize2(double v[2]); |
---|
| 82 | void normalize3(double v[3]); |
---|
[7679] | 83 | |
---|
[8668] | 84 | void generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius, |
---|
| 85 | float hTile, float vTile); |
---|
[8495] | 86 | private: |
---|
[8255] | 87 | |
---|
[8668] | 88 | bool cloudActivate; |
---|
| 89 | float animationSpeed; |
---|
[7768] | 90 | |
---|
[8636] | 91 | // Material cloudMaterial; |
---|
[8730] | 92 | Skydome* skydome; |
---|
[8668] | 93 | |
---|
| 94 | // SHADER STUFF |
---|
| 95 | Shader* shader; |
---|
| 96 | Shader::Uniform* offset; |
---|
| 97 | float offsetZ; |
---|
| 98 | float scale; |
---|
| 99 | float planetRadius; |
---|
| 100 | float atmosphericRadius; |
---|
| 101 | int divs; |
---|
[8636] | 102 | |
---|
[8668] | 103 | // NOISE STUFF |
---|
| 104 | int noise3DTexSize; |
---|
| 105 | GLuint noise3DTexName; |
---|
| 106 | GLubyte *noise3DTexPtr; |
---|
[8663] | 107 | |
---|
[8668] | 108 | int p[MAXB + MAXB + 2]; |
---|
| 109 | double g3[MAXB + MAXB + 2][3]; |
---|
| 110 | double g2[MAXB + MAXB + 2][2]; |
---|
| 111 | double g1[MAXB + MAXB + 2]; |
---|
[8636] | 112 | |
---|
[8668] | 113 | int start; |
---|
| 114 | int B; |
---|
| 115 | int BM; |
---|
[7679] | 116 | }; |
---|
| 117 | |
---|
| 118 | #endif /* _CLOUD_EFFECT */ |
---|