- Timestamp:
- Jun 26, 2006, 3:36:16 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 17 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defs/class_id.h
r8783 r8793 186 186 CL_MAPPED_WATER = 0x00000311, 187 187 CL_BSP_ENTITY = 0x00000312, 188 CL_SKYDOME = 0x00000313, 188 189 189 190 // Playables -
trunk/src/lib/graphics/effects/cloud_effect.cc
r8495 r8793 1 1 /* 2 3 4 5 6 7 8 9 10 2 orxonox - the future of 3D-vertical-scrollers 3 4 Copyright (C) 2004 orx 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 11 ### File Specific: 12 13 14 12 main-programmer: hdavid, amaechler 13 14 INSPIRED BY http://www.codesampler.com/usersrc/usersrc_6.htm#oglu_sky_dome_shader 15 15 */ 16 16 … … 22 22 23 23 #include "material.h" 24 #include <math.h>25 24 #include "state.h" 26 25 #include "p_node.h" … … 30 29 #include "parser/tinyxml/tinyxml.h" 31 30 31 Vector CloudEffect::cloudColor; 32 Vector CloudEffect::skyColor; 33 Vector CloudEffect::newCloudColor; 34 Vector CloudEffect::newSkyColor; 32 35 33 36 using namespace std; … … 40 43 CloudEffect::CloudEffect(const TiXmlElement* root) 41 44 { 42 this->setClassID(CL_CLOUD_EFFECT, "CloudEffect"); 43 // this->toList(OM_ENVIRON); 44 45 this->init(); 46 47 if (root != NULL) 48 this->loadParams(root); 49 50 //if(cloudActivate) 51 this->activate(); 45 this->setClassID(CL_CLOUD_EFFECT, "CloudEffect"); 46 47 this->init(); 48 49 if (root != NULL) 50 this->loadParams(root); 51 52 if(cloudActivate) 53 this->activate(); 52 54 } 53 55 54 56 CloudEffect::~CloudEffect() 55 57 { 56 this->deactivate(); 58 this->deactivate(); 59 60 if (glIsTexture(noise3DTexName)) 61 glDeleteTextures(1, &noise3DTexName); 62 63 delete shader; 57 64 } 58 65 … … 60 67 void CloudEffect::init() 61 68 { 62 PRINTF(0)("Initializing CloudEffect\n"); 63 64 /// initialization of the texture coords, speeds etc... 65 /* this->move = 0.0f; 66 this->g_WaterUV = 35.0f; 67 this->kNormalMapScale = 0.25f; 68 this->g_WaterFlow = 0.0015f;*/ 69 70 cloudMaterial.setDiffuseMap("pictures/sky/cloud1.jpg", GL_TEXTURE_2D, 0); 71 72 shader = new Shader(ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.vert", 73 ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.frag"); 74 69 PRINTF(0)("Initializing CloudEffect\n"); 70 71 this->offsetZ = 0; 72 this->animationSpeed = 2; 73 this->scale = 0.0004f; 74 this->atmosphericRadius = 4000; 75 this->planetRadius = 1500; 76 this->divs = 50; 77 78 skyColor = Vector(0.0f, 0.0f, 0.8f); 79 cloudColor = Vector(0.8f, 0.8f, 0.8f); 80 newSkyColor = skyColor; 81 newCloudColor = cloudColor; 82 this->fadeTime = 3; 83 84 this->noise3DTexSize = 128; 85 this->noise3DTexName = 0; 86 87 this->make3DNoiseTexture(); 88 89 glGenTextures(1, &noise3DTexName); 90 glBindTexture(GL_TEXTURE_3D, noise3DTexName); 91 92 glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT); 93 glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT); 94 glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT); 95 glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 96 glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 97 98 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 99 noise3DTexSize, noise3DTexSize, noise3DTexSize, 100 0, GL_RGBA, GL_UNSIGNED_BYTE, noise3DTexPtr); 101 102 this->skydome = new Skydome(); 103 this->skydome->setTexture(noise3DTexName); 104 105 this->shader = new Shader(ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.vert", 106 ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.frag"); 107 75 108 this->shader->activateShader(); 76 109 77 110 Shader::Uniform(shader, "Noise").set(0); 78 Shader::Uniform(shader, "SkyColor").set(0.0f, 0.0f, 0.8f); 79 Shader::Uniform(shader, "CloudColor").set(0.8f, 0.8f, 0.8f); 80 81 // Change: Have to be updated each frame!like camerpos in mapped_water.cc 82 Shader::Uniform(shader, "Offset").set(0.0f, 0.0f, 0.0f); 83 84 Shader::Uniform(shader, "LightPos").set(100.0f, 100.0f, 100.0f); 85 Shader::Uniform(shader, "Scale").set(1.0f); 86 111 112 this->offset = new Shader::Uniform(shader, "Offset"); 113 this->skycolor = new Shader::Uniform(shader, "SkyColor"); 114 this->cloudcolor = new Shader::Uniform(shader, "CloudColor"); 115 87 116 this->shader->deactivateShader(); 117 118 this->skydome->setShader(shader); 88 119 } 89 120 … … 91 122 void CloudEffect::loadParams(const TiXmlElement* root) 92 123 { 93 WeatherEffect::loadParams(root); 94 95 // LoadParam(root, "speed", this, CloudEffect, setCloudAnimation); 96 // LoadParam(root, "texture", this, CloudEffect, setCloudTexture); 97 /* 98 LOAD_PARAM_START_CYCLE(root, element); 99 { 100 LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption); 101 } 102 LOAD_PARAM_END_CYCLE(element);*/ 124 WeatherEffect::loadParams(root); 125 126 LoadParam(root, "speed", this, CloudEffect, setAnimationSpeed); 127 LoadParam(root, "scale", this, CloudEffect, setCloudScale); 128 LoadParam(root, "cloudcolor", this, CloudEffect, setCloudColor); 129 LoadParam(root, "skycolor", this, CloudEffect, setSkyColor); 130 131 LoadParam(root, "planetRadius", this, CloudEffect, setPlanetRadius); 132 LoadParam(root, "atmosphericRadius", this, CloudEffect, setAtmosphericRadius); 133 LoadParam(root, "divisions", this, CloudEffect, setDivisions); 134 135 LOAD_PARAM_START_CYCLE(root, element); 136 { 137 LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption); 138 } 139 LOAD_PARAM_END_CYCLE(element); 103 140 } 104 141 … … 106 143 void CloudEffect::activate() 107 144 { 108 PRINTF(0)( "Activating\n"); 109 110 // this->cloudActivate = true; 145 PRINTF(0)( "Activating\n"); 146 147 // Can only be set after the loadParams call 148 this->shader->activateShader(); 149 Shader::Uniform(shader, "Scale").set(this->scale); 150 this->skycolor->set(skyColor.x, skyColor.y, skyColor.z); 151 this->cloudcolor->set(cloudColor.x, cloudColor.y, cloudColor.z); 152 this->shader->deactivateShader(); 153 154 this->skydome->generateSkyPlane(this->divs, this->planetRadius, this->atmosphericRadius, 1, 1); 155 156 this->cloudActivate = true; 111 157 } 112 158 113 159 void CloudEffect::deactivate() 114 160 { 115 116 117 //this->cloudActivate = false;161 PRINTF(0)("Deactivating CloudEffect\n"); 162 163 this->cloudActivate = false; 118 164 } 119 165 120 166 void CloudEffect::draw() const 121 { 122 //if (!this->cloudActivate) 123 // return; 124 125 //glMatrixMode(GL_MODELVIEW); 126 //glColor4f(1,1,1,1); 127 glPushMatrix(); 128 //glTranslatef(0,this->waterHeight,0); 129 130 cloudMaterial.unselect(); 131 cloudMaterial.select(); 132 133 this->shader->activateShader(); 134 135 136 glBegin(GL_QUADS); 137 138 glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); 139 glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, 100.0f); 140 glTexCoord2f(0.0f, 0.0f); glVertex3f( 100.0f, 0.0f, 100.0f); 141 glTexCoord2f(1.0f, 0.0f); glVertex3f(100.0f, 0.0f, 0.0f); 142 143 glEnd(); 144 145 this->shader->deactivateShader(); 146 147 cloudMaterial.unselect(); 148 149 glPopMatrix(); 150 151 } 167 {} 152 168 153 169 void CloudEffect::tick (float dt) 154 170 { 155 //if (!this->cloudActivate) 156 // return; 157 } 158 171 if (this->cloudActivate) 172 { 173 this->offsetZ += 0.05 * dt * this->animationSpeed; 174 175 this->shader->activateShader(); 176 this->offset->set(0.0f, 0.0f, offsetZ); 177 178 //if(cloudColor != newCloudColor) 179 //{ 180 // TODO: fade from cloudColor to newCloudColor 181 cloudColor = newCloudColor; 182 this->cloudcolor->set(this->cloudColor.x, this->cloudColor.y, this->cloudColor.z); 183 //} 184 //if(cloudColor != newCloudColor) 185 //{ 186 // TODO: fade from skyColor to newSkyColor 187 skyColor = newSkyColor; 188 this->skycolor->set(this->skyColor.x, this->skyColor.y, this->skyColor.z); 189 //} 190 191 this->shader->deactivateShader(); 192 } 193 } 194 195 196 void CloudEffect::changeSkyColor(Vector color) 197 { 198 newSkyColor = color; 199 } 200 201 202 void CloudEffect::changeCloudColor(Vector color) 203 { 204 newCloudColor = color; 205 } 206 207 208 void CloudEffect::make3DNoiseTexture() 209 { 210 int f, i, j, k, inc; 211 int startFrequency = 4; 212 int numOctaves = 4; 213 double ni[3]; 214 double inci, incj, inck; 215 int frequency = startFrequency; 216 GLubyte *ptr; 217 double amp = 0.5; 218 219 if ((noise3DTexPtr = (GLubyte *) malloc(noise3DTexSize * 220 noise3DTexSize * 221 noise3DTexSize * 4)) == NULL) 222 PRINTF(0)("ERROR: Could not allocate 3D noise texture\n"); 223 224 for (f=0, inc=0; f < numOctaves; 225 ++f, frequency *= 2, ++inc, amp *= 0.5) 226 { 227 SetNoiseFrequency(frequency); 228 ptr = noise3DTexPtr; 229 ni[0] = ni[1] = ni[2] = 0; 230 231 inci = 1.0 / (noise3DTexSize / frequency); 232 for (i=0; i<noise3DTexSize; ++i, ni[0] += inci) 233 { 234 incj = 1.0 / (noise3DTexSize / frequency); 235 for (j=0; j<noise3DTexSize; ++j, ni[1] += incj) 236 { 237 inck = 1.0 / (noise3DTexSize / frequency); 238 for (k=0; k<noise3DTexSize; ++k, ni[2] += inck, ptr+= 4) 239 { 240 *(ptr+inc) = (GLubyte) (((noise3(ni)+1.0) * amp)*128.0); 241 } 242 } 243 } 244 } 245 } 246 247 void CloudEffect::initNoise() 248 { 249 int i, j, k; 250 251 srand(30757); 252 for (i = 0 ; i < B ; i++) 253 { 254 p[i] = i; 255 g1[i] = (double)((rand() % (B + B)) - B) / B; 256 257 for (j = 0 ; j < 2 ; j++) 258 g2[i][j] = (double)((rand() % (B + B)) - B) / B; 259 normalize2(g2[i]); 260 261 for (j = 0 ; j < 3 ; j++) 262 g3[i][j] = (double)((rand() % (B + B)) - B) / B; 263 normalize3(g3[i]); 264 } 265 266 while (--i) 267 { 268 k = p[i]; 269 p[i] = p[j = rand() % B]; 270 p[j] = k; 271 } 272 273 for (i = 0 ; i < B + 2 ; i++) 274 { 275 p[B + i] = p[i]; 276 g1[B + i] = g1[i]; 277 for (j = 0 ; j < 2 ; j++) 278 g2[B + i][j] = g2[i][j]; 279 for (j = 0 ; j < 3 ; j++) 280 g3[B + i][j] = g3[i][j]; 281 } 282 } 283 284 void CloudEffect::SetNoiseFrequency( int frequency) 285 { 286 start = 1; 287 B = frequency; 288 BM = B-1; 289 } 290 291 double CloudEffect::noise3( double vec[3]) 292 { 293 int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11; 294 double rx0, rx1, ry0, ry1, rz0, rz1, *q, sy, sz, a, b, c, d, t, u, v; 295 int i, j; 296 297 if (start) 298 { 299 start = 0; 300 initNoise(); 301 } 302 303 setup(0, bx0,bx1, rx0,rx1); 304 setup(1, by0,by1, ry0,ry1); 305 setup(2, bz0,bz1, rz0,rz1); 306 307 i = p[ bx0 ]; 308 j = p[ bx1 ]; 309 310 b00 = p[ i + by0 ]; 311 b10 = p[ j + by0 ]; 312 b01 = p[ i + by1 ]; 313 b11 = p[ j + by1 ]; 314 315 t = s_curve(rx0); 316 sy = s_curve(ry0); 317 sz = s_curve(rz0); 318 319 q = g3[ b00 + bz0 ] ; u = at3(rx0,ry0,rz0); 320 q = g3[ b10 + bz0 ] ; v = at3(rx1,ry0,rz0); 321 a = lerp(t, u, v); 322 323 q = g3[ b01 + bz0 ] ; u = at3(rx0,ry1,rz0); 324 q = g3[ b11 + bz0 ] ; v = at3(rx1,ry1,rz0); 325 b = lerp(t, u, v); 326 327 c = lerp(sy, a, b); 328 329 q = g3[ b00 + bz1 ] ; u = at3(rx0,ry0,rz1); 330 q = g3[ b10 + bz1 ] ; v = at3(rx1,ry0,rz1); 331 a = lerp(t, u, v); 332 333 q = g3[ b01 + bz1 ] ; u = at3(rx0,ry1,rz1); 334 q = g3[ b11 + bz1 ] ; v = at3(rx1,ry1,rz1); 335 b = lerp(t, u, v); 336 337 d = lerp(sy, a, b); 338 339 return lerp(sz, c, d); 340 } 341 342 void CloudEffect::normalize2( double v[2]) 343 { 344 double s; 345 346 s = sqrt(v[0] * v[0] + v[1] * v[1]); 347 v[0] = v[0] / s; 348 v[1] = v[1] / s; 349 } 350 351 void CloudEffect::normalize3( double v[3]) 352 { 353 double s; 354 355 s = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); 356 v[0] = v[0] / s; 357 v[1] = v[1] / s; 358 v[2] = v[2] / s; 359 } 360 -
trunk/src/lib/graphics/effects/cloud_effect.h
r8495 r8793 1 1 /** 2 * @file cloud_effect.h 2 * @file cloud_effect.h 3 * Creates clouds 3 4 */ 4 5 … … 11 12 #include "sound_source.h" 12 13 13 #include " world_entity.h"14 #include "skydome.h" 14 15 #include "material.h" 15 16 #include "shader.h" 16 17 17 class CloudEffect : public WeatherEffect { 18 public: 19 CloudEffect(const TiXmlElement* root = NULL); 20 virtual ~CloudEffect(); 18 #define MAXB 0x100 19 #define N 0x1000 20 #define NP 12 /* 2^N */ 21 #define NM 0xfff 21 22 22 virtual void loadParams(const TiXmlElement* root); 23 24 virtual void init(); 25 26 virtual void activate(); 27 virtual void deactivate(); 28 29 inline void activateCloud() { 30 this->activate(); 31 } 32 inline void deactivateCloud() { 33 this->deactivate(); 34 } 35 36 virtual void draw() const; 37 virtual void tick(float dt); 38 39 /*inline void setCloudOption(const std::string& option) { 40 if (option == "activate") 41 this->cloudActivate = true; 42 }*/ 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] ) 43 33 44 34 35 class CloudEffect : public WeatherEffect 36 { 37 public: 38 CloudEffect(const TiXmlElement* root = NULL); 39 virtual ~CloudEffect(); 40 41 virtual void loadParams(const TiXmlElement* root); 42 43 virtual void init(); 44 45 virtual void activate(); 46 virtual void deactivate(); 47 48 inline void activateCloud() 49 { this->activate(); } 50 51 inline void deactivateCloud() 52 { this->deactivate(); } 53 54 inline void setCloudOption(const std::string& option) 55 { 56 if (option == "activate") 57 this->cloudActivate = true; 58 } 59 60 inline void setAnimationSpeed(float speed) 61 { this->animationSpeed = speed; } 62 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); 45 99 private: 46 //void initialize(char* fileName);47 100 48 //bool cloudActivate; 101 bool cloudActivate; 102 float animationSpeed; 103 float fadeTime; 104 105 static Vector newSkyColor; 106 static Vector newCloudColor; 49 107 50 Material cloudMaterial; 51 Shader* shader; 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; 52 135 }; 53 136 -
trunk/src/lib/graphics/effects/fog_effect.cc
r8495 r8793 20 20 #include "shell_command.h" 21 21 22 // Define shell commands 22 23 SHELL_COMMAND(activate, FogEffect, activateFog); 23 24 SHELL_COMMAND(deactivate, FogEffect, deactivateFog); … … 25 26 SHELL_COMMAND(fadeout, FogEffect, fadeOutFog); 26 27 27 // TODO: Fix fades28 29 28 using namespace std; 30 29 31 30 CREATE_FACTORY(FogEffect, CL_FOG_EFFECT); 32 31 32 /** 33 * @brief standard constructor 34 */ 33 35 FogEffect::FogEffect(const TiXmlElement* root) { 34 36 this->setClassID(CL_FOG_EFFECT, "FogEffect"); 35 37 38 // Initialize values 36 39 this->init(); 37 40 41 // Load XML params 38 42 if (root != NULL) 39 43 this->loadParams(root); 40 44 45 // Activate fog, if chosen to be activated by default 41 46 if (this->fogActivate) 42 47 this->activate(); 43 48 } 44 49 45 50 /** 51 * @brief standard destructor 52 */ 46 53 FogEffect::~FogEffect() { 47 54 this->deactivate(); 48 55 } 49 56 50 57 /** 58 * @brief initalizes the fog effect with default values 59 */ 60 void FogEffect::init() { 61 // default values 62 this->fogMode = GL_LINEAR; 63 this->fogDensity = 0.005; 64 this->fogStart = 0; 65 this->fogEnd = 300; 66 this->colorVector = Vector(0.6, 0.0, 0.0); 67 68 // init variables 69 this->fogFadeInDuration = 0; 70 this->fogFadeOutDuration = 0; 71 this->fogFadeDensity = 0; 72 this->fogFadeEnd = 0; 73 74 this->localTimer = 0; 75 this->fogActivate = false; 76 this->fogFadeInActivate = false; 77 this->fogFadeOutActivate = false; 78 } 79 80 /** 81 * @brief loads the fog effect parameters. 82 * @param root: the XML-Element to load the data from 83 */ 51 84 void FogEffect::loadParams(const TiXmlElement* root) { 52 85 WeatherEffect::loadParams(root); 53 86 54 LoadParam(root, "mode", this, FogEffect, setFogMode) ;55 LoadParam(root, "density", this, FogEffect, setFogDensity) ;56 LoadParam(root, "range", this, FogEffect, setFogRange) ;57 LoadParam(root, "color", this, FogEffect, setFogColor) ;58 LoadParam(root, "fadeinduration", this, FogEffect, setFogFadeIn) ;59 LoadParam(root, "fadeoutduration", this, FogEffect, setFogFadeOut) ;87 LoadParam(root, "mode", this, FogEffect, setFogMode).describe("fog mode (linear, exponential)");; 88 LoadParam(root, "density", this, FogEffect, setFogDensity).describe("fog density if exp. fog");; 89 LoadParam(root, "range", this, FogEffect, setFogRange).describe("fog range: start, end");; 90 LoadParam(root, "color", this, FogEffect, setFogColor).describe("fog color: r,g,b");; 91 LoadParam(root, "fadeinduration", this, FogEffect, setFogFadeIn).describe("duration of the fade in");; 92 LoadParam(root, "fadeoutduration", this, FogEffect, setFogFadeOut).describe("duration of the fade out");; 60 93 61 94 LOAD_PARAM_START_CYCLE(root, element); 62 95 { 63 LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption);96 LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption).describe("sets a fog option: activate");; 64 97 } 65 98 LOAD_PARAM_END_CYCLE(element); 66 99 } 67 100 68 void FogEffect::init() { 69 // default values 70 this->fogMode = GL_LINEAR; 71 this->fogDensity = 0.03; 72 this->fogStart = 0; 73 this->fogEnd = 50; 74 this->colorVector = Vector(0.3, 0.3, 0.3); 75 76 // init variables 77 this->fogFadeInDuration = 0; 78 this->fogFadeOutDuration = 0; 79 this->fogFadeDensity = 0; 80 this->localTimer = 0; 81 this->fogActivate = false; 82 this->fogFadeInActivate = false; 83 this->fogFadeOutActivate = false; 84 85 } 86 87 101 /** 102 * @brief activates the fog effect 103 */ 88 104 void FogEffect::activate() { 89 PRINTF(0)( "Enabling FogEffect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity, this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z); 90 91 this->fogActivate = true; 92 105 PRINTF(0)( "Activating FogEffect\n"); 106 107 // init fogGL 93 108 GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0}; 94 109 glFogi(GL_FOG_MODE, this->fogMode); … … 99 114 glFogf(GL_FOG_END, this->fogEnd); 100 115 116 this->fogActivate = true; 117 101 118 glEnable(GL_FOG); 102 103 } 104 105 119 } 120 121 /** 122 * @brief deactivates the fog effect 123 */ 106 124 void FogEffect::deactivate() { 107 125 PRINTF(0)("Deactivating FogEffect\n"); … … 112 130 113 131 glDisable(GL_FOG); 114 115 } 116 132 } 133 134 /** 135 * @brief draws the fog effect 136 */ 117 137 void FogEffect::draw() const { 118 138 … … 120 140 return; 121 141 122 // If Fog Fade 123 if ( this->fogFadeInActivate || this->fogFadeOutActivate ) 124 glFogf(GL_FOG_DENSITY, this->fogFadeDensity); 125 126 } 127 142 // If fog is fading 143 if ( this->fogFadeInActivate || this->fogFadeOutActivate ) { 144 if ( this->fogMode == GL_LINEAR) 145 glFogf(GL_FOG_END, this->fogFadeEnd); 146 else 147 glFogf(GL_FOG_DENSITY, this->fogFadeDensity); 148 } 149 } 150 151 /** 152 * @brief ticks the fog effect 153 * @param dt: tick float 154 */ 128 155 void FogEffect::tick(float dt) { 156 129 157 if (!this->fogActivate) 130 158 return; 131 159 160 // If fog is fading in 132 161 if ( this->fogFadeInActivate ) { 133 162 this->localTimer += dt; 134 this->fogFadeDensity = ( this->localTimer / this->fogFadeInDuration ) * this->fogDensity; 135 136 if ( this->localTimer >= this->fogFadeOutDuration ) 163 164 if ( this->fogMode == GL_LINEAR) 165 this->fogFadeEnd = 2000 * (1 - ( this->localTimer / this->fogFadeInDuration )) + this->fogEnd; 166 else 167 this->fogFadeDensity = ( this->localTimer / this->fogFadeInDuration ) * this->fogDensity; 168 169 if ( this->localTimer >= this->fogFadeInDuration ) 137 170 this->fogFadeInActivate = false; 138 171 } 139 172 173 // If fog is fading out 140 174 if ( this->fogFadeOutActivate ) { 141 175 this->localTimer += dt; 142 this->fogFadeDensity = 1 - (( this->localTimer / this->fogFadeInDuration ) * this->fogDensity); 176 177 if ( this->fogMode == GL_LINEAR) 178 this->fogFadeEnd = 2000 * ( this->localTimer / this->fogFadeInDuration ) + this->fogEnd; 179 else 180 this->fogFadeDensity = 1 - (( this->localTimer / this->fogFadeInDuration ) * this->fogDensity); 143 181 144 182 if ( this->localTimer >= this->fogFadeOutDuration ) … … 147 185 } 148 186 187 /** 188 * @brief fades the fog in 189 */ 149 190 void FogEffect::fadeInFog() { 150 191 … … 163 204 this->localTimer = 0; 164 205 206 // Activate Fog 207 this->activate(); 208 165 209 // set FogFadeIn activate 166 210 this->fogFadeInActivate = true; 167 168 // Activate Fog 169 this->activate(); 170 171 } 172 173 211 } 212 213 /** 214 * @brief fades the fog out 215 */ 174 216 void FogEffect::fadeOutFog() { 175 217 … … 190 232 // Reset local timer 191 233 this->localTimer = 0; 192 193 } 194 195 196 GLint FogEffect::stringToFogMode(const std::string& mode) { 197 if(mode == "GL_LINEAR") 198 return GL_LINEAR; 199 else if(mode == "GL_EXP") 200 return GL_EXP; 201 else if(mode == "GL_EXP2" ) 202 return GL_EXP2; 203 else 204 return -1; 205 } 206 207 234 } 235 -
trunk/src/lib/graphics/effects/fog_effect.h
r8495 r8793 1 1 /** 2 * @file fog_effect.h 2 * @file fog_effect.h 3 * Generates simple openGL fog 3 4 */ 4 5 … … 6 7 #define _FOG_EFFECT 7 8 8 9 9 #include "weather_effect.h" 10 10 #include "glincl.h" 11 11 #include "vector.h" 12 12 13 class FogEffect : public WeatherEffect { 13 class FogEffect : public WeatherEffect 14 { 14 15 public: 15 16 16 FogEffect(const TiXmlElement* root = NULL); 17 virtual ~FogEffect(); 17 18 18 19 virtual void loadParams(const TiXmlElement* root); 19 20 20 21 virtual void init(); 21 22 22 23 23 virtual void activate(); 24 virtual void deactivate(); 24 25 25 void activateFog() { 26 this->activate(); 27 } 28 void deactivateFog() { 29 this->deactivate(); 30 } 26 void activateFog() 27 { 28 this->activate(); 29 } 31 30 32 virtual void draw() const; 33 virtual void tick(float dt); 31 void deactivateFog() 32 { 33 this->deactivate(); 34 } 34 35 35 inline void setFogMode(const std::string& mode) { 36 this->fogMode = this->stringToFogMode(mode); 37 } 38 inline void setFogDensity(float density) { 39 this->fogDensity = density; 40 } 41 inline void setFogRange(float start, float end) { 42 this->fogStart = start; 43 this->fogEnd = end; 44 } 45 inline void setFogColor(float r, float g, float b) { 46 this->colorVector = Vector(r, g, b); 47 } 48 inline void setFogFadeIn(float fadein) { 49 this->fogFadeInDuration = fadein; 50 } 51 inline void setFogFadeOut(float fadeout) { 52 this->fogFadeOutDuration = fadeout; 53 } 36 virtual void draw() const; 37 virtual void tick(float dt); 54 38 55 inline void setFogOption(const std::string& option) {56 if (option == "activate")57 this->fogActivate = true;58 39 inline void setFogMode(const std::string& mode) 40 { 41 this->fogMode = this->stringToFogMode(mode); 42 } 59 43 60 void fadeInFog(); 61 void fadeOutFog(); 44 inline void setFogDensity(float density) 45 { 46 this->fogDensity = density; 47 } 48 49 inline void setFogRange(float start, float end) 50 { 51 this->fogStart = start; 52 this->fogEnd = end; 53 } 54 55 inline void setFogColor(float r, float g, float b) 56 { 57 this->colorVector = Vector(r, g, b); 58 } 59 60 inline void setFogFadeIn(float fadein) 61 { 62 this->fogFadeInDuration = fadein; 63 } 64 65 inline void setFogFadeOut(float fadeout) 66 { 67 this->fogFadeOutDuration = fadeout; 68 } 69 70 inline void setFogOption(const std::string& option) 71 { 72 if (option == "activate") 73 this->fogActivate = true; 74 } 75 76 void fadeInFog(); 77 void fadeOutFog(); 62 78 63 79 64 80 private: 65 GLint stringToFogMode(const std::string& mode); 81 inline GLint stringToFogMode(const std::string& mode) 82 { 83 if(mode == "GL_LINEAR") 84 return GL_LINEAR; 85 else if(mode == "GL_EXP") 86 return GL_EXP; 87 else if(mode == "GL_EXP2" ) 88 return GL_EXP2; 89 else 90 return -1; 91 } 66 92 67 93 bool fogActivate; 68 94 69 70 95 bool fogFadeInActivate; 96 bool fogFadeOutActivate; 71 97 72 73 98 GLfloat fogFadeInDuration; 99 GLfloat fogFadeOutDuration; 74 100 75 float localTimer; 101 GLint fogMode; 102 GLfloat fogDensity; 103 GLfloat fogFadeDensity; 76 104 77 GLint fogMode;78 GLfloat fogDensity;79 GLfloat fogFadeDensity;105 GLfloat fogStart; 106 GLfloat fogEnd; 107 GLfloat fogFadeEnd; 80 108 81 GLfloat fogStart; 82 GLfloat fogEnd; 83 Vector colorVector; 109 Vector colorVector; 110 float localTimer; 84 111 }; 85 112 86 87 113 #endif /* _FOG_EFFECT */ -
trunk/src/lib/graphics/effects/lightening_effect.cc
r8495 r8793 16 16 17 17 #include "state.h" 18 18 19 #include "util/loading/load_param.h" 19 20 #include "util/loading/factory.h" 21 #include "util/loading/resource_manager.h" 22 20 23 #include "effects/billboard.h" 21 24 … … 33 36 CREATE_FACTORY(LighteningEffect, CL_LIGHTENING_EFFECT); 34 37 35 // TODO: FIx Lightening with Fog enabled36 37 38 LighteningEffect::LighteningEffect(const TiXmlElement* root) 38 39 { 39 40 41 42 43 44 45 46 47 40 this->setClassID(CL_LIGHTENING_EFFECT, "LighteningEffect"); 41 42 this->init(); 43 44 if (root != NULL) 45 this->loadParams(root); 46 47 if(this->lighteningActivate) 48 this->activate(); 48 49 } 49 50 50 51 LighteningEffect::~LighteningEffect() 51 52 { 52 53 this->deactivate(); 53 54 } 54 55 55 56 void LighteningEffect::loadParams(const TiXmlElement* root) 56 57 { 57 58 59 60 61 62 63 64 65 66 67 68 69 70 58 WeatherEffect::loadParams(root); 59 60 LoadParam(root, "coord", this, LighteningEffect, coord); 61 LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency); 62 LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime); 63 LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime); 64 LoadParam(root, "size", this, LighteningEffect, setFlashSize); 65 LoadParam(root, "seed", this, LighteningEffect, setFlashSeed); 66 67 LOAD_PARAM_START_CYCLE(root, element); 68 { 69 LoadParam_CYCLE(element, "option", this, LighteningEffect, setLighteningOption); 70 } 71 LOAD_PARAM_END_CYCLE(element); 71 72 } 72 73 … … 74 75 void LighteningEffect::init() 75 76 { 76 //default values 77 this->lighteningActivate = false; 78 79 this->time = 0.0; 80 this->flashFrequency = 4.0f; 81 this->mainFrequency = 4.0f; 82 this->flashConstTime = 0.1f; 83 this->flashRisingTime = 0.03f; 84 85 this->width = 700.0f; 86 this->height = 250.0f; 87 this->seedWidth = 50.0f; 88 this->seedHeight = 50.0f; 89 this->bNewCoordinate = false; 77 //default values 78 this->lighteningActivate = false; 79 80 this->flashFrequency = 4.0f; 81 this->flashFrequencyBase = 4.0f; 82 this->flashFrequencySeed = 2.0f; 83 84 this->flashHoldTime = 0.1f; 85 this->flashRisingTime = 0.03f; 86 87 this->seedX = 500.f; 88 this->seedZ = 1000.0f; 89 90 this->width = 700.0f; 91 this->height = 250.0f; 92 this->seedWidth = 50.0f; 93 this->seedHeight = 50.0f; 94 90 95 this->lighteningMove = false; 91 96 92 this->seedX = 500.f; 93 this->seedZ = 1000.0f; 94 this->seedTime = 2.0f; 95 96 this->mainPosX = 3000; 97 this->mainPosX = 1200; 97 98 this->mainPosY = 900; 98 99 this->mainPosZ = 0; 99 100 100 // initialize lightening textures 101 this->billboard[0] = new Billboard(NULL); 102 this->billboard[0]->setTexture("maps/lightning_bolt1.png"); 103 this->billboard[0]->setSize(this->width, this->height); 104 this->billboard[0]->setVisibiliy(false); 105 106 this->billboard[1] = new Billboard(NULL); 107 this->billboard[1]->setTexture("maps/lightning_bolt2.png"); 108 this->billboard[1]->setSize(this->width, this->height); 109 this->billboard[1]->setVisibiliy(false); 110 111 this->billboard[2] = new Billboard(NULL); 112 this->billboard[2]->setTexture("maps/lightning_bolt3.png"); 113 this->billboard[2]->setSize(this->width, this->height); 114 this->billboard[2]->setVisibiliy(false); 115 116 this->billboard[3] = new Billboard(NULL); 117 this->billboard[3]->setTexture("maps/lightning_bolt4.png"); 118 this->billboard[3]->setSize(this->width, this->height); 119 this->billboard[3]->setVisibiliy(false); 120 121 if (this->lighteningMove) { 122 this->cameraCoor = State::getCameraNode()->getAbsCoor(); 123 this->billboard[0]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0); 124 this->billboard[1]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0); 125 this->billboard[2]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0); 126 this->billboard[3]->setAbsCoor(this->cameraCoor.x+3000,900,this->cameraCoor.z+0); 127 } else { 128 this->billboard[0]->setAbsCoor(3000,900,0); 129 this->billboard[1]->setAbsCoor(3000,900,0); 130 this->billboard[2]->setAbsCoor(3000,900,0); 131 this->billboard[3]->setAbsCoor(3000,900,0); 132 } 133 134 this->flashLight = new Light(); 135 this->flashLight->setDiffuseColor(0,0,0); 136 this->flashLight->setSpecularColor(0,0,0); 137 138 /* 139 this->soundSource = NULL; 140 this->thunderBuffer = NULL; 141 142 this->soundSource.setSourceNode(this); 143 144 //load sound 145 if (this->thunderBuffer != NULL) 146 ResourceManager::getInstance()->unload(this->thunderBuffer); 147 this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/ 101 this->time = 0.0; 102 103 // initialize lightening textures 104 this->billboard[0] = new Billboard(NULL); 105 this->billboard[0]->setTexture("maps/lightning_bolt1.png"); 106 this->billboard[0]->setSize(this->width, this->height); 107 this->billboard[0]->setVisibiliy(false); 108 109 this->billboard[1] = new Billboard(NULL); 110 this->billboard[1]->setTexture("maps/lightning_bolt2.png"); 111 this->billboard[1]->setSize(this->width, this->height); 112 this->billboard[1]->setVisibiliy(false); 113 114 this->billboard[2] = new Billboard(NULL); 115 this->billboard[2]->setTexture("maps/lightning_bolt3.png"); 116 this->billboard[2]->setSize(this->width, this->height); 117 this->billboard[2]->setVisibiliy(false); 118 119 this->billboard[3] = new Billboard(NULL); 120 this->billboard[3]->setTexture("maps/lightning_bolt4.png"); 121 this->billboard[3]->setSize(this->width, this->height); 122 this->billboard[3]->setVisibiliy(false); 123 124 if (this->lighteningMove) 125 { 126 this->cameraCoor = State::getCameraNode()->getAbsCoor(); 127 this->billboard[0]->setAbsCoor(this->cameraCoor.x+1200,900,this->cameraCoor.z+0); 128 this->billboard[1]->setAbsCoor(this->cameraCoor.x+1200,900,this->cameraCoor.z+0); 129 this->billboard[2]->setAbsCoor(this->cameraCoor.x+1200,900,this->cameraCoor.z+0); 130 this->billboard[3]->setAbsCoor(this->cameraCoor.x+1200,900,this->cameraCoor.z+0); 131 } 132 else 133 { 134 this->billboard[0]->setAbsCoor(1200,900,0); 135 this->billboard[1]->setAbsCoor(1200,900,0); 136 this->billboard[2]->setAbsCoor(1200,900,0); 137 this->billboard[3]->setAbsCoor(1200,900,0); 138 } 139 140 this->flashLight = new Light(); 141 this->flashLight->setDiffuseColor(0,0,0); 142 this->flashLight->setSpecularColor(0,0,0); 143 144 //load sound 145 if (this->thunderBuffer != NULL) 146 ResourceManager::getInstance()->unload(this->thunderBuffer); 147 this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/thunder.wav", WAV); 148 148 149 149 } … … 151 151 void LighteningEffect::coord(float x, float y, float z) 152 152 { 153 if (this->lighteningMove) { 154 this->cameraCoor = State::getCameraNode()->getAbsCoor(); 155 this->billboard[0]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 156 this->billboard[1]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 157 this->billboard[2]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 158 this->billboard[3]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 159 } else { 160 this->billboard[0]->setAbsCoor(x, y, z); 161 this->billboard[1]->setAbsCoor(x, y, z); 162 this->billboard[2]->setAbsCoor(x, y, z); 163 this->billboard[3]->setAbsCoor(x, y, z); 164 } 165 166 this->mainPosX = x; 167 this->mainPosY = y; 168 this->mainPosZ = z; 153 if (this->lighteningMove) 154 { 155 this->cameraCoor = State::getCameraNode()->getAbsCoor(); 156 this->billboard[0]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 157 this->billboard[1]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 158 this->billboard[2]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 159 this->billboard[3]->setAbsCoor(this->cameraCoor.x+x, y, this->cameraCoor.z+z); 160 } 161 else 162 { 163 this->billboard[0]->setAbsCoor(x, y, z); 164 this->billboard[1]->setAbsCoor(x, y, z); 165 this->billboard[2]->setAbsCoor(x, y, z); 166 this->billboard[3]->setAbsCoor(x, y, z); 167 } 168 169 this->mainPosX = x; 170 this->mainPosY = y; 171 this->mainPosZ = z; 169 172 } 170 173 … … 172 175 void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight) 173 176 { 174 175 176 177 178 179 180 181 182 177 this->width = width; 178 this->height = height; 179 this->seedWidth = seedWidth; 180 this->seedHeight = seedHeight; 181 182 this->billboard[0]->setSize(this->width, this->height); 183 this->billboard[1]->setSize(this->width, this->height); 184 this->billboard[2]->setSize(this->width, this->height); 185 this->billboard[3]->setSize(this->width, this->height); 183 186 } 184 187 … … 186 189 void LighteningEffect::activate() 187 190 { 188 189 190 191 191 PRINTF(0)( "Activating LighteningEffect\n" ); 192 this->lighteningActivate = true; 193 194 this->time = 0; 192 195 } 193 196 … … 195 198 void LighteningEffect::deactivate() 196 199 { 197 198 199 200 201 202 203 200 PRINTF(0)("Deactivating LighteningEffect\n"); 201 this->lighteningActivate = false; 202 203 this->billboard[0]->setVisibiliy(false); 204 this->billboard[1]->setVisibiliy(false); 205 this->billboard[2]->setVisibiliy(false); 206 this->billboard[3]->setVisibiliy(false); 204 207 } 205 208 206 209 void LighteningEffect::tick (float dt) 207 210 { 208 if(!lighteningActivate) 209 return; 210 211 this->time += dt; 212 213 // TODO: Make random flashing with short light dingsda:) 214 215 if( this->time > this->flashFrequency) { 216 217 this->billboard[0]->setVisibiliy(true); 218 this->time = 0.0f; 219 220 this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z); 221 222 // flash environmental lightening 223 this->flashLight->setDiffuseColor(1,1,1); 224 this->flashLight->setSpecularColor(1,1,1); 225 226 //this->soundSource.play(this->thunderBuffer); 227 228 } else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime) { 229 230 this->billboard[3]->setVisibiliy(false); 231 this->time = 0.0f; 232 this->flashLight->setDiffuseColor(0,0,0); 233 this->flashLight->setSpecularColor(0,0,0); 234 this->bNewCoordinate = true; 235 236 } 237 238 if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime) { 239 240 this->billboard[2]->setVisibiliy(false); 241 this->billboard[3]->setVisibiliy(true); 242 // this->flashLight->setDiffuseColor(1,1,1); 243 // this->flashLight->setSpecularColor(1,1,1); 244 245 } else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 ) { 246 247 this->billboard[1]->setVisibiliy(false); 248 this->billboard[2]->setVisibiliy(true); 249 //this->flashLight->setDiffuseColor(0,0,0); 250 //this->flashLight->setSpecularColor(0,0,0); 251 252 } else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 ) { 253 254 this->billboard[0]->setVisibiliy(false); 255 this->billboard[1]->setVisibiliy(true); 256 //this->flashLight->setDiffuseColor(1,1,1); 257 //this->flashLight->setSpecularColor(1,1,1); 258 259 } 260 261 if( this->bNewCoordinate) { 262 float posX, posZ; 263 264 if(this->lighteningMove) { 265 266 this->cameraCoor = State::getCameraNode()->getAbsCoor(); 267 posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX + this->cameraCoor.x; 268 posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX + this->cameraCoor.z; 269 270 } else { 271 272 posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX; 273 posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX; 274 275 } 276 277 this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ); 278 this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ); 279 this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ); 280 this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ); 281 282 this->flashFrequency = this->mainFrequency + this->seedTime * (float)rand()/(float)RAND_MAX; 283 284 float w = this->width + this->seedWidth * (float)rand()/(float)RAND_MAX; 285 float h = this->height + this->seedHeight * (float)rand()/(float)RAND_MAX; 286 287 this->billboard[0]->setSize(w, h); 288 this->billboard[1]->setSize(w, h); 289 this->billboard[2]->setSize(w, h); 290 this->billboard[3]->setSize(w, h); 291 292 this->bNewCoordinate = false; 293 } 294 } 295 296 void LighteningEffect::draw() const 297 { 298 } 211 if(!lighteningActivate) 212 return; 213 214 this->time += dt; 215 216 float x; 217 x = (float)rand()/(float)RAND_MAX; 218 219 // TODO: Make random flashing with short light dingsda:) 220 221 if( this->time > this->flashFrequency) 222 { 223 // Reset timer 224 this->time = 0.0f; 225 226 // Move billboard to start position 227 this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z); 228 229 // Start a flash & lightening cycle 230 this->billboard[0]->setVisibiliy(true); 231 232 // Lighten up environment 233 this->flashLight->setDiffuseColor(1,1,1); 234 this->flashLight->setSpecularColor(1,1,1); 235 236 // Play thunder sound 237 this->soundSource.play(this->thunderBuffer); 238 } 239 240 if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 ) 241 { 242 this->billboard[0]->setVisibiliy(false); 243 this->billboard[1]->setVisibiliy(true); 244 } 245 else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 ) 246 { 247 this->billboard[1]->setVisibiliy(false); 248 this->billboard[2]->setVisibiliy(true); 249 250 } 251 else if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime) 252 { 253 this->billboard[2]->setVisibiliy(false); 254 this->billboard[3]->setVisibiliy(true); 255 } 256 257 if( this->billboard[3]->isVisible() && this->time > this->flashHoldTime) 258 { 259 this->billboard[3]->setVisibiliy(false); 260 this->time = 0.0f; 261 this->flashLight->setDiffuseColor(0,0,0); 262 this->flashLight->setSpecularColor(0,0,0); 263 264 this->newCoordinates(); 265 } 266 } 267 268 void LighteningEffect::newCoordinates() { 269 270 float posX, posZ; 271 272 if(this->lighteningMove) 273 { 274 275 this->cameraCoor = State::getCameraNode()->getAbsCoor(); 276 posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX + this->cameraCoor.x; 277 posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX + this->cameraCoor.z; 278 279 } 280 else 281 { 282 283 posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX; 284 posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX; 285 286 } 287 288 this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ); 289 this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ); 290 this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ); 291 this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ); 292 293 this->flashFrequency = this->flashFrequencyBase + this->flashFrequencySeed * (float)rand()/(float)RAND_MAX; 294 295 float w = this->width + this->seedWidth * (float)rand()/(float)RAND_MAX; 296 float h = this->height + this->seedHeight * (float)rand()/(float)RAND_MAX; 297 298 this->billboard[0]->setSize(w, h); 299 this->billboard[1]->setSize(w, h); 300 this->billboard[2]->setSize(w, h); 301 this->billboard[3]->setSize(w, h); 302 } -
trunk/src/lib/graphics/effects/lightening_effect.h
r8495 r8793 33 33 inline void deactivateLightening() { this->deactivate(); } 34 34 35 virtual void draw() const;36 35 virtual void tick(float dt); 37 36 38 37 void coord(float x, float y, float z); 39 38 void setFlashSize(float width, float height, float seedWidth, float seedHeight); 40 39 41 40 inline void setLighteningOption(const std::string& option) { 42 41 if (option == "activate") this->lighteningActivate = true; … … 44 43 } 45 44 46 inline void setFlashFrequency(float mainFrequency, float seedTime) {47 this-> mainFrequency = mainFrequency;48 this->flashFrequency = mainFrequency;49 this-> seedTime= seedTime;45 inline void setFlashFrequency(float baseFrequency, float seedTime) { 46 this->flashFrequencyBase = baseFrequency; 47 this->flashFrequency = baseFrequency; 48 this->flashFrequencySeed = seedTime; 50 49 } 51 52 inline void setFlashConstTime(float flashConstTime) { this->flashConstTime = flashConstTime; }50 51 inline void setFlashConstTime(float holdTime) { this->flashHoldTime = holdTime; } 53 52 54 53 inline void setFlashRisingTime(float flashRisingTime) { 55 if(flashRisingTime > this->flash ConstTime)56 this->flashRisingTime = this->flash ConstTime/2;54 if(flashRisingTime > this->flashHoldTime) 55 this->flashRisingTime = this->flashHoldTime * 0.5; 57 56 else 58 57 this->flashRisingTime = flashRisingTime; 59 58 } 60 59 61 60 inline void setFlashSeed(float seedX, float seedZ) { 62 61 this->seedX = seedX; 63 62 this->seedZ = seedZ; 64 63 } 65 64 66 65 67 66 private: … … 69 68 bool lighteningActivate; 70 69 bool lighteningMove; 71 70 72 71 float flashFrequency; 73 float mainFrequency;74 float flash ConstTime;72 float flashFrequencyBase; 73 float flashHoldTime; 75 74 float flashRisingTime; 76 75 77 76 float time; 78 79 bool bNewCoordinate; 77 80 78 float width; 81 79 float height; 82 80 float seedWidth; 83 81 float seedHeight; 84 82 85 83 float seedX; 86 84 float seedZ; 87 float seedTime;88 85 float flashFrequencySeed; 86 89 87 float mainPosX; 90 88 float mainPosY; 91 89 float mainPosZ; 92 90 91 void newCoordinates(); 92 93 93 Vector cameraCoor; 94 94 95 95 Light* flashLight; 96 97 //OrxSound::SoundSource soundSource;98 //OrxSound::SoundBuffer* thunderBuffer;96 97 OrxSound::SoundSource soundSource; 98 OrxSound::SoundBuffer* thunderBuffer; 99 99 100 100 }; -
trunk/src/lib/graphics/effects/rain_effect.cc
r8495 r8793 1 1 /* 2 orxonox - the future of 3D-vertical-scrollers3 4 Copyright (C) 2004 orx5 6 This program is free software; you can redistribute it and/or modify7 it under the terms of the GNU General Public License as published by8 the Free Software Foundation; either version 2, or (at your option)9 any later version.10 2 orxonox - the future of 3D-vertical-scrollers 3 4 Copyright (C) 2004 orx 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 11 ### File Specific: 12 main-programmer: hdavid, amaechler12 main-programmer: hdavid, amaechler 13 13 */ 14 14 … … 26 26 #include "shell_command.h" 27 27 #include "light.h" 28 #include "cloud_effect.h" 28 29 29 30 #include "parser/tinyxml/tinyxml.h" 30 31 32 // Define shell commands 31 33 SHELL_COMMAND(activate, RainEffect, activateRain); 32 34 SHELL_COMMAND(deactivate, RainEffect, deactivateRain); … … 38 40 CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT); 39 41 40 /* TODO: 41 - test multiple rain emitters 42 - Think about what happens with building poss. to hang movewithcam off 43 - Possible to activate lightening 44 - turn off visibility when in a building 45 - variable emitter size depending on playable 42 /** 43 * @brief standard constructor 44 */ 45 RainEffect::RainEffect(const TiXmlElement* root) 46 { 47 this->setClassID(CL_RAIN_EFFECT, "RainEffect"); 48 49 this->init(); 50 51 if (root != NULL) 52 this->loadParams(root); 53 54 //load rain sound 55 if (this->rainBuffer != NULL) 56 ResourceManager::getInstance()->unload(this->rainBuffer); 57 this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV); 58 59 //load wind sound 60 if (this->rainWindForce != 0) 61 { 62 if (this->windBuffer != NULL) 63 ResourceManager::getInstance()->unload(this->windBuffer); 64 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 65 } 66 67 if(rainActivate) 68 { 69 this->activate(); 70 RainEffect::rainParticles->precache((int)this->rainLife * 2); 71 } 72 } 73 74 /** 75 * @brief standard deconstructor 76 */ 77 RainEffect::~RainEffect() 78 { 79 this->deactivate(); 80 81 if (this->rainBuffer != NULL) 82 ResourceManager::getInstance()->unload(this->rainBuffer); 83 84 if (this->windBuffer != NULL) 85 ResourceManager::getInstance()->unload(this->windBuffer); 86 } 87 88 /** 89 * @brief initalizes the rain effect with default values 90 */ 91 void RainEffect::init() 92 { 93 //Default values 94 this->rainActivate = false; 95 this->rainMove = false; 96 this->rainCoord = Vector(500, 500, 500); 97 this->rainSize = Vector2D(1000, 1000); 98 this->rainRate = 4000; 99 this->rainVelocity = -300; 100 this->rainLife = 4; 101 this->rainWindForce = 0; 102 this->rainFadeInDuration = 0; 103 this->rainFadeOutDuration = 0; 104 105 this->cloudColor = Vector(0.8f, 0.8f, 0.8f); 106 this->skyColor = Vector(0.0f, 0.0f, 0.0f); 107 108 this->rainMaxParticles = this->rainRate * this->rainLife; 109 this->localTimer = 0; 110 this->soundRainVolume = 0.3f; 111 this->emitter = new PlaneEmitter(this->rainSize); 112 113 lightMan = LightManager::getInstance(); 114 this->rainAmbient = lightMan->getAmbientColor(); 115 } 116 117 /** 118 * @brief loads the rain effect parameters. 119 * @param root: the XML-Element to load the data from 120 */ 121 void RainEffect::loadParams(const TiXmlElement* root) 122 { 123 WeatherEffect::loadParams(root); 124 125 LoadParam(root, "coord", this, RainEffect, setRainCoord); 126 LoadParam(root, "size", this, RainEffect, setRainSize); 127 LoadParam(root, "rate", this, RainEffect, setRainRate); 128 LoadParam(root, "velocity", this, RainEffect, setRainVelocity); 129 LoadParam(root, "life", this, RainEffect, setRainLife); 130 LoadParam(root, "wind", this, RainEffect, setRainWind); 131 LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn); 132 LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut); 133 LoadParam(root, "cloudcolor", this, RainEffect, setCloudColor); 134 LoadParam(root, "skycolor", this, RainEffect, setSkyColor); 135 136 LOAD_PARAM_START_CYCLE(root, element); 137 { 138 LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption); 139 } 140 LOAD_PARAM_END_CYCLE(element); 141 } 142 143 SparkParticles* RainEffect::rainParticles = NULL; 144 145 /** 146 * @brief activates the rain effect 147 */ 148 void RainEffect::activate() 149 { 150 PRINTF(0)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" ); 151 152 this->rainActivate = true; 153 154 if (unlikely(RainEffect::rainParticles == NULL)) 155 { 156 RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles); 157 RainEffect::rainParticles->setName("RainParticles"); 158 RainEffect::rainParticles->setLifeSpan(this->rainLife, 2); 159 RainEffect::rainParticles->setRadius(0, 0.03); 160 RainEffect::rainParticles->setRadius(0.2, 0.02); 161 RainEffect::rainParticles->setRadius(1, 0.01); 162 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 163 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 164 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey 165 } 166 167 this->emitter->setSystem(RainEffect::rainParticles); 168 169 this->emitter->setRelCoor(this->rainCoord); 170 171 this->emitter->setEmissionRate(this->rainRate); 172 this->emitter->setEmissionVelocity(this->rainVelocity); 173 174 this->emitter->setSpread(this->rainWindForce / 50, 0.2); 175 176 // plays the rain sound and loops it 177 this->soundSource.play(this->rainBuffer, this->soundRainVolume, true); 178 179 // if there is wind, play the wind sound 180 if (this->rainWindForce != 0) 181 this->soundSource.play(this->windBuffer, 0.1f * this->rainWindForce, true); 182 183 if (this->rainFadeInDuration == 0) 184 lightMan->setAmbientColor(.1,.1,.1); 185 186 // Change the cloudcolor,skycolor 187 this->oldCloudColor = CloudEffect::cloudColor; 188 this->oldSkyColor = CloudEffect::skyColor; 189 CloudEffect::changeCloudColor(this->cloudColor); 190 CloudEffect::changeSkyColor(this->skyColor); 191 } 192 193 /** 194 * @brief deactivates the rain effect 195 */ 196 void RainEffect::deactivate() 197 { 198 PRINTF(0)("Deactivating RainEffect\n"); 199 200 this->rainActivate = false; 201 this->emitter->setSystem(NULL); 202 203 // Stop Sound 204 this->soundSource.stop(); 205 206 // Restore Light Ambient 207 lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient); 208 209 CloudEffect::changeCloudColor(this->oldCloudColor); 210 CloudEffect::changeSkyColor(this->oldSkyColor); 211 } 212 213 /** 214 * @brief ticks the rain effect 215 * @param dt: tick float 216 */ 217 void RainEffect::tick (float dt) 218 { 219 if (!this->rainActivate) 220 return; 221 222 if (this->rainMove) 223 { 224 this->rainCoord = State::getCameraNode()->getAbsCoor(); 225 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z); 226 } 227 228 if (this->rainFadeInDuration != 0 && this->localTimer < this->rainFadeInDuration) 229 { 230 this->localTimer += dt; 231 float progress = this->localTimer / this->rainFadeInDuration; 232 233 // Dim Light 234 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 235 236 // use alpha in color to fade in 237 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 238 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 239 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 240 241 // increase radius for more "heavy" rain 242 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 243 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 244 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 245 246 // increase sound volume 247 if (!this->soundSource.isPlaying()) 248 this->soundSource.play(this->rainBuffer, this->soundRainVolume, true); 249 250 this->soundSource.gain(this->rainBuffer, this->soundRainVolume * progress); 251 } 252 else if ( this->rainFadeOutDuration != 0 ) 253 { 254 if ( this->localTimer < this->rainFadeOutDuration ) 255 { 256 this->localTimer += dt; 257 float progress = 1 - (this->localTimer / this->rainFadeOutDuration); 258 259 // Fade In Light 260 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 261 262 // use alpha in color to fade out 263 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 264 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 265 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 266 267 // decrease radius 268 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 269 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 270 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 271 272 // decrease sound volume 273 if (!this->soundSource.isPlaying()) 274 this->soundSource.play(this->rainBuffer, this->soundRainVolume, true); 275 276 this->soundSource.gain(this->rainBuffer, this->soundRainVolume * progress); 277 } 278 else 279 this->deactivate(); 280 } 281 } 282 283 /** 284 * @brief starts raining slowly 46 285 */ 47 48 RainEffect::RainEffect(const TiXmlElement* root) { 49 this->setClassID(CL_RAIN_EFFECT, "RainEffect"); 50 51 this->init(); 52 53 if (root != NULL) 54 this->loadParams(root); 55 56 //load rain sound 57 if (this->rainBuffer != NULL) 58 ResourceManager::getInstance()->unload(this->rainBuffer); 59 this->rainBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/rain.wav", WAV); 60 61 //load wind sound 62 if (this->rainWindForce != 0) { 63 if (this->windBuffer != NULL) 64 ResourceManager::getInstance()->unload(this->windBuffer); 65 this->windBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/wind.wav", WAV); 66 } 67 68 if(rainActivate) { 69 this->activate(); 70 RainEffect::rainParticles->precache((int)this->rainLife * 5); // TODO: Figure out the correct value 71 } 72 } 73 74 RainEffect::~RainEffect() { 286 void RainEffect::startRaining() 287 { 288 289 if (this->rainActivate) 75 290 this->deactivate(); 76 291 77 if (this->rainBuffer != NULL) 78 ResourceManager::getInstance()->unload(this->rainBuffer); 79 80 if (this->windBuffer != NULL) 81 ResourceManager::getInstance()->unload(this->windBuffer); 82 } 83 84 void RainEffect::loadParams(const TiXmlElement* root) { 85 WeatherEffect::loadParams(root); 86 87 LoadParam(root, "coord", this, RainEffect, setRainCoord); 88 LoadParam(root, "size", this, RainEffect, setRainSize); 89 LoadParam(root, "rate", this, RainEffect, setRainRate); 90 LoadParam(root, "velocity", this, RainEffect, setRainVelocity); 91 LoadParam(root, "life", this, RainEffect, setRainLife); 92 LoadParam(root, "wind", this, RainEffect, setRainWind); 93 LoadParam(root, "fadeinduration", this, RainEffect, setRainFadeIn); 94 LoadParam(root, "fadeoutduration", this, RainEffect, setRainFadeOut); 95 96 LOAD_PARAM_START_CYCLE(root, element); 97 { 98 LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption); 99 } 100 LOAD_PARAM_END_CYCLE(element); 101 102 } 103 104 105 void RainEffect::init() { 106 //Default values 107 this->rainActivate = false; 108 this->rainMove = false; 109 this->rainCoord = Vector(500, 500, 500); 110 this->rainSize = Vector2D(1000, 1000); 111 this->rainRate = 4000; 112 this->rainVelocity = -300; 113 this->rainLife = 4; 114 this->rainMaxParticles = this->rainRate * this->rainLife; 115 this->rainWindForce = 0; 116 this->rainFadeInDuration = 0; 117 this->rainFadeOutDuration = 0; 118 this->localTimer = 0; 119 this->soundRainVolume = 0.8f; 120 121 this->emitter = new PlaneEmitter(this->rainSize); 122 123 lightMan = LightManager::getInstance(); 124 this->rainAmbient = lightMan->getAmbientColor(); 125 } 126 127 128 SparkParticles* RainEffect::rainParticles = NULL; 129 130 void RainEffect::activate() { 131 PRINTF(0)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" ); 132 133 this->rainActivate = true; 134 135 if (unlikely(RainEffect::rainParticles == NULL)) { 136 RainEffect::rainParticles = new SparkParticles((int) this->rainMaxParticles); 137 RainEffect::rainParticles->setName("RainParticles"); 138 RainEffect::rainParticles->setLifeSpan(this->rainLife, 2); 139 RainEffect::rainParticles->setRadius(0, 0.03); 140 RainEffect::rainParticles->setRadius(0.2, 0.02); 141 RainEffect::rainParticles->setRadius(1, 0.01); 142 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 143 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 144 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey 145 } 146 147 this->emitter->setSystem(RainEffect::rainParticles); 148 149 this->emitter->setRelCoor(this->rainCoord); 150 151 this->emitter->setEmissionRate(this->rainRate); 152 this->emitter->setEmissionVelocity(this->rainVelocity); 153 154 this->emitter->setSpread(this->rainWindForce / 50, 0.2); 155 156 this->soundSource.play(this->rainBuffer, this->soundRainVolume, true); 157 158 if (this->rainWindForce != 0) 159 this->soundSource.play(this->windBuffer, 0.1f * this->rainWindForce, true); 160 161 if (this->rainFadeInDuration == 0) 162 lightMan->setAmbientColor(.1,.1,.1); 163 164 } 165 166 167 void RainEffect::deactivate() { 168 PRINTF(0)("Deactivating RainEffect\n"); 169 170 this->rainActivate = false; 171 this->emitter->setSystem(NULL); 172 173 // Stop Sound 174 this->soundSource.stop(); 175 176 // Restore Light Ambient 177 lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient); 178 179 } 180 181 void RainEffect::tick (float dt) { 182 if (!this->rainActivate) 183 return; 184 185 if (this->rainMove) { 186 this->rainCoord = State::getCameraNode()->getAbsCoor(); 187 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z); 188 } 189 190 if (this->rainFadeInDuration != 0 && this->localTimer < this->rainFadeInDuration) { 191 this->localTimer += dt; 192 float progress = this->localTimer / this->rainFadeInDuration; 193 194 // Dim Light 195 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 196 197 // use alpha in color to fade in 198 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 199 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 200 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 201 202 // increase radius for more "heavy" rain 203 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 204 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 205 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 206 207 // increase sound volume 208 // this->soundSource.fadein(this->rainBuffer, 10); 209 } else if ( this->rainFadeOutDuration != 0 ) { 210 if ( this->localTimer < this->rainFadeOutDuration ) { 211 this->localTimer += dt; 212 float progress = 1 - (this->localTimer / this->rainFadeOutDuration); 213 214 // Fade In Light 215 lightMan->setAmbientColor(1 - progress * 0.9, 1 - progress * 0.9, 1 - progress * 0.9); 216 217 // use alpha in color to fade out 218 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 219 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 220 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 221 222 // decrease radius 223 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 224 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 225 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 226 227 // decrease sound volume 228 // this->soundSource.fadeout(this->rainBuffer, 10); 229 } else 230 this->deactivate(); 231 } 232 233 } 234 235 void RainEffect::startRaining() { 236 237 if (this->rainActivate) 238 this->deactivate(); 239 240 if (!this->rainFadeInDuration > 0) 241 this->rainFadeInDuration = 20; 242 243 this->localTimer = 0; 244 292 if (!this->rainFadeInDuration > 0) 293 this->rainFadeInDuration = 20; 294 295 this->localTimer = 0; 296 297 this->activate(); 298 } 299 300 /** 301 * @brief stops raining slowly 302 */ 303 void RainEffect::stopRaining() 304 { 305 306 if (!this->rainActivate) 245 307 this->activate(); 246 308 247 } 248 249 void RainEffect::stopRaining() { 250 251 if (!this->rainActivate) 252 this->activate(); 253 254 if (!this->rainFadeOutDuration > 0) 255 this->rainFadeOutDuration = 20; 256 257 this->localTimer = 0; 258 259 } 309 if (!this->rainFadeOutDuration > 0) 310 this->rainFadeOutDuration = 20; 311 312 this->localTimer = 0; 313 } 314 315 /** 316 * @brief hides the rain 317 */ 318 void RainEffect::hideRain() 319 { 320 RainEffect::rainParticles->setColor(0, 0,0,0, 0); 321 RainEffect::rainParticles->setColor(0, 0,0,0, 0); 322 } -
trunk/src/lib/graphics/effects/rain_effect.h
r8495 r8793 1 1 /** 2 * @file rain_effect.h 2 * @file rain_effect.h 3 * Generates rain using the particle engine 3 4 */ 4 5 5 6 #ifndef _RAIN_EFFECT 6 7 #define _RAIN_EFFECT 8 9 #include "weather_effect.h" 7 10 8 11 #include "vector.h" … … 15 18 class PlainEmitter; 16 19 class LightManager; 17 18 #include "weather_effect.h" 20 class CloudEffect; 19 21 20 22 #include "sound_buffer.h" 21 23 #include "sound_source.h" 22 24 25 class RainEffect : public WeatherEffect 26 { 27 public: 28 RainEffect(const TiXmlElement* root = NULL); 29 virtual ~RainEffect(); 23 30 24 class RainEffect : public WeatherEffect { 25 public: 26 RainEffect(const TiXmlElement* root = NULL); 27 virtual ~RainEffect(); 31 virtual void loadParams(const TiXmlElement* root); 28 32 29 virtual void loadParams(const TiXmlElement* root);33 virtual void init(); 30 34 31 virtual void init(); 35 virtual void activate(); 36 virtual void deactivate(); 32 37 33 virtual void activate(); 34 virtual void deactivate(); 38 inline void activateRain() 39 { 40 this->activate(); 41 } 35 42 36 inline void activateRain() { 37 this->activate(); 38 } 39 inline void deactivateRain() { 40 this->deactivate(); 41 } 43 inline void deactivateRain() 44 { 45 this->deactivate(); 46 } 42 47 43 48 virtual void tick(float dt); 44 49 45 46 50 void startRaining(); 51 void stopRaining(); 47 52 48 inline void setRainCoord(float x, float y, float z) { 49 this->rainCoord = Vector(x, y, z); 50 } 51 inline void setRainSize(float x, float y) { 52 this->rainSize = Vector2D(x, y); 53 } 54 inline void setRainRate(float rate) { 55 this->rainRate = rate; 56 } 57 inline void setRainVelocity(float velocity) { 58 this->rainVelocity = -velocity; 59 } 60 inline void setRainLife(float life) { 61 this->rainLife = life; 62 } 63 inline void setRainWind(int force) { 64 this->rainWindForce = force; 65 } 53 void hideRain(); 66 54 67 inline void setRainFadeIn(float fadein) { 68 this->rainFadeInDuration = fadein; 69 } 70 inline void setRainFadeOut(float fadeout) { 71 this->rainFadeOutDuration = fadeout; 72 } 55 inline void setRainCoord(float x, float y, float z) 56 { 57 this->rainCoord = Vector(x, y, z); 58 } 59 inline void setRainSize(float x, float y) 60 { 61 this->rainSize = Vector2D(x, y); 62 } 63 inline void setRainRate(float rate) 64 { 65 this->rainRate = rate; 66 } 67 inline void setRainVelocity(float velocity) 68 { 69 this->rainVelocity = -velocity; 70 } 71 inline void setRainLife(float life) 72 { 73 this->rainLife = life; 74 } 75 inline void setRainWind(int force) 76 { 77 this->rainWindForce = force; 78 } 73 79 74 inline void setRainOption(const std::string& option) { 75 if (option == "moverain") 76 this->rainMove = true; 77 if (option == "activate") 78 this->rainActivate = true; 79 } 80 inline void setRainFadeIn(float fadein) 81 { 82 this->rainFadeInDuration = fadein; 83 } 84 inline void setRainFadeOut(float fadeout) 85 { 86 this->rainFadeOutDuration = fadeout; 87 } 88 89 inline void setCloudColor(float colorX, float colorY, float colorZ) 90 { 91 this->cloudColor = Vector(colorX, colorY, colorZ); 92 } 93 inline void setSkyColor(float colorX, float colorY, float colorZ) 94 { 95 this->skyColor = Vector(colorX, colorY, colorZ); 96 } 97 98 inline void setRainOption(const std::string& option) 99 { 100 if (option == "moverain") 101 this->rainMove = true; 102 if (option == "activate") 103 this->rainActivate = true; 104 } 80 105 81 106 82 107 private: 83 84 108 static SparkParticles* rainParticles; 109 ParticleEmitter* emitter; 85 110 86 GLfloat rainFadeInDuration; 87 GLfloat rainFadeOutDuration; 88 float localTimer; 111 float localTimer; 89 112 90 Vector rainCoord; 91 Vector2D rainSize; 92 GLfloat rainRate; 93 GLfloat rainVelocity; 94 GLfloat rainLife; 95 GLfloat rainMaxParticles; 96 int rainWindForce; 97 bool rainMove; 98 bool rainActivate; 113 GLfloat rainFadeInDuration; 114 GLfloat rainFadeOutDuration; 99 115 100 OrxSound::SoundSource soundSource; 101 OrxSound::SoundBuffer* rainBuffer; 102 OrxSound::SoundBuffer* windBuffer; 116 Vector rainCoord; 117 Vector2D rainSize; 118 GLfloat rainRate; 119 GLfloat rainVelocity; 120 GLfloat rainLife; 121 GLfloat rainMaxParticles; 122 int rainWindForce; 123 bool rainMove; 124 bool rainActivate; 103 125 104 float soundRainVolume; 126 OrxSound::SoundSource soundSource; 127 OrxSound::SoundBuffer* rainBuffer; 128 OrxSound::SoundBuffer* windBuffer; 105 129 106 LightManager* lightMan; 107 GLfloat rainAmbient; 130 float soundRainVolume; 131 132 LightManager* lightMan; 133 GLfloat rainAmbient; 134 135 Vector oldSkyColor; 136 Vector oldCloudColor; 137 Vector skyColor; 138 Vector cloudColor; 108 139 109 140 }; -
trunk/src/lib/graphics/effects/snow_effect.cc
r8495 r8793 56 56 this->activate(); 57 57 SnowEffect::snowParticles->precache((int) this->snowLife); 58 } 58 } 59 59 } 60 60 … … 143 143 if (this->snowWindForce != 0) 144 144 this->soundSource.play(this->windBuffer, 0.1f * this->snowWindForce, true); 145 145 146 146 } 147 147 -
trunk/src/lib/graphics/effects/sun_effect.cc
r7836 r8793 56 56 * initializes the graphics effect 57 57 */ 58 boolSunEffect::init()58 void SunEffect::init() 59 59 {} 60 60 -
trunk/src/lib/graphics/effects/sun_effect.h
r7810 r8793 1 1 /*! 2 2 * @file sun_effect.h 3 * 3 * 4 4 */ 5 5 … … 20 20 virtual void loadParams(const TiXmlElement* root); 21 21 22 virtual boolinit();22 virtual void init(); 23 23 24 virtual boolactivate() = 0;25 virtual booldeactivate() = 0;24 virtual void activate() = 0; 25 virtual void deactivate() = 0; 26 26 27 27 virtual void draw() const; -
trunk/src/lib/sound/sound_source.cc
r8495 r8793 164 164 165 165 /** 166 * @brief Plays back buffer on this Source with gain 167 * @param buffer the buffer to play back on this Source 166 * @brief Plays back buffer on this Source with gain 167 * @param buffer the buffer to play back on this Source 168 * @param gain the gain of the sound buffer 168 169 */ 169 170 void SoundSource::play(const SoundBuffer* buffer, float gain) … … 189 190 SoundEngine::checkError("Play Source", __LINE__); 190 191 } 191 192 192 193 /** 193 194 * @brief Plays back buffer on this Source with gain and looping possibility 194 195 * @param buffer the buffer to play back on this Source 195 */ 196 * @param gain the gain of the sound buffer 197 * @param loop if true, sound gets looped 198 */ 196 199 void SoundSource::play(const SoundBuffer* buffer, float gain, bool loop) 197 200 { … … 204 207 alSourceStop(this->sourceID); 205 208 alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 206 209 207 210 if (loop) 208 211 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 209 212 else 210 211 213 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE); 214 212 215 alSourcef (this->sourceID, AL_GAIN, gain); 213 216 … … 220 223 if (DEBUG_LEVEL >= 3) 221 224 SoundEngine::checkError("Play Source", __LINE__); 222 } 223 224 225 /** 226 * @brief Stops playback of a SoundSource 227 */ 225 } 226 227 /** 228 * @brief Changes the volume of an (active) buffer 229 * @param buffer the buffer to play back on this Source 230 * @param gain the new gain value 231 */ 232 void SoundSource::gain(const SoundBuffer* buffer, float gain) 233 { 234 // alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 235 alSourcef (this->sourceID, AL_GAIN, gain); 236 } 237 238 /** 239 * @brief Stops playback of a SoundSource 240 */ 228 241 void SoundSource::stop() 229 242 { -
trunk/src/lib/sound/sound_source.h
r8495 r8793 14 14 namespace OrxSound 15 15 { 16 class SoundBuffer; 17 //! A class that represents a SoundSource 18 class SoundSource : public BaseObject 19 { 20 public: 21 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL); 22 SoundSource(const SoundSource& source); 23 SoundSource& operator=(const SoundSource& source); 24 bool operator==(const SoundSource& source); 25 26 virtual ~SoundSource(); 27 28 // user interaction 29 void play(); 30 void play(const SoundBuffer* buffer); 31 void play(const SoundBuffer* buffer, float gain); 32 void play(const SoundBuffer* buffer, float gain, bool loop); 16 class SoundBuffer; 17 //! A class that represents a SoundSource 18 class SoundSource : public BaseObject 19 { 20 public: 21 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL); 22 SoundSource(const SoundSource& source); 23 SoundSource& operator=(const SoundSource& source); 24 bool operator==(const SoundSource& source); 33 25 34 void stop(); 35 void pause(); 36 void rewind(); 37 void fadein(const SoundBuffer* buffer, ALfloat duration); 38 39 40 // development functions 41 /** @returns The ID of this Source */ 42 inline ALuint getID() const { return this->sourceID; }; 43 /** @returns true, if the Source is Playing */ 44 inline bool isPlaying() const { return this->bPlay; }; 45 void setSourceNode(const PNode* sourceNode); 46 /** @returns the SoundBuffer of this Source */ 47 inline const SoundBuffer* getBuffer() const { return this->buffer; }; 48 /** @returns the SourceNode of this Source */ 49 inline const PNode* getNode() const { return this->sourceNode; }; 50 /** @param resident if the Source is Resident */ 51 inline void setResident(bool resident) { this->resident = resident; }; 52 /** @returns true if the alSource is Resident */ 53 inline bool isResident() const { return this->resident; }; 54 55 void setRolloffFactor(ALfloat rolloffFactor); 56 57 static void resetSource(ALuint sourceID); 58 59 private: 60 bool retrieveSource(); 61 62 private: 63 bool bPlay; //!< If the Source is Playing. 64 bool resident; //!< If the alSource should be resident (if true, the alSource will be returned on deletion). 65 ALuint sourceID; //!< The ID of the Source 66 const SoundBuffer* buffer; //!< The buffer to play in this source. 67 const PNode* sourceNode; //!< The SourceNode representing the position/velocity... of this source. 68 }; 26 virtual ~SoundSource(); 27 28 // user interaction 29 void play(); 30 void play(const SoundBuffer* buffer); 31 void play(const SoundBuffer* buffer, float gain); 32 void play(const SoundBuffer* buffer, float gain, bool loop); 33 34 void gain(const SoundBuffer* buffer, float gain); 35 36 void stop(); 37 void pause(); 38 void rewind(); 39 void fadein(const SoundBuffer* buffer, ALfloat duration); 40 41 // development functions 42 /** @returns The ID of this Source */ 43 inline ALuint getID() const { return this->sourceID; }; 44 /** @returns true, if the Source is Playing */ 45 inline bool isPlaying() const { return this->bPlay; }; 46 void setSourceNode(const PNode* sourceNode); 47 /** @returns the SoundBuffer of this Source */ 48 inline const SoundBuffer* getBuffer() const { return this->buffer; }; 49 /** @returns the SourceNode of this Source */ 50 inline const PNode* getNode() const { return this->sourceNode; }; 51 /** @param resident if the Source is Resident */ 52 inline void setResident(bool resident) { this->resident = resident; }; 53 /** @returns true if the alSource is Resident */ 54 inline bool isResident() const { return this->resident; }; 55 56 void setRolloffFactor(ALfloat rolloffFactor); 57 58 static void resetSource(ALuint sourceID); 59 60 private: 61 bool retrieveSource(); 62 63 private: 64 bool bPlay; //!< If the Source is Playing. 65 bool resident; //!< If the alSource should be resident (if true, the alSource will be returned on deletion). 66 ALuint sourceID; //!< The ID of the Source 67 const SoundBuffer* buffer; //!< The buffer to play in this source. 68 const PNode* sourceNode; //!< The SourceNode representing the position/velocity... of this source. 69 }; 69 70 } 70 71 #endif /* _SOUND_SOURCE_H */ -
trunk/src/world_entities/WorldEntities.am
r8724 r8793 9 9 world_entities/skysphere.cc \ 10 10 world_entities/skybox.cc \ 11 world_entities/skydome.cc \ 11 12 world_entities/terrain.cc \ 12 13 world_entities/satellite.cc \ … … 66 67 skysphere.h \ 67 68 skybox.h \ 69 skydome.h \ 68 70 terrain.h \ 69 71 satellite.h \ -
trunk/src/world_entities/effects/lightning_bolt.cc
r7713 r8793 64 64 if (this->thunderBuffer != NULL) 65 65 ResourceManager::getInstance()->unload(this->thunderBuffer); 66 this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/ thunder.wav", WAV);66 this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/atmosphere/thunder.wav", WAV); 67 67 } 68 68 -
trunk/src/world_entities/npcs/generic_npc.h
r8783 r8793 11 11 12 12 #include <string> 13 // 13 14 14 #include "sound_source.h" 15 16 #include "vector.h" 17 #include "qaternion.h" 18 15 19 16 20 namespace OrxSound{ class SoundSource; } … … 38 42 void playSound(int i); 39 43 44 float lookAt(WorldEntity* worldEntity); 45 40 46 float walkTo(const Vector& coordinate, const Quaternion& dir); 41 47 float walkTo(float x, float y, float z, float qu, float qx, float qy, float qz); … … 50 56 float crouchTo(float x, float y, float qu, float qx, float qy, float qz); 51 57 58 float talkTo(WorldEnity* worldEntity, int dialogNr); 59 52 60 53 61 void destroy(); … … 60 68 OrxSound::SoundBuffer* soundBuffer; 61 69 float soundVolume; 70 71 Vector destCoor; 72 Quaternion destDir; 62 73 }; 63 74
Note: See TracChangeset
for help on using the changeset viewer.