Changeset 7784 in orxonox.OLD for branches/atmospheric_engine/src/lib
- Timestamp:
- May 24, 2006, 2:59:44 AM (19 years ago)
- Location:
- branches/atmospheric_engine/src/lib/graphics/effects
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc
r7782 r7784 19 19 20 20 #include "glincl.h" 21 #include "graphics_engine.h" 22 21 //#include "graphics_engine.h" 23 22 24 23 #include "parser/tinyxml/tinyxml.h" … … 48 47 { 49 48 WeatherEffect::loadParams(root); 49 50 LoadParam(root, "animSpeed", this, CloudEffect, setCloudAnimation); 51 50 52 } 51 53 … … 53 55 bool CloudEffect::init() 54 56 { 55 //Default values 56 57 CloudEffect::setNoise(map32); 58 59 } 60 61 bool CloudEffect::activate() 62 { 63 PRINTF(0)( "Activating CloudEffect\n"); 64 65 //Our cloud function 66 CloudEffect::overlapOctaves(map32, map256); 67 CloudEffect::expFilter(map256); 68 69 for(int i=0; i<256; i++) //Set cloud color value to temporary array 70 for(int j=0; j<256; j++) 71 { 72 float color = map256[i*256+j]; 73 texture[i][j][0] = (char) color; 74 texture[i][j][1] = (char) color; 75 texture[i][j][2] = (char) color; 76 } 77 78 /* for(int n=0; n<256; n++) { 79 for(int i=0; i<256; i++) 80 PRINTF(0)("%f ", map256[n*i]); 81 PRINTF(0)("\n"); 82 } */ 57 // default values 58 this->cloudAnimTimeStep = 0; 83 59 84 60 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); … … 87 63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 88 64 89 glGenTextures(1, &texID[0]); //Texture binding 65 // Generate noise map a 66 CloudEffect::genNoiseMap(cloudMap32_a); 67 68 if (this->cloudAnimTimeStep > 0) { 69 // Generate noise map b 70 CloudEffect::genNoiseMap(cloudMap32_b); 71 } 72 } 73 74 bool CloudEffect::activate() 75 { 76 PRINTF(0)( "Activating CloudEffect\n"); 77 if (this->cloudAnimTimeStep == 0) { 78 for (int i = 0; i < 32*32; i++) 79 cloudMap32_c[i] = cloudMap32_a[i]; 80 81 CloudEffect::overlapOctaves(); 82 CloudEffect::expFilter(); 83 CloudEffect::genCloudTexture(); 84 } 85 } 86 87 bool CloudEffect::deactivate() 88 { 89 PRINTF(0)("Deactivating CloudEffect\n"); 90 } 91 92 void CloudEffect::genCloudTexture() { 93 for(int i=0; i<256; i++) 94 for(int j=0; j<256; j++) 95 { 96 float color = cloudMap256[i*256+j]; 97 cloudTexture[i][j][0] = (char) color; 98 cloudTexture[i][j][1] = (char) color; 99 cloudTexture[i][j][2] = (char) color; 100 } 101 102 glGenTextures(2, &texID[0]); 90 103 glBindTexture(GL_TEXTURE_2D, texID[0]); 91 92 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, texture); 93 } 94 95 96 bool CloudEffect::deactivate()97 { 98 PRINTF(0)("Deactivating CloudEffect\n"); 104 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, cloudTexture); 105 } 106 107 void CloudEffect::calcAnimMap(float timer) { 108 109 for (int x=0; x<32*32; x++) 110 cloudMap32_c[x] = (cloudMap32_a[x] * ((this->cloudAnimTimeStep - timer) / this->cloudAnimTimeStep)) + (cloudMap32_b[x] * (timer / this->cloudAnimTimeStep)); 111 99 112 } 100 113 101 114 void CloudEffect::draw() const 102 115 { 103 //glPushAttrib(GL_ENABLE_BIT);104 //glMatrixMode(GL_MODELVIEW);105 106 116 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 107 117 … … 109 119 glEnable(GL_TEXTURE_2D); 110 120 111 //glLoadIdentity();112 121 glBindTexture(GL_TEXTURE_2D, texID[0]); 113 122 114 //glMatrixMode(GL_TEXTURE); //Let's move the clouds from left to right 115 //static float x; 116 //x+=0.01f; 117 //glTranslatef(x,0,0); 118 123 // FIXME : Bind this to the sky - how do I do this? 119 124 glBegin(GL_QUADS); 120 // Front Face121 125 glTexCoord2f(0.0f, 0.0f); glVertex3f(20, 20, 60); // Bottom Left Of The Texture and Quad 122 126 glTexCoord2f(1.0f, 0.0f); glVertex3f(60, 20, 60); // Bottom Right Of The Texture and Quad … … 126 130 127 131 glPopMatrix(); 128 //glPopAttrib();129 130 132 } 131 133 132 134 void CloudEffect::tick (float dt) 133 135 { 136 if (this->cloudAnimTimeStep > 0) { 137 if (timer >= this->cloudAnimTimeStep) { 138 timer -= this->cloudAnimTimeStep; 139 for (int i = 0; i < 32*32; i++) 140 cloudMap32_a[i] = cloudMap32_b[i]; 141 CloudEffect::genNoiseMap(cloudMap32_b); 142 } 143 144 //map32anim = (map32a * (10 - timer)) + (map32b * timer); 145 CloudEffect::calcAnimMap(timer); 146 147 CloudEffect::overlapOctaves(); 148 CloudEffect::expFilter(); 149 CloudEffect::genCloudTexture(); 150 151 timer += dt; 152 } 134 153 } 135 154 … … 148 167 Set noise for the 32*32 noise map: 149 168 */ 150 void CloudEffect:: setNoise(float *map)169 void CloudEffect::genNoiseMap(float *map) 151 170 { 152 171 float temp[34][34]; 153 154 /* We declare a temporary array to make our function cleaner. Why does the array hold 34*34 elements instead of 32*32? This is because we will need extra elements for side and corner mirroring, as we shall see soon. */155 172 156 173 int random = rand() % 5000; … … 181 198 float corners = (temp[x+1][y+1] + temp[x+1][y-1] + temp[x-1][y+1] + temp[x-1][y-1])/16.0f; 182 199 183 map 32[((x-1)*32) + (y-1)] = center + sides + corners;200 map[((x-1)*32) + (y-1)] = center + sides + corners; 184 201 } 185 202 } … … 211 228 Octaves are overlapped together to give cloud more turbulence. We will use four octaves for our cloud. 212 229 */ 213 void CloudEffect::overlapOctaves( float *map32, float *map256)230 void CloudEffect::overlapOctaves() 214 231 { 215 232 for (int x=0; x<256*256; x++) 216 233 { 217 map256[x] = 0;234 cloudMap256[x] = 0; 218 235 } 219 236 … … 223 240 { 224 241 float scale = 1 / pow(2, 3-octave); 225 float noise = CloudEffect::interpolate(x*scale, y*scale , map32);242 float noise = CloudEffect::interpolate(x*scale, y*scale , cloudMap32_c); 226 243 227 244 //The octaves are added together with the proper weight factors. 228 245 //You could replace pow(2, i) with 1<<i for faster computation 229 map256[(y*256) + x] += noise / pow(2, octave);246 cloudMap256[(y*256) + x] += noise / pow(2, octave); 230 247 } 231 248 } … … 235 252 Filter the noise with exponential function 236 253 */ 237 void CloudEffect::expFilter( float *map)254 void CloudEffect::expFilter() 238 255 { 239 256 float cover = 20.0f; … … 242 259 for (int x=0; x<256*256; x++) 243 260 { 244 float c = map[x] - (255.0f-cover);261 float c = cloudMap256[x] - (255.0f-cover); 245 262 if (c<0) c = 0; 246 map[x] = 255.0f - ((float)(pow(sharpness, c))*255.0f); 247 } 248 } 263 cloudMap256[x] = 255.0f - ((float)(pow(sharpness, c))*255.0f); 264 } 265 } 266 267 -
branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h
r7782 r7784 30 30 virtual void tick(float dt); 31 31 32 inline void setCloudAnimation(float timestep) { this->cloudAnimTimeStep = timestep; } 33 32 34 private: 33 // Basic noise map 32x32 34 float map32[32 * 32]; 35 // Basic noise maps 32x32 36 float cloudMap32_a[32 * 32]; 37 float cloudMap32_b[32 * 32]; 38 float cloudMap32_c[32 * 32]; 35 39 36 // The cloud map 37 float map256[256 * 256];40 // The cloud map 256x256 41 float cloudMap256[256 * 256]; 38 42 39 char texture[256][256][3]; //Temporary array to hold texture RGB values 43 // Temporary array to hold texture RGB values 44 char cloudTexture[256][256][3]; 40 45 41 float noise(int x, int y, int random); 42 void setNoise(float *map); 43 float interpolate(float x, float y, float *map); 44 void overlapOctaves(float *map32, float *map256); 45 void expFilter(float *map); 46 GLuint texID[1]; 46 GLuint texID[2]; 47 float timer; 48 49 bool cloudAnimTimeStep; 50 51 float noise(int x, int y, int random); 52 float interpolate(float x, float y, float *map); 53 void overlapOctaves(); 54 void expFilter(); 55 56 void genNoiseMap(float *map); 57 void genCloudTexture(); 58 void calcAnimMap(float timer); 47 59 48 60 }; -
branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.cc
r7696 r7784 74 74 WeatherEffect::loadParams(root); 75 75 76 // LoadParam(root, "moverain", this, RainEffect, setMoveRain);77 76 LoadParam(root, "coord", this, RainEffect, setRainCoord); 78 77 LoadParam(root, "size", this, RainEffect, setRainSize);
Note: See TracChangeset
for help on using the changeset viewer.