- Timestamp:
- Jun 8, 2006, 2:04:37 PM (18 years ago)
- Location:
- branches/atmospheric_engine/src/lib/graphics/effects
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc
r8175 r8242 27 27 #include "p_node.h" 28 28 #include "shader.h" 29 #include "shell_command.h" 29 30 30 31 #include "parser/tinyxml/tinyxml.h" … … 33 34 34 35 using namespace std; 36 37 SHELL_COMMAND(activate, CloudEffect, activateCloud); 38 SHELL_COMMAND(deactivate, CloudEffect, deactivateCloud); 35 39 36 40 CREATE_FACTORY(CloudEffect, CL_CLOUD_EFFECT); … … 45 49 this->loadParams(root); 46 50 47 this->activate(); 51 if(cloudActivate) 52 this->activate(); 48 53 } 49 54 … … 54 59 delete this->cloudMaterial; 55 60 56 g_sky_model.Delete();57 Shader::unload(this-> skyShader);61 cloudModel.Delete(); 62 Shader::unload(this->cloudShader); 58 63 59 64 } … … 63 68 { 64 69 PRINTF(1)("Initializing CloudEffect\n"); 70 71 // Default values 72 this->cloudActivate = false; 73 this->cloudTint[4] = ( 0.9f, 0.7f, 0.7f, 1.0f ); 74 this->cloudScroll = 1.0f; 75 this->time = 0.0f; 76 //g_cloud_texture = 0; 77 78 this->cloudTexture = "pictures/sky/cloud1.jpg"; 79 80 cloudModel.Load("sky.sgl"); 81 cloudModel.Unitize(); 82 83 // Get the bounding box of the sky dome 84 float bbox[3] = {0}; 85 cloudModel.GetDimensions(bbox[0], bbox[1], bbox[2]); 86 87 // Load Shaders 88 this->cloudShader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/sky.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/sky.frag"); 89 90 // Tell the shader the bounding box of the sky dome 91 this->cloudShader->bindShader("bbox", bbox, 4); 92 93 // Initialze Cloud Material 94 this->cloudMaterial = new Material("Sky"); 95 this->cloudMaterial->setIllum(3); 96 this->cloudMaterial->setAmbient(1.0, 1.0, 1.0); 97 this->cloudMaterial->setDiffuseMap(this->cloudTexture); 98 99 } 100 101 102 void CloudEffect::loadParams(const TiXmlElement* root) 103 { 104 WeatherEffect::loadParams(root); 105 106 // LoadParam(root, "speed", this, CloudEffect, setCloudAnimation); 107 // LoadParam(root, "texture", this, CloudEffect, setCloudTexture); 108 109 LOAD_PARAM_START_CYCLE(root, element); 110 { 111 LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption); 112 } 113 LOAD_PARAM_END_CYCLE(element); 114 } 115 116 117 bool CloudEffect::activate() 118 { 119 PRINTF(0)( "Activating CloudEffect with Material %s\n", this->cloudTexture.c_str()); 120 121 this->cloudActivate = true; 122 123 } 124 125 bool CloudEffect::deactivate() 126 { 127 PRINTF(0)("Deactivating CloudEffect\n"); 128 129 this->cloudActivate = false; 130 } 131 132 void CloudEffect::draw() const 133 { 134 if (!this->cloudActivate) 135 return; 136 137 // glMatrixMode(GL_MODELVIEW); 138 // glPushMatrix(); 139 // 140 // // Move sphere along with the camera 141 // Vector r = State::getCameraNode()->getAbsCoor(); 142 // glTranslatef(r.x, r.y, r.z); 143 // 144 // // Sky movement 145 // glRotatef(mover, 0, 0, 1); 146 // 147 // cloudMaterial->select(); 148 // gluSphere(this->sphereObj, this->sphereRadius, 20, 20); 149 // glPopMatrix(); 150 151 // ****** 152 153 glMatrixMode(GL_MODELVIEW); 154 glPushMatrix(); 65 155 66 156 // glClearColor(0.0f, 0.0f, 0.0f, 0.0f); … … 72 162 73 163 glLineWidth(3.0f); 74 75 float diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};76 float position[] = {0.0f, 2.0f, 0.0f, 1.0f};77 float specular[] = {1.0f, 1.0f, 1.0f, 1.0f};78 79 glEnable(GL_LIGHTING);80 glEnable( GL_LIGHT0);81 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);82 glLightfv(GL_LIGHT0, GL_POSITION, position);83 glLightfv(GL_LIGHT0, GL_SPECULAR, specular);84 85 float shininess = 5.0f;86 glEnable(GL_COLOR_MATERIAL);87 glMaterialf( GL_FRONT, GL_SHININESS, shininess);88 glMaterialfv(GL_FRONT, GL_SPECULAR, specular);89 90 this->cloudTexture = "pictures/sky/cloud1.jpg";91 92 g_sky_model.Load("sky.sgl");93 g_sky_model.Unitize();94 95 /* Get the bounding box of the sky dome. */96 float bbox[3] = {0};97 g_sky_model.GetDimensions(bbox[0], bbox[1], bbox[2]);98 99 // this->skyShader = (Shader*)ResourceManager::getInstance()->load("shaders/sky.vert", SHADER, RP_GAME, "shaders/skyfrag");100 this->skyShader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/sky.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/sky.frag");101 102 /* Tell the shader the bounding box of the sky dome. */103 this->skyShader->bindShader("bbox", bbox, 4);104 105 //g_cloud_texture = 0;106 107 g_tint[4] = ( 0.9f, 0.7f, 0.7f, 1.0f );108 g_scroll = 1.0f;109 time = 0.0f;110 }111 112 113 void CloudEffect::loadParams(const TiXmlElement* root)114 {115 WeatherEffect::loadParams(root);116 117 LoadParam(root, "speed", this, CloudEffect, setCloudAnimation);118 LoadParam(root, "texture", this, CloudEffect, setCloudTexture);119 }120 121 122 bool CloudEffect::activate()123 {124 PRINTF(0)( "Activating CloudEffect with Material %s\n", this->cloudTexture.c_str());125 126 this->cloudMaterial = new Material("Sky");127 this->cloudMaterial->setIllum(3);128 this->cloudMaterial->setAmbient(1.0, 1.0, 1.0);129 this->cloudMaterial->setDiffuseMap(this->cloudTexture);130 }131 132 bool CloudEffect::deactivate()133 {134 PRINTF(0)("Deactivating CloudEffect\n");135 }136 137 void CloudEffect::draw() const138 {139 140 // glMatrixMode(GL_MODELVIEW);141 // glPushMatrix();142 //143 // // Move sphere along with the camera144 // Vector r = State::getCameraNode()->getAbsCoor();145 // glTranslatef(r.x, r.y, r.z);146 //147 // // Sky movement148 // glRotatef(mover, 0, 0, 1);149 //150 // cloudMaterial->select();151 // gluSphere(this->sphereObj, this->sphereRadius, 20, 20);152 // glPopMatrix();153 154 // ******155 156 glMatrixMode(GL_MODELVIEW);157 glPushMatrix();158 164 159 165 static float time = 0.0f; … … 164 170 // gluLookAt(eye[x], eye[y], eye[z], look[x], look[y], look[z], up[x], up[y], up[z]); 165 171 166 / * Turn off the depth buffer when rendering the background. */172 // Turn off the depth buffer when rendering the background 167 173 // glDisable(GL_DEPTH_TEST); 168 174 169 this-> skyShader->activateShader();175 this->cloudShader->activateShader(); 170 176 171 177 /* Select the shader program and update parameters. */ 172 178 /* The "time" parameter controls the cloud scrolling. */ 173 this-> skyShader->bindShader("time", &time, 1);179 this->cloudShader->bindShader("time", &time, 1); 174 180 /* The "horizon" parameter controls the sky tinting. */ 175 this-> skyShader->bindShader("horizon", g_tint, 4);176 181 this->cloudShader->bindShader("horizon", cloudTint, 4); 182 177 183 glActiveTexture(GL_TEXTURE0 + 0); 178 184 glActiveTexture(GL_TEXTURE0 + 1); 179 /* Load the cloud texture. */ 185 186 // Load the cloud texture 180 187 //glBindTexture(GL_TEXTURE_2D, g_cloud_texture); 181 188 this->cloudMaterial->select(); 182 183 / * Render the sky dome. */184 g_sky_model.Render();185 186 / * Unselect the shader. */189 190 // Render the sky dome 191 cloudModel.Render(); 192 193 // Unselect the shader 187 194 Shader::deactivateShader(); 188 195 … … 203 210 204 211 glPopMatrix(); 212 205 213 } 206 214 207 215 void CloudEffect::tick (float dt) 208 216 { 209 // mover = mover + this->cloudSpeed * dt; 210 211 /* Update the timer for scrolling the clouds. */ 212 time = time + ((1.0f / 2000.0f) * g_scroll); 213 } 214 217 if (!this->cloudActivate) 218 return; 219 220 // Update the timer for scrolling the clouds 221 time = time + ((1.0f / 2000.0f) * cloudScroll); 222 } 223 -
branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h
r8175 r8242 33 33 virtual bool deactivate(); 34 34 35 inline void activateCloud() { this->activate(); } 36 inline void deactivateCloud() { this->deactivate(); } 37 35 38 virtual void draw() const; 36 39 virtual void tick(float dt); 37 40 38 // void setRadius(float radius); 39 // void setTexture(char* fileName); 41 inline void setCloudOption(const std::string& option) { 42 if (option == "activate") this->cloudActivate = true; 43 } 40 44 41 45 … … 43 47 void initialize(char* fileName); 44 48 45 // GLUquadricObj* sphereObj; // A Placeholder for the Sphere. 49 bool cloudActivate; 50 46 51 Material* cloudMaterial; // A Material for the Sphere. 47 float sphereRadius; // Radius of the Sphere.48 52 49 float mover;50 float cloudSpeed;51 53 std::string cloudTexture; 52 54 53 inline void setCloudTexture(const std::string& file) { this->cloudTexture = file; }54 inline void setCloudAnimation(float speed) { this->cloudSpeed = speed; }55 Sglmodel_sgl cloudModel; 56 Shader* cloudShader; 55 57 56 Sglmodel_sgl g_sky_model;57 Shader* skyShader;58 GLfloat cloudTint[4]; 59 GLfloat cloudScroll; 58 60 59 float g_tint[4]; 60 float g_scroll; 61 62 float time; 63 61 float time; 64 62 65 63 }; -
branches/atmospheric_engine/src/lib/graphics/effects/rain_effect.cc
r8181 r8242 125 125 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" ); 126 126 127 this->rainActivate = true; 128 127 129 if (unlikely(RainEffect::rainParticles == NULL)) 128 130 { … … 134 136 RainEffect::rainParticles->setRadius(0.2, 0.02); 135 137 RainEffect::rainParticles->setRadius(1, 0.01); 136 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); 137 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); 138 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); 138 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1 139 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2 140 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey 139 141 } 140 142 … … 158 160 { 159 161 PRINTF(0)("Deactivating RainEffect\n"); 162 163 this->rainActivate = false; 160 164 this->emitter->setSystem(NULL); 161 162 165 this->soundSource.stop(); 163 166 … … 167 170 void RainEffect::tick (float dt) 168 171 { 169 if (RainEffect::rainParticles != NULL) { 170 if (this->rainMove) { 171 this->rainCoord = State::getCameraNode()->getAbsCoor(); 172 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z); 173 } 172 if (!this->rainActivate) 173 return; 174 175 if (this->rainMove) { 176 this->rainCoord = State::getCameraNode()->getAbsCoor(); 177 this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z); 178 } 179 180 if (this->rainStartDuration != 0 && this->localTimer < this->rainStartDuration) { 181 this->localTimer += dt; 182 float progress = this->localTimer / this->rainStartDuration; 183 184 // PRINTF(0)("Progress %f: \n", progress); 185 186 // use alpha in color to fade in 187 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1 188 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2 189 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey 190 191 // increase radius for more "heavy" rain 192 RainEffect::rainParticles->setRadius(0, 0.03 * progress); 193 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress); 194 RainEffect::rainParticles->setRadius(1, 0.01 * progress); 195 196 // increase sound volume 197 // this->soundSource.fadein(this->rainBuffer, 10); 198 } 174 199 175 if (this->rainStartDuration != 0 && this->localTimer < this->rainStartDuration) {176 this->localTimer += dt;177 float progress = this->localTimer / this->rainStartDuration;178 179 // PRINTF(0)("Progress %f: \n", progress);180 181 // use alpha in color to fade in182 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1183 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2184 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2 * progress); // light grey185 186 // increase radius for more "heavy" rain187 RainEffect::rainParticles->setRadius(0, 0.03 * progress);188 RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);189 RainEffect::rainParticles->setRadius(1, 0.01 * progress);190 191 // increase sound volume192 // this->soundSource.fadein(this->rainBuffer, 10);193 }194 }195 200 } 196 201 197 202 void RainEffect::startRaining() { 198 203 199 if ( RainEffect::rainParticles != NULL)204 if (this->rainActivate) 200 205 this->deactivate(); 201 206 -
branches/atmospheric_engine/src/lib/graphics/effects/snow_effect.cc
r8023 r8242 53 53 } 54 54 55 56 55 if(snowActivate) 56 this->activate(); 57 57 } 58 58 … … 76 76 LoadParam(root, "emissionRate", this, SnowEffect, emissionRate); 77 77 LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity); 78 78 LoadParam(root, "wind", this, SnowEffect, wind); 79 79 LoadParam(root, "size", this, SnowEffect, size); 80 80 LoadParam(root, "coord", this, SnowEffect, coord); 81 81 82 83 84 85 86 82 LOAD_PARAM_START_CYCLE(root, element); 83 { 84 LoadParam_CYCLE(element, "option", this, SnowEffect, setSnowOption); 85 } 86 LOAD_PARAM_END_CYCLE(element); 87 87 } 88 88 … … 92 92 93 93 // Default values 94 95 94 this->snowActivate = false; 95 this->snowMove = false; 96 96 this->particles = 12000; 97 97 this->texture = "maps/snow_flake_01_32x32.png"; … … 109 109 this->alpha = 0.5; 110 110 this->snowSize = Vector2D(2500, 2500); 111 111 this->snowCoord = Vector(100,450,400); 112 112 this->snowWindForce = 1; 113 114 // this->activated = false;115 113 } 116 114 … … 118 116 { 119 117 PRINTF(0)("Activating SnowEffect\n"); 120 // activated = true; 118 119 this->snowActivate = true; 121 120 122 121 SnowEffect::snowParticles = new SpriteParticles(particles); … … 140 139 this->emitter->setSize(snowSize); 141 140 142 //SnowEffect::snowParticles->precache(8);141 // SnowEffect::snowParticles->precache(8); 143 142 144 143 if (this->snowWindForce > 1) … … 150 149 { 151 150 PRINTF(0)("Deactivating SnowEffect\n"); 152 //activated = false; 153 151 152 this->snowActivate = false; 154 153 this->emitter->setSystem(NULL); 155 154 … … 161 160 void SnowEffect::draw() const 162 161 { 162 if (!this->snowActivate) 163 return; 163 164 } 164 165 165 166 void SnowEffect::tick(float dt) 166 {/* 167 float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len(); 168 169 if(activated) 170 { 171 if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y) 172 this->deactivate(); 173 else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y) 174 this->alpha = 0.15; 175 else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y) 176 this->alpha = 0.25; 177 else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y) 178 this->alpha = 0.4; 179 180 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 181 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 182 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 183 } 184 else 185 { 186 if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y ) 187 this->activate(); 188 if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y ) 189 this->alpha = 0.25; 190 else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y ) 191 this->alpha = 0.4; 192 else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y ) 193 this->alpha = 0.5; 194 195 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 196 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 197 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 198 }*/ 199 if (this->snowMove) { 200 this->snowCoord = State::getCameraNode()->getAbsCoor(); 201 this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z); 202 } 203 } 204 167 { 168 if (!this->snowActivate) 169 return; 170 171 /* 172 float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len(); 173 174 if(activated) 175 { 176 if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y) 177 this->deactivate(); 178 else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y) 179 this->alpha = 0.15; 180 else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y) 181 this->alpha = 0.25; 182 else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y) 183 this->alpha = 0.4; 184 185 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 186 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 187 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 188 } 189 else 190 { 191 if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y ) 192 this->activate(); 193 if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y ) 194 this->alpha = 0.25; 195 else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y ) 196 this->alpha = 0.4; 197 else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y ) 198 this->alpha = 0.5; 199 200 SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha); 201 SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2); 202 SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0); 203 }*/ 204 205 if (this->snowMove) { 206 this->snowCoord = State::getCameraNode()->getAbsCoor(); 207 this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z); 208 } 209 } -
branches/atmospheric_engine/src/lib/graphics/effects/snow_effect.h
r8023 r8242 33 33 virtual bool deactivate(); 34 34 35 inline void activateSnow() { this->activate(); } 36 inline void deactivateSnow() { this->deactivate(); } 37 35 38 virtual void draw() const; 36 39 virtual void tick(float dt); 37 40 38 void activateSnow() { this->activate(); }39 void deactivateSnow() { this->deactivate(); }40 41 41 42 inline void numParticles(int n) { this->particles = n; } … … 48 49 inline void size(float sizeX, float sizeY) { this->snowSize = Vector2D(sizeX, sizeY); } 49 50 inline void coord(float x, float y, float z) { this->snowCoord = Vector(x, y, z); } 50 inline void wind(int force) { this->snowWindForce = force; } 51 inline void setSnowOption(const std::string& option) { /*if (option == "fade") this->snowFade = true;*/ 52 if (option == "movesnow") this->snowMove = true; 53 if (option == "activate") this->snowActivate = true; } 51 inline void wind(int force) { this->snowWindForce = force; } 52 53 inline void setSnowOption(const std::string& option) { 54 /*if (option == "fade") this->snowFade = true;*/ 55 if (option == "movesnow") this->snowMove = true; 56 if (option == "activate") this->snowActivate = true; 57 } 54 58 55 59 56 60 private: 57 int 58 std::string 59 float 60 float 61 float 62 float 63 float 64 float 65 float 66 Vector 67 Vector2D 68 int 61 int particles; 62 std::string texture; 63 float life, randomLife; 64 float snowRadius, randomRadius; 65 float snowMass, randomMass; 66 float rate; 67 float velocity, randomVelocity; 68 float angle, randomAngle; 69 float alpha; 70 Vector snowCoord; 71 Vector2D snowSize; 72 int snowWindForce; 69 73 70 //bool activated; 71 bool snowMove; 72 bool snowActivate; 73 74 PlaneEmitter* emitter; 74 bool snowMove; 75 bool snowActivate; 75 76 76 static SpriteParticles* snowParticles; 77 OrxSound::SoundSource soundSource; 78 OrxSound::SoundBuffer* windBuffer; 77 PlaneEmitter* emitter; 78 79 static SpriteParticles* snowParticles; 80 OrxSound::SoundSource soundSource; 81 OrxSound::SoundBuffer* windBuffer; 79 82 80 83 };
Note: See TracChangeset
for help on using the changeset viewer.