Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3761 in orxonox.OLD


Ignore:
Timestamp:
Apr 8, 2005, 12:49:40 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: added proto_world_entity to easily create a world_entity

Location:
orxonox/trunk/src
Files:
2 edited
2 copied

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/Makefile.am

    r3750 r3761  
    7171                 lib/math/vector.cc \
    7272                 lib/math/curve.cc \
    73                  glmenu/glmenu_imagescreen.cc
     73                 glmenu/glmenu_imagescreen.cc 
    7474
    7575noinst_HEADERS = orxonox.h \
     
    132132             proto/proto_class.cc \
    133133             proto/proto_singleton.h \
    134              proto/proto_singleton.cc
     134             proto/proto_singleton.cc \
     135             proto/proto_world_entity.h \
     136             proto/proto_world_entity.cc
    135137
    136138if SUB_PROJECTS
  • orxonox/trunk/src/Makefile.in

    r3750 r3761  
    280280                 lib/math/vector.cc \
    281281                 lib/math/curve.cc \
    282                  glmenu/glmenu_imagescreen.cc
     282                 glmenu/glmenu_imagescreen.cc 
    283283
    284284noinst_HEADERS = orxonox.h \
     
    339339             proto/proto_class.cc \
    340340             proto/proto_singleton.h \
    341              proto/proto_singleton.cc
     341             proto/proto_singleton.cc \
     342             proto/proto_world_entity.h \
     343             proto/proto_world_entity.cc
    342344
    343345@SUB_PROJECTS_FALSE@SUB_PROGS =
  • orxonox/trunk/src/proto/proto_world_entity.cc

    r3760 r3761  
    1010
    1111   ### File Specific:
    12    main-programmer: Benjamin Grauer
     12   main-programmer: ...
    1313   co-programmer: ...
    1414*/
    1515
    16 
    17 #include "terrain.h"
     16#include "proto_world_entity.h"
     17#include "glincl.h"
    1818#include "stdincl.h"
     19#include "vector.h"
    1920#include "model.h"
    20 #include "vector.h"
    21 #include "glincl.h"
    2221
    2322using namespace std;
    24 
    2523
    2624/**
     
    2826
    2927*/
    30 Terrain::Terrain ()
     28ProtoWorldEntity::ProtoWorldEntity ()
    3129{
    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);
    6431}
    6532
    6633/**
    6734   \brief standard deconstructor
     35*/
     36ProtoWorldEntity::~ProtoWorldEntity ()
     37{
    6838
    69 */
    70 Terrain::~Terrain ()
    71 {
    72   if (objectList)
    73     glDeleteLists(this->objectList, 1);
    7439}
    7540
    7641
    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*/
     45void ProtoWorldEntity::draw ()
    8746{
    8847  glMatrixMode(GL_MODELVIEW);
     
    9554                this->getAbsCoor ().z);
    9655  /* rotate */
    97   this->getAbsDir ().matrix (matrix);
     56  this->getAbsDir().matrix(matrix);
    9857  glMultMatrixf((float*)matrix);
    9958
    100   if (objectList)
    101     glCallList(objectList);
    102   else if (model)
     59  if (model)
    10360    model->draw();
    104   //  this->model->draw();
    10561  glPopMatrix();
    10662}
    107 
    108 
    109 void Terrain::buildDebugTerrain(DebugTerrain debugTerrain)
    110 {
    111   // if the terrain is the Terrain of Dave
    112   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 #else
    136       height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;
    137 #endif
    138      
    139       //Die Huegel ein wenig glaetten
    140       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 Vektoren
    146       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  
    11/*!
    2     \file terrain.h
    3     \brief Defines and handles the terrain of the World
     2    \file proto_world_entity
    43
    5     \todo implement it
    6 
    7     The terrain should either be build from a Model a OBJModel or from a HeightMap.
    84*/
    95
    10 #ifndef _TERRAIN_H
    11 #define _TERRAIN_H
     6#ifndef _PROTO_WORLD_ENTITY_H
     7#define _PROTO_WORLD_ENTITY_H
    128
    139#include "world_entity.h"
    1410
    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 ...
     12class ProtoWorldEntity : public WorldEntity
    2313{
    2414
    2515 public:
    26   Terrain();
    27   Terrain(char* fileName);
    28   Terrain(DebugTerrain debugTerrain);
    29   virtual ~Terrain();
     16  ProtoWorldEntity();
     17  virtual ~ProtoWorldEntity();
    3018  void init();
    3119 
    32   void buildDebugTerrain(DebugTerrain debugTerrain);
    3320  virtual void draw();
    3421
    3522 private:
    36   int objectList;
     23
    3724};
    3825
    39 #endif /* _TERRAIN_H */
     26#endif /* _PROTO_WORLD_ENTITY_H */
Note: See TracChangeset for help on using the changeset viewer.