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