Changeset 8242 in orxonox.OLD for branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc
- Timestamp:
- Jun 8, 2006, 2:04:37 PM (19 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.