Changeset 8495 in orxonox.OLD for trunk/src/lib/graphics/effects/cloud_effect.cc
- Timestamp:
- Jun 15, 2006, 9:50:56 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/effects/cloud_effect.cc
r8255 r8495 21 21 #include "util/loading/resource_manager.h" 22 22 23 #include "glincl.h"24 23 #include "material.h" 25 24 #include <math.h> … … 31 30 #include "parser/tinyxml/tinyxml.h" 32 31 33 #include "sglmodel.h"34 32 35 33 using namespace std; … … 43 41 { 44 42 this->setClassID(CL_CLOUD_EFFECT, "CloudEffect"); 43 // this->toList(OM_ENVIRON); 45 44 46 45 this->init(); … … 49 48 this->loadParams(root); 50 49 51 if(cloudActivate)50 //if(cloudActivate) 52 51 this->activate(); 53 52 } … … 56 55 { 57 56 this->deactivate(); 58 59 delete this->cloudMaterial;60 61 cloudModel.Delete();62 Shader::unload(this->cloudShader);63 64 57 } 65 58 66 59 67 boolCloudEffect::init()60 void CloudEffect::init() 68 61 { 69 PRINTF(1)("Initializing CloudEffect\n"); 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); 70 71 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; 72 shader = new Shader(ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.vert", 73 ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.frag"); 74 75 this->shader->activateShader(); 77 76 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 77 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 87 this->shader->deactivateShader(); 99 88 } 100 89 … … 106 95 // LoadParam(root, "speed", this, CloudEffect, setCloudAnimation); 107 96 // LoadParam(root, "texture", this, CloudEffect, setCloudTexture); 108 97 /* 109 98 LOAD_PARAM_START_CYCLE(root, element); 110 99 { 111 100 LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption); 112 101 } 113 LOAD_PARAM_END_CYCLE(element); 102 LOAD_PARAM_END_CYCLE(element);*/ 114 103 } 115 104 116 105 117 boolCloudEffect::activate()106 void CloudEffect::activate() 118 107 { 119 PRINTF(0)( "Activating CloudEffect with Material %s\n", this->cloudTexture.c_str());108 PRINTF(0)( "Activating\n"); 120 109 121 this->cloudActivate = true; 122 110 // this->cloudActivate = true; 123 111 } 124 112 125 boolCloudEffect::deactivate()113 void CloudEffect::deactivate() 126 114 { 127 115 PRINTF(0)("Deactivating CloudEffect\n"); 128 116 129 this->cloudActivate = false;117 // this->cloudActivate = false; 130 118 } 131 119 132 120 void CloudEffect::draw() const 133 121 { 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(); 122 //if (!this->cloudActivate) 123 // return; 150 124 151 // ****** 125 //glMatrixMode(GL_MODELVIEW); 126 //glColor4f(1,1,1,1); 127 glPushMatrix(); 128 //glTranslatef(0,this->waterHeight,0); 152 129 153 glMatrixMode(GL_MODELVIEW);154 glPushMatrix();130 cloudMaterial.unselect(); 131 cloudMaterial.select(); 155 132 156 // glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 157 // glShadeModel(GL_SMOOTH); 158 // glEnable(GL_DEPTH_TEST); 159 // glEnable(GL_CULL_FACE); 160 // glCullFace(GL_BACK); 161 // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 162 163 // glLineWidth(3.0f); 133 this->shader->activateShader(); 164 134 165 static float time = 0.0f;166 // static vector3f eye = {0.0f, 0.0f, 0.0f}, look = {0.0f, 0.0f, 1.0f}, up = {0.0f, 1.0f, 0.0f};167 135 168 // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 169 // glLoadIdentity(); 170 // gluLookAt(eye[x], eye[y], eye[z], look[x], look[y], look[z], up[x], up[y], up[z]); 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(); 171 144 172 // Turn off the depth buffer when rendering the background 173 // glDisable(GL_DEPTH_TEST); 145 this->shader->deactivateShader(); 174 146 175 this->cloudShader->activateShader();147 cloudMaterial.unselect(); 176 148 177 /* Select the shader program and update parameters. */ 178 /* The "time" parameter controls the cloud scrolling. */ 179 this->cloudShader->bindShader("time", &time, 1); 180 /* The "horizon" parameter controls the sky tinting. */ 181 this->cloudShader->bindShader("horizon", cloudTint, 4); 149 glPopMatrix(); 182 150 183 glActiveTexture(GL_TEXTURE0 + 0);184 glActiveTexture(GL_TEXTURE0 + 1);185 186 // Load the cloud texture187 //glBindTexture(GL_TEXTURE_2D, g_cloud_texture);188 this->cloudMaterial->select();189 190 // Render the sky dome191 cloudModel.Render();192 193 // Unselect the shader194 Shader::deactivateShader();195 196 /* Turn on the depth buffer when rendering the foreground. */197 // glEnable(GL_DEPTH_TEST);198 199 /* Render the forground, for example, a teapot or bunny. */200 // glEnable(GL_LIGHTING);201 // glColor3f(0.0f, 1.0f, 0.0f);202 // glBegin(GL_QUADS);203 // glNormal3f( 0.0f, 1.0f, 0.0f);204 // glVertex3f( 20.0f, -1.0f, 20.0f);205 // glVertex3f( 20.0f, -1.0f, -20.0f);206 // glVertex3f(-20.0f, -1.0f, -20.0f);207 // glVertex3f(-20.0f, -1.0f, 20.0f);208 // glEnd();209 // glDisable(GL_LIGHTING);210 211 glPopMatrix();212 213 151 } 214 152 215 153 void CloudEffect::tick (float dt) 216 154 { 217 if (!this->cloudActivate) 218 return; 219 220 // Update the timer for scrolling the clouds 221 time = time + ((1.0f / 2000.0f) * cloudScroll); 155 //if (!this->cloudActivate) 156 // return; 222 157 } 223 158
Note: See TracChangeset
for help on using the changeset viewer.