Changeset 3761 in orxonox.OLD for orxonox/trunk/src/proto
- Timestamp:
- Apr 8, 2005, 12:49:40 PM (20 years ago)
- Location:
- orxonox/trunk/src/proto
- Files:
-
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/proto/proto_world_entity.cc
r3760 r3761 10 10 11 11 ### File Specific: 12 main-programmer: Benjamin Grauer12 main-programmer: ... 13 13 co-programmer: ... 14 14 */ 15 15 16 17 #include " terrain.h"16 #include "proto_world_entity.h" 17 #include "glincl.h" 18 18 #include "stdincl.h" 19 #include "vector.h" 19 20 #include "model.h" 20 #include "vector.h"21 #include "glincl.h"22 21 23 22 using namespace std; 24 25 23 26 24 /** … … 28 26 29 27 */ 30 Terrain::Terrain()28 ProtoWorldEntity::ProtoWorldEntity () 31 29 { 32 this->init(); 33 } 34 35 /** 36 \brief Constructor for loading a Terrain out of a file 37 \param fileName The file to load data from. 38 39 this either loads out of an OBJ-file, or loads a heightmap if no .obj-extension is found. 40 */ 41 Terrain::Terrain(char* fileName) 42 { 43 this->init(); 44 45 if (strstr(fileName, ".obj") || strstr(fileName, ".OBJ")) 46 { 47 this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_LEVEL); 48 } 49 else 50 { 51 // load the hightMap here. 52 } 53 } 54 55 /** 56 \brief a Constructor for the Debug-Worlds 57 58 \todo make it not compileable when not in debug-mode 59 */ 60 Terrain::Terrain(DebugTerrain debugTerrain) 61 { 62 this->init(); 63 this->buildDebugTerrain(debugTerrain); 30 this->model = (Model*)ResourceManager::getInstance()->load("cube", PRIM, RP_LEVEL); 64 31 } 65 32 66 33 /** 67 34 \brief standard deconstructor 35 */ 36 ProtoWorldEntity::~ProtoWorldEntity () 37 { 68 38 69 */70 Terrain::~Terrain ()71 {72 if (objectList)73 glDeleteLists(this->objectList, 1);74 39 } 75 40 76 41 77 void Terrain::init(void) 78 { 79 this->setClassName ("Terrain"); 80 81 this->objectList = 0; 82 } 83 84 85 86 void Terrain::draw () 42 /** 43 \biref draws this worldEntity 44 */ 45 void ProtoWorldEntity::draw () 87 46 { 88 47 glMatrixMode(GL_MODELVIEW); … … 95 54 this->getAbsCoor ().z); 96 55 /* rotate */ 97 this->getAbsDir ().matrix(matrix);56 this->getAbsDir().matrix(matrix); 98 57 glMultMatrixf((float*)matrix); 99 58 100 if (objectList) 101 glCallList(objectList); 102 else if (model) 59 if (model) 103 60 model->draw(); 104 // this->model->draw();105 61 glPopMatrix(); 106 62 } 107 108 109 void Terrain::buildDebugTerrain(DebugTerrain debugTerrain)110 {111 // if the terrain is the Terrain of Dave112 if (debugTerrain == TERRAIN_DAVE)113 {114 objectList = glGenLists(1);115 glNewList (objectList, GL_COMPILE);116 117 glColor3f(1.0,0,0);118 119 int sizeX = 100;120 int sizeZ = 80;121 float length = 1000;122 float width = 200;123 float widthX = float (length /sizeX);124 float widthZ = float (width /sizeZ);125 126 float height [sizeX][sizeZ];127 Vector normal_vectors[sizeX][sizeZ];128 129 130 for ( int i = 0; i<sizeX-1; i+=1)131 for (int j = 0; j<sizeZ-1;j+=1)132 //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;133 #ifdef __WIN32__134 height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;135 #else136 height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;137 #endif138 139 //Die Huegel ein wenig glaetten140 for (int h=1; h<2;h++)141 for (int i=1;i<sizeX-2 ;i+=1 )142 for(int j=1;j<sizeZ-2;j+=1)143 height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;144 145 //Berechnung von normalen Vektoren146 for(int i=1;i<sizeX-2;i+=1)147 for(int j=1;j<sizeZ-2 ;j+=1)148 {149 Vector v1 = Vector (widthX*(1), height[i][j], widthZ*(j) );150 Vector v2 = Vector (widthX*(i-1), height[i-1][j], widthZ*(j));151 Vector v3 = Vector (widthX*(i), height[i][j+1], widthZ*(j+1));152 Vector v4 = Vector (widthX*(i+1), height[i+1][j], widthZ*(j));153 Vector v5 = Vector (widthX*(i), height[i][j-1], widthZ*(j-1));154 155 Vector c1 = v2 - v1;156 Vector c2 = v3 - v1;157 Vector c3= v4 - v1;158 Vector c4 = v5 - v1;159 Vector zero = Vector (0,0,0);160 normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);161 normal_vectors[i][j].normalize();162 }163 164 glBegin(GL_QUADS);165 int snowheight=3;166 for ( int i = 0; i<sizeX; i+=1)167 for (int j = 0; j<sizeZ;j+=1)168 {169 Vector v1 = Vector (widthX*(i), height[i][j]-20, widthZ*(j) -width/2);170 Vector v2 = Vector (widthX*(i+1), height[i+1][j]-20, widthZ*(j) -width/2);171 Vector v3 = Vector (widthX*(i+1), height[i+1][j+1]-20, widthZ*(j+1)-width/2);172 Vector v4 = Vector (widthX*(i), height[i][j+1]-20, widthZ*(j+1)-width/2);173 float a[3];174 if(height[i][j]<snowheight){175 a[0]=0;176 a[1]=1.0-height[i][j]/10-.3;177 a[2]=0;178 glMaterialfv(GL_FRONT,GL_DIFFUSE,a);179 }180 else{181 a[0]=1.0;182 a[1]=1.0;183 a[2]=1.0;184 glMaterialfv(GL_FRONT,GL_DIFFUSE,a);185 186 }187 glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);188 glVertex3f(v1.x, v1.y, v1.z);189 if(height[i+1][j]<snowheight){190 a[0]=0;191 a[1] =1.0-height[i+1][j]/10-.3;192 a[2]=0;193 glMaterialfv(GL_FRONT,GL_DIFFUSE,a);194 }195 else{196 a[0]=1.0;197 a[1]=1.0;198 a[2]=1.0;199 glMaterialfv(GL_FRONT,GL_DIFFUSE,a);200 201 }202 glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);203 glVertex3f(v2.x, v2.y, v2.z);204 if(height[i+1][j+1]<snowheight){205 a[0]=0;206 a[1] =1.0-height[i+1][j+1]/10-.3;207 a[2]=0;208 glMaterialfv(GL_FRONT,GL_DIFFUSE,a);209 }210 else{211 a[0]=1.0;212 a[1]=1.0;213 a[2]=1.0;214 glMaterialfv(GL_FRONT,GL_DIFFUSE,a);215 216 217 }218 glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);219 glVertex3f(v3.x, v3.y, v3.z);220 if(height[i][j+1]<snowheight){221 a[0]=0;222 a[1] =1.0-height[i+1][j+1]/10-.3;223 a[2]=0;224 glMaterialfv(GL_FRONT,GL_DIFFUSE,a);225 }226 else{227 a[0]=1.0;228 a[1]=1.0;229 a[2]=1.0;230 glMaterialfv(GL_FRONT,GL_DIFFUSE,a);231 }232 glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);233 glVertex3f(v4.x, v4.y, v4.z);234 235 }236 glEnd();237 glEndList();238 }239 240 if (debugTerrain == TERRAIN_BENSCH)241 {242 /*243 this->model = (OBJModel*) new Model();244 this->model->setName("CUBE");245 this->model->addVertex (-0.5, -0.5, 0.5);246 this->model->addVertex (0.5, -0.5, 0.5);247 this->model->addVertex (-0.5, 0.5, 0.5);248 this->model->addVertex (0.5, 0.5, 0.5);249 this->model->addVertex (-0.5, 0.5, -0.5);250 this->model->addVertex (0.5, 0.5, -0.5);251 this->model->addVertex (-0.5, -0.5, -0.5);252 this->model->addVertex (0.5, -0.5, -0.5);253 254 this->model->addVertexTexture (0.0, 0.0);255 this->model->addVertexTexture (1.0, 0.0);256 this->model->addVertexTexture (0.0, 1.0);257 this->model->addVertexTexture (1.0, 1.0);258 this->model->addVertexTexture (0.0, 2.0);259 this->model->addVertexTexture (1.0, 2.0);260 this->model->addVertexTexture (0.0, 3.0);261 this->model->addVertexTexture (1.0, 3.0);262 this->model->addVertexTexture (0.0, 4.0);263 this->model->addVertexTexture (1.0, 4.0);264 this->model->addVertexTexture (2.0, 0.0);265 this->model->addVertexTexture (2.0, 1.0);266 this->model->addVertexTexture (-1.0, 0.0);267 this->model->addVertexTexture (-1.0, 1.0);268 269 this->model->finalize();270 */271 }272 273 } -
orxonox/trunk/src/proto/proto_world_entity.h
r3760 r3761 1 1 /*! 2 \file terrain.h 3 \brief Defines and handles the terrain of the World 2 \file proto_world_entity 4 3 5 \todo implement it6 7 The terrain should either be build from a Model a OBJModel or from a HeightMap.8 4 */ 9 5 10 #ifndef _ TERRAIN_H11 #define _ TERRAIN_H6 #ifndef _PROTO_WORLD_ENTITY_H 7 #define _PROTO_WORLD_ENTITY_H 12 8 13 9 #include "world_entity.h" 14 10 15 // FORWARD DEFINITION \\ 16 17 //! A simple method to call a desired debug world. 18 enum DebugTerrain {TERRAIN_DAVE, TERRAIN_BENSCH}; 19 20 21 //! A Class to handle Terrain of orxonox 22 class Terrain : public WorldEntity 11 //! A Class to ... 12 class ProtoWorldEntity : public WorldEntity 23 13 { 24 14 25 15 public: 26 Terrain(); 27 Terrain(char* fileName); 28 Terrain(DebugTerrain debugTerrain); 29 virtual ~Terrain(); 16 ProtoWorldEntity(); 17 virtual ~ProtoWorldEntity(); 30 18 void init(); 31 19 32 void buildDebugTerrain(DebugTerrain debugTerrain);33 20 virtual void draw(); 34 21 35 22 private: 36 int objectList; 23 37 24 }; 38 25 39 #endif /* _ TERRAIN_H */26 #endif /* _PROTO_WORLD_ENTITY_H */
Note: See TracChangeset
for help on using the changeset viewer.