/* 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: Benjamin Grauer co-programmer: ... */ #include "terrain.h" #include "stdincl.h" #include "model.h" #include "vector.h" #include "glincl.h" using namespace std; /** \brief standard constructor */ Terrain::Terrain () { this->init(); } /** \brief Constructor for loading a Terrain out of a file \param fileName The file to load data from. this either loads out of an OBJ-file, or loads a heightmap if no .obj-extension is found. */ Terrain::Terrain(char* fileName) { this->init(); if (strstr(fileName, ".obj") || strstr(fileName, ".OBJ")) { this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_LEVEL); } else { // load the hightMap here. } } /** \brief a Constructor for the Debug-Worlds \todo make it not compileable when not in debug-mode */ Terrain::Terrain(DebugTerrain debugTerrain) { this->init(); this->buildDebugTerrain(debugTerrain); } /** \brief standard deconstructor */ Terrain::~Terrain () { if (objectList) glDeleteLists(this->objectList, 1); } void Terrain::init(void) { this->setClassName ("Terrain"); this->objectList = 0; } void Terrain::draw () { glMatrixMode(GL_MODELVIEW); glPushMatrix(); float matrix[4][4]; /* translate */ glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); /* rotate */ this->getAbsDir ().matrix (matrix); glMultMatrixf((float*)matrix); if (this->objectList) glCallList(this->objectList); else if (this->model) this->model->draw(); glPopMatrix(); } void Terrain::buildDebugTerrain(DebugTerrain debugTerrain) { // if the terrain is the Terrain of Dave if (debugTerrain == TERRAIN_DAVE) { objectList = glGenLists(1); glNewList (objectList, GL_COMPILE); glColor3f(1.0,0,0); int sizeX = 100; int sizeZ = 80; float length = 1000; float width = 200; float widthX = float (length /sizeX); float widthZ = float (width /sizeZ); float height [sizeX][sizeZ]; Vector normal_vectors[sizeX][sizeZ]; for ( int i = 0; imodel = (OBJModel*) new Model(); this->model->setName("CUBE"); this->model->addVertex (-0.5, -0.5, 0.5); this->model->addVertex (0.5, -0.5, 0.5); this->model->addVertex (-0.5, 0.5, 0.5); this->model->addVertex (0.5, 0.5, 0.5); this->model->addVertex (-0.5, 0.5, -0.5); this->model->addVertex (0.5, 0.5, -0.5); this->model->addVertex (-0.5, -0.5, -0.5); this->model->addVertex (0.5, -0.5, -0.5); this->model->addVertexTexture (0.0, 0.0); this->model->addVertexTexture (1.0, 0.0); this->model->addVertexTexture (0.0, 1.0); this->model->addVertexTexture (1.0, 1.0); this->model->addVertexTexture (0.0, 2.0); this->model->addVertexTexture (1.0, 2.0); this->model->addVertexTexture (0.0, 3.0); this->model->addVertexTexture (1.0, 3.0); this->model->addVertexTexture (0.0, 4.0); this->model->addVertexTexture (1.0, 4.0); this->model->addVertexTexture (2.0, 0.0); this->model->addVertexTexture (2.0, 1.0); this->model->addVertexTexture (-1.0, 0.0); this->model->addVertexTexture (-1.0, 1.0); this->model->finalize(); */ } }