/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: ... co-programmer: ... */ #include "environment.h" #include #include using namespace std; //Sorry Bensch #define LEVEL_LENGTH 500 dVector V1V2,V1V3,Kreuz; dVector V1,V2,V3; Environment::Environment () { //Sorry Bensch: x,y = 10 for (int x = 0; x < 50; x++) { for (int y = 0; y < 50; y++) { mountainTest[x][y] =0; } } //Sorry Bensch: x,y = 9 for (int x = 1; x < LEVEL_LENGTH; x++) { for (int y = 1; y < LEVEL_LENGTH; y++) { //mountainTest[x][y] = (float)random() / 900000000; mountainTest[x][y] = (float)(random() % 2); } } } Environment::~Environment () {} void Environment::drawEnvironment() { glPushMatrix(); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); //glScalef(0.5, 0.5, 1.0); //glTranslatef(xCor, yCor, zCor); glTranslatef( -25.0, -10.0, 0.0); glColor3f(0.6, 0.6, 0.4); glNormal3d(0,0,1); glBegin(GL_TRIANGLES); for (int x=0;x<60;x+=1) { for(int y=-30+DataTank::yOffset;y<40+DataTank::yOffset;y+=1) { if((int)DataTank::yOffset%2==1) { V1.x=x;V1.y=y;V1.z=mountainTest[x][y]; V2.x=x;V2.y=y+1;V2.z=mountainTest[x][y+1]; V3.x=x+1;V3.y=y;V3.z=mountainTest[x+1][y]; glNormal3d(-(Environment::CalcNormale(&V1,&V2,&V3)).x,-(Environment::CalcNormale(&V1,&V2,&V3)).y,-(Environment::CalcNormale(&V1,&V2,&V3).z)); glVertex3f((float)(x),(float)(y),mountainTest[x][y]); glVertex3f((float)(x),(float)(y+1),mountainTest[x][y+1]); glVertex3f((float)(x+1),(float)(y),mountainTest[x+1][y]); V1.x=x;V1.y=y+1;V1.z=mountainTest[x][y+1]; V2.x=x+1;V2.y=y+1;V2.z=mountainTest[x+1][y+1]; V3.x=x+1;V3.y=y;V3.z=mountainTest[x+1][y]; glNormal3d(-(Environment::CalcNormale(&V1,&V2,&V3)).x,-(Environment::CalcNormale(&V1,&V2,&V3)).y,-(Environment::CalcNormale(&V1,&V2,&V3).z)); glVertex3f((float)(x),(float)(y+1),mountainTest[x][y+1]); glVertex3f((float)(x+1),(float)(y+1),mountainTest[x+1][y+1]); glVertex3f((float)(x+1),(float)(y),mountainTest[x+1][y]); } else { V1.x=x;V1.y=y+1;V1.z=mountainTest[x][y+1]; V2.x=x;V2.y=y+2;V2.z=mountainTest[x][y+2]; V3.x=x+1;V3.y=y+1;V3.z=mountainTest[x+1][y+1]; glNormal3d(-(Environment::CalcNormale(&V1,&V2,&V3).x),-(Environment::CalcNormale(&V1,&V2,&V3).y),-(Environment::CalcNormale(&V1,&V2,&V3).z)); glVertex3f((float)(x),(float)(y+1),mountainTest[x][y+1]); glVertex3f((float)(x),(float)(y+2),mountainTest[x][y+2]); glVertex3f((float)(x+1),(float)(y+1),mountainTest[x+1][y+1]); V1.x=x;V1.y=y+2;V1.z=mountainTest[x][y+2]; V2.x=x+1;V2.y=y+2;V2.z=mountainTest[x+1][y+2]; V3.x=x+1;V3.y=y+1;V3.z=mountainTest[x+1][y+1]; glNormal3d(-(Environment::CalcNormale(&V1,&V2,&V3).x),-(Environment::CalcNormale(&V1,&V2,&V3).y),-(Environment::CalcNormale(&V1,&V2,&V3).z)); glVertex3f((float)(x),(float)(y+2),mountainTest[x][y+2]); glVertex3f((float)(x+1),(float)(y+2),mountainTest[x+1][y+2]); glVertex3f((float)(x+1),(float)(y+1),mountainTest[x+1][y+1]); }} } glEnd(); /*glBegin(GL_LINES); for(int y=0+DataTank::yOffset/2;y<25+DataTank::yOffset/2;y+=1) { for(int x=0;x<25;x+=1) { glVertex3f((float)(2*x),(float)(2*y),mountainTest[x][y]); glVertex3f((float)(2*(x+1)),(float)(2*y),mountainTest[x+1][y]); } } glEnd(); */ glPopMatrix(); } dVector Environment::CalcNormale(dVector *V1, dVector *V2, dVector *V3){ GLdouble Betrag; V1V2.x = V2->x - V1->x; V1V2.y = V2->y -V1->y; V1V2.z = V2->z -V1->z; V1V3.x = V3->x -V1->x; V1V3.y = V3->y -V1->y; V1V3.z = V3->z -V1->z; Kreuz.x =+((V1V2.y * V1V3.z) -(V1V2.z * V1V3.y)); Kreuz.y =-((V1V2.x *V1V3.z) -(V1V2.z * V1V3.x)); Kreuz.z =+((V1V2.x * V1V3.y) - (V1V2.y * V1V3.x)); Betrag =sqrt(pow(Kreuz.x, 2) + pow(Kreuz.y,2) +pow(Kreuz.z,2)); return Kreuz; }