Changeset 4597 in orxonox.OLD for orxonox/trunk/src/world_entities/terrain.cc
- Timestamp:
- Jun 11, 2005, 12:55:48 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/terrain.cc
r4320 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 28 28 29 29 */ 30 Terrain::Terrain () 30 Terrain::Terrain () 31 31 { 32 32 this->init(); … … 36 36 \brief Constructor for loading a Terrain out of a file 37 37 \param fileName The file to load data from. 38 38 39 39 this either loads out of an OBJ-file, or loads a heightmap if no .obj-extension is found. 40 40 */ 41 Terrain::Terrain(c har* fileName)41 Terrain::Terrain(const char* fileName) 42 42 { 43 43 this->init(); … … 68 68 69 69 */ 70 Terrain::~Terrain () 70 Terrain::~Terrain () 71 71 { 72 72 if (objectList) … … 78 78 { 79 79 this->setClassID(CL_TERRAIN, "Terrain"); 80 80 81 this->objectList = 0; 81 82 } … … 84 85 85 86 void Terrain::draw () 86 { 87 { 87 88 glMatrixMode(GL_MODELVIEW); 88 89 glPushMatrix(); 89 90 float matrix[4][4]; 90 91 91 92 /* translate */ 92 glTranslatef (this->getAbsCoor ().x, 93 this->getAbsCoor ().y, 94 93 glTranslatef (this->getAbsCoor ().x, 94 this->getAbsCoor ().y, 95 this->getAbsCoor ().z); 95 96 /* rotate */ 96 97 this->getAbsDir ().matrix (matrix); … … 112 113 objectList = glGenLists(1); 113 114 glNewList (objectList, GL_COMPILE); 114 115 115 116 glColor3f(1.0,0,0); 116 117 117 118 int sizeX = 100; 118 119 int sizeZ = 80; … … 121 122 float widthX = float (length /sizeX); 122 123 float widthZ = float (width /sizeZ); 123 124 124 125 float height [sizeX][sizeZ]; 125 126 Vector normal_vectors[sizeX][sizeZ]; 126 127 127 128 128 129 for ( int i = 0; i<sizeX-1; i+=1) 129 130 130 for (int j = 0; j<sizeZ-1;j+=1) 131 //height[i][j] = rand()/20046 + (j-25)*(j-25)/30; 131 132 #ifdef __WIN32__ 132 133 height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5; 133 134 #else 134 135 height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5; 135 136 #endif 136 137 137 138 //Die Huegel ein wenig glaetten 138 139 for (int h=1; h<2;h++) 139 140 141 142 140 for (int i=1;i<sizeX-2 ;i+=1 ) 141 for(int j=1;j<sizeZ-2;j+=1) 142 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4; 143 143 144 //Berechnung von normalen Vektoren 144 145 for(int i=1;i<sizeX-2;i+=1) 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 146 for(int j=1;j<sizeZ-2 ;j+=1) 147 { 148 Vector v1 = Vector (widthX*(1), height[i][j], widthZ*(j) ); 149 Vector v2 = Vector (widthX*(i-1), height[i-1][j], widthZ*(j)); 150 Vector v3 = Vector (widthX*(i), height[i][j+1], widthZ*(j+1)); 151 Vector v4 = Vector (widthX*(i+1), height[i+1][j], widthZ*(j)); 152 Vector v5 = Vector (widthX*(i), height[i][j-1], widthZ*(j-1)); 153 154 Vector c1 = v2 - v1; 155 Vector c2 = v3 - v1; 156 Vector c3= v4 - v1; 157 Vector c4 = v5 - v1; 158 Vector zero = Vector (0,0,0); 159 normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4); 160 normal_vectors[i][j].normalize(); 161 } 162 162 163 glBegin(GL_QUADS); 163 164 int snowheight=3; 164 165 for ( int i = 0; i<sizeX; i+=1) 165 166 { 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 166 for (int j = 0; j<sizeZ;j+=1) 167 { 168 Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2); 169 Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2); 170 Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2); 171 Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2); 172 float a[3]; 173 if(height[i][j]<snowheight){ 174 a[0]=0; 175 a[1]=1.0-height[i][j]/10-.3; 176 a[2]=0; 177 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 178 } 179 else{ 180 a[0]=1.0; 181 a[1]=1.0; 182 a[2]=1.0; 183 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 184 185 } 186 glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z); 187 glVertex3f(v1.x, v1.y, v1.z); 188 if(height[i+1][j]<snowheight){ 189 a[0]=0; 190 a[1] =1.0-height[i+1][j]/10-.3; 191 a[2]=0; 192 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 193 } 194 else{ 195 a[0]=1.0; 196 a[1]=1.0; 197 a[2]=1.0; 198 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 199 200 } 201 glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z); 202 glVertex3f(v2.x, v2.y, v2.z); 203 if(height[i+1][j+1]<snowheight){ 204 a[0]=0; 205 a[1] =1.0-height[i+1][j+1]/10-.3; 206 a[2]=0; 207 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 208 } 209 else{ 210 a[0]=1.0; 211 a[1]=1.0; 212 a[2]=1.0; 213 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 214 215 216 } 217 glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z); 218 glVertex3f(v3.x, v3.y, v3.z); 219 if(height[i][j+1]<snowheight){ 220 a[0]=0; 221 a[1] =1.0-height[i+1][j+1]/10-.3; 222 a[2]=0; 223 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 224 } 225 else{ 226 a[0]=1.0; 227 a[1]=1.0; 228 a[2]=1.0; 229 glMaterialfv(GL_FRONT,GL_DIFFUSE,a); 230 } 231 glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z); 232 glVertex3f(v4.x, v4.y, v4.z); 233 234 } 234 235 glEnd(); 235 236 glEndList(); … … 239 240 { 240 241 /* 241 242 this->model = (OBJModel*) new Model(); 242 243 this->model->setName("CUBE"); 243 244 this->model->addVertex (-0.5, -0.5, 0.5); … … 249 250 this->model->addVertex (-0.5, -0.5, -0.5); 250 251 this->model->addVertex (0.5, -0.5, -0.5); 251 252 252 253 this->model->addVertexTexture (0.0, 0.0); 253 254 this->model->addVertexTexture (1.0, 0.0); … … 268 269 */ 269 270 } 270 271 } 271 272 }
Note: See TracChangeset
for help on using the changeset viewer.