- Timestamp:
- Dec 17, 2004, 1:19:06 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world.cc
r3194 r3199 191 191 glBegin(GL_QUADS); 192 192 float height [500][100]; 193 float size = 2.0; 194 for ( int i = 0; i<=200; i+=1) 193 Vector normal_vectors[500][100]; 194 float size = 2; 195 196 197 for ( int i = 0; i<400; i+=1) 198 { 199 for (int j = 0; j<100;j+=1) 200 { 201 //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; 202 #ifdef __WIN32__ 203 height[i][j]=(sin((float)j/3)*rand()*i/182400)*.2; 204 #else 205 height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.2; 206 #endif 207 } 208 } 209 //Die Hügel ein wenig glätten 210 for (int h=1; h<2;h++) 211 for (int i=1;i<399 ;i+=1 ) 212 for(int j=1;j<99;j+=1) 213 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; 214 215 //Berechnung von normalen Vektoren 216 217 for(int i=1;i<399;i+=1){ 218 for(int j=1;j<99 ;j+=1) 219 195 220 { 196 for (int j = 0; j<=50;j+=1) 197 { 198 height[i][j] = rand()/200321400 + (j-25)*(j-25)/30; 221 Vector* v1 = new Vector (size*i,size*(j-25)-50,height[i][j]-20 ); 222 Vector* v2 = new Vector (size*(i+1),size*(j-25)-50,height[i+1][j]-20); 223 Vector* v3 = new Vector (size*(i),size*(j-24)-50,height[i][j+1]-20); 224 Vector* v4 = new Vector (size*(i-1),size*(j-25)-50,height[i-1][j]-20); 225 Vector* v5 = new Vector (size*(i),size*(j-26)-50,height[i][j-1]-20); 226 227 Vector c1 = *v1 - *v2; 228 Vector c2 = *v1 - *v3; 229 Vector c3= *v1 - *v4; 230 Vector c4 = *v1 - *v5; 231 normal_vectors[i][j]=c1.cross(*v1-*v3)+c2.cross(*v1-*v4)+c3.cross(*v1-*v5)+c4.cross(*v1-*v2); 232 normal_vectors[i][j].normalize(); 233 234 235 236 237 } 238 } 239 int snowheight=3; 240 for ( int i = 0; i<400; i+=1) 241 { 242 for (int j = 0; j<100;j+=1) 243 { 244 Vector* v1 = new Vector (size*i, size*(j-25)-50, height[i][j]-20 ); 245 Vector* v2 = new Vector (size*(i+1), size*(j-25)-50, height[i+1][j]-20); 246 Vector* v3 = new Vector (size*(i+1), size*(j-24)-50, height[i+1][j+1]-20); 247 Vector* v4 = new Vector (size*(i), size*(j-24)-50, height[i][j+1]-20); 248 float a[3]; 249 if(height[i][j]<snowheight){ 250 a[0]=0; 251 a[1]=1.0-height[i][j]/10-.3; 252 a[2]=0; 253 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 254 } 255 else{ 256 a[0]=1.0; 257 a[1]=1.0; 258 a[2]=1.0; 259 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 199 260 200 261 } 201 } 202 for ( int i = 0; i<=200; i+=1) 203 { 204 for (int j = 0; j<=50;j+=1) 205 { 206 Vector* v1 = new Vector (size*i, size*j-25*size, height[i][j] -20); 207 Vector* v2 = new Vector (size*i+size, size*j-25*size, height[i+1][j]-20); 208 Vector* v3 = new Vector (size*i+size, size*j+size-25*size, height[i+1][j+1]-20); 209 Vector* v4 = new Vector (size*i, size*j+size -25*size, height[i][j+1]-20); 210 211 Vector c1 = *v2 - *v1; 212 Vector c2 = *v3 - *v2; 213 Vector c3 = *v4 - *v3; 214 Vector c4 = *v1 - *v4; 215 216 c1.cross(*v4 - *v1); 217 c2.cross(*v1 - *v2); 218 c3.cross(*v2 - *v3); 219 c4.cross(*v3 - *v4); 220 221 222 glVertex3f(v1->x, v1->y, v1->z); 223 224 glVertex3f(v2->x, v2->y, v2->z); 225 226 glVertex3f(v3->x, v3->y, v3->z); 227 glNormal3f(c4.x, c4.y, c4.z); 228 glVertex3f(v4->x, v4->y, v4->z); 229 230 } 231 } 232 glEnd(); 233 /* 262 glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); 263 glVertex3f(v1->x, v1->y, v1->z); 264 if(height[i+1][j]<snowheight){ 265 a[0]=0; 266 a[1] =1.0-height[i+1][j]/10-.3; 267 a[2]=0; 268 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 269 } 270 else{ 271 a[0]=1.0; 272 a[1]=1.0; 273 a[2]=1.0; 274 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 275 276 } 277 glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); 278 glVertex3f(v2->x, v2->y, v2->z); 279 if(height[i+1][j+1]<snowheight){ 280 a[0]=0; 281 a[1] =1.0-height[i+1][j+1]/10-.3; 282 a[2]=0; 283 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 284 } 285 else{ 286 a[0]=1.0; 287 a[1]=1.0; 288 a[2]=1.0; 289 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 290 291 292 } 293 glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); 294 glVertex3f(v3->x, v3->y, v3->z); 295 if(height[i][j+1]<snowheight){ 296 a[0]=0; 297 a[1] =1.0-height[i+1][j+1]/10-.3; 298 a[2]=0; 299 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 300 } 301 else{ 302 a[0]=1.0; 303 a[1]=1.0; 304 a[2]=1.0; 305 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 306 } 307 glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); 308 glVertex3f(v4->x, v4->y, v4->z); 309 310 } 311 } 312 glEnd(); 313 /* 234 314 glBegin(GL_LINES); 235 315 for( float x = -128.0; x < 128.0; x += 25.0)
Note: See TracChangeset
for help on using the changeset viewer.