Changeset 6693 in orxonox.OLD for branches/network/src/world_entities/environments
- Timestamp:
- Jan 25, 2006, 2:19:46 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/world_entities/environments/water.cc
r6686 r6693 54 54 this->rebuildGrid(); 55 55 this->waterMaterial = new Material(); 56 this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, (void*)"shaders/water.frag");56 this->waterShader = (Shader*)ResourceManager::getInstance()->load("shaders/water.vert", SHADER, RP_GAME, "shaders/water.frag"); 57 57 58 58 this->grid->height(this->grid->columns()/2,this->grid->rows()/2) = 100; … … 70 70 71 71 LoadParam(root, "size", this, Water, setSize) 72 73 72 .describe("the size of the WaterSurface") 73 .defaultValues(2, 1.0f, 1.0f); 74 74 75 75 LoadParam(root, "resolution", this, Water, setResolution) 76 77 76 .describe("sets the resolution of the water surface") 77 .defaultValues(2, 10, 10); 78 78 79 79 LoadParam(root, "height", this, Water, setHeight) 80 81 80 .describe("the height of the Waves") 81 .defaultValues(1, 0.5f); 82 82 } 83 83 … … 92 92 } 93 93 94 // WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel();95 // if (this->grid != NULL)96 // this->grid = NULL;94 // WE DO NOT NEED THIS AS IT IS DONE IN WORLDENTITY->setModel(); 95 // if (this->grid != NULL) 96 // this->grid = NULL; 97 97 98 98 this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY); … … 127 127 void Water::draw() const 128 128 { 129 //SkyBox::enableCubeMap(); 130 131 glBindTexture(GL_TEXTURE_2D, 15); 132 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 133 134 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 135 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 136 glEnable(GL_TEXTURE_GEN_S); 137 glEnable(GL_TEXTURE_GEN_T); 138 139 glEnable(GL_BLEND); 140 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 141 // this->waterShader->activateShader(); 142 // this->waterMaterial->select(); 143 WorldEntity::draw(); 144 //Shader::deactivateShader(); 145 146 SkyBox::disableCubeMap(); 129 if (this->grid != NULL) 130 { 131 //SkyBox::enableCubeMap(); 132 WorldEntity::draw(); 133 glBindTexture(GL_TEXTURE_2D, 15); 134 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 135 136 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 137 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 138 glEnable(GL_TEXTURE_GEN_S); 139 glEnable(GL_TEXTURE_GEN_T); 140 141 glEnable(GL_BLEND); 142 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 143 // this->waterShader->activateShader(); 144 // this->waterMaterial->select(); 145 //Shader::deactivateShader(); 146 147 SkyBox::disableCubeMap(); 148 } 147 149 } 148 150 149 151 void Water::tick(float dt) 150 152 { 151 /* 152 THE OLD USELESS ALGORITHM153 phase += dt *.1;154 for (unsigned int i = 0; i < this->grid->rows(); i++)155 {156 for (unsigned int j = 0; j < this->grid->columns(); j++)153 if (unlikely(this->velocities == NULL)) 154 return; 155 /* 156 THE OLD USELESS ALGORITHM 157 phase += dt *.1; 158 for (unsigned int i = 0; i < this->grid->rows(); i++) 157 159 { 158 this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+ 159 this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0); 160 for (unsigned int j = 0; j < this->grid->columns(); j++) 161 { 162 this->grid->height(i,j) = this->height*sin(((float)i/(float)this->grid->rows() *phase)+ 163 this->height*cos((float)j/(float)this->grid->columns()) * phase * 2.0); 164 } 160 165 } 161 } 162 this->grid->rebuildNormals(this->height);*/ 166 this->grid->rebuildNormals(this->height);*/ 163 167 164 168 … … 168 172 // wave/advection 169 173 // calc movement 170 for(j = 1; j < this->grid->rows() - 1; j++) { 171 for(i = 1; i < this->grid->columns() - 1; i++) { 174 for(j = 1; j < this->grid->rows() - 1; j++) 175 { 176 for(i = 1; i < this->grid->columns() - 1; i++) 177 { 172 178 u = this->grid->height(i+1,j)+ this->grid->height(i-1, j) + 173 this->grid->height(i, j+1) + this->grid->height(i, j-1) -174 4 * this->grid->height(i, j);179 this->grid->height(i, j+1) + this->grid->height(i, j-1) - 180 4 * this->grid->height(i, j); 175 181 this->velocities[i][j] += dt * this->viscosity * this->viscosity * u / this->height; 176 182 this->grid->height(i, j) += dt * this->velocities[i][j]; 177 183 } 178 184 } 179 /* // advect 180 for(j = 1; j < this->grid->rows() - 1; j++) { 181 for(i = 1; i < this->grid->columns() - 1; i++) { 182 this->grid->height(i, j) += dt * this->velocities[i][j]; 183 } 184 }*/ 185 // boundraries 186 for (j = 0; j < this->grid->rows(); j++) 187 { 188 this->grid->height(0,j) = this->grid->height(1,j); 189 this->grid->height(this->grid->rows()-1,j) = this->grid->height(this->grid->rows()-2, j); 190 } 191 for (i = 0; i < this->grid->rows(); i++) 192 { 193 this->grid->height(i,0) = this->grid->height(i,1); 194 this->grid->height(i,this->grid->columns()-1) = this->grid->height(i, this->grid->columns()-2); 195 } 196 /* // advect 197 for(j = 1; j < this->grid->rows() - 1; j++) { 198 for(i = 1; i < this->grid->columns() - 1; i++) { 199 this->grid->height(i, j) += dt * this->velocities[i][j]; 200 } 201 }*/ 185 202 // bound 186 // unsigned int w = this->grid->columns - 1;187 // for(i = 0; i < this->grid->columns; i++) {188 // _map[i][0].u[1] = _map[i][1 ].u[1];189 // _map[i][w].u[1] = _map[i][w-1].u[1];190 // _map[0][i].u[1] = _map[1 ][i].u[1];191 // _map[w][i].u[1] = _map[w-1][i].u[1];192 // }203 // unsigned int w = this->grid->columns - 1; 204 // for(i = 0; i < this->grid->columns; i++) { 205 // _map[i][0].u[1] = _map[i][1 ].u[1]; 206 // _map[i][w].u[1] = _map[i][w-1].u[1]; 207 // _map[0][i].u[1] = _map[1 ][i].u[1]; 208 // _map[w][i].u[1] = _map[w-1][i].u[1]; 209 // } 193 210 194 211 // diffusion 195 for(j = 1; j < this->grid->rows() - 1; j++) { 196 for(i = 1; i < this->grid->columns() - 1 ; i++) { 212 for(j = 1; j < this->grid->rows() - 1; j++) 213 { 214 for(i = 1; i < this->grid->columns() - 1 ; i++) 215 { 197 216 u = this->grid->height(i+1, j) + this->grid->height(i-1, j) + 198 217 this->grid->height(i, j+1) + this->grid->height(i, j-1) - … … 203 222 204 223 // calc normals 205 // float l[3];206 // float m[3];207 // for(j = 1; j < this->grid->rows() -1; j++) {208 // for(i = 1; i < this->grid->columns() - 1; i++) {209 // l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x;210 // l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y;211 // l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z;212 // m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x;213 // m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y;214 // m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z;215 // this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1];216 // this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2];217 // this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0];218 // }219 // }224 // float l[3]; 225 // float m[3]; 226 // for(j = 1; j < this->grid->rows() -1; j++) { 227 // for(i = 1; i < this->grid->columns() - 1; i++) { 228 // l[0] = this->grid->vertexG(i, j-1).x - this->grid->vertexG(i, j+1).x; 229 // l[1] = this->grid->vertexG(i, j-1).y - this->grid->vertexG(i, j+1).y; 230 // l[2] = this->grid->vertexG(i, j-1).z - this->grid->vertexG(i, j+1).z; 231 // m[0] = this->grid->vertexG(i-1,j).x - this->grid->vertexG(i+1, j).x; 232 // m[1] = this->grid->vertexG(i-1,j).y - this->grid->vertexG(i+1, j).y; 233 // m[2] = this->grid->vertexG(i-1,j).z - this->grid->vertexG(i+1, j).z; 234 // this->grid->normalG(i, j).x = l[1] * m[2] - l[2] * m[1]; 235 // this->grid->normalG(i, j).y = l[2] * m[0] - l[0] * m[2]; 236 // this->grid->normalG(i, j).z = l[0] * m[1] - l[1] * m[0]; 237 // } 238 // } 220 239 this->grid->rebuildNormals(this->height); 221 240 }
Note: See TracChangeset
for help on using the changeset viewer.