Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6037 in orxonox.OLD for trunk/src/lib/graphics


Ignore:
Timestamp:
Dec 11, 2005, 12:23:25 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: triangle Stripper

Location:
trunk/src/lib/graphics/importer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/vertex_array_model.cc

    r6012 r6037  
    3535  this->setClassID(CL_MODEL, "VertexArrayModel");
    3636
    37   this->finalized = false;
     37  this->bFinalized = false;
     38  this->newStripe();
    3839}
    3940
     
    5960
    6061/**
    61  * @brief Finalizes an Object. This can be done outside of the Class.
    62  */
    63 void VertexArrayModel::finalize()
    64 {
    65   // this creates the display List.
    66   this->importToVertexArray();
    67 
    68   this->finalized = true;
    69 }
    70 
    71 
    72 //////////
    73 // DRAW //
    74 //////////
    75 /**
    76  *  Draws the VertexArrayModels of all Groups.
    77    It does this by just calling the Lists that must have been created earlier.
    78 */
    79 void VertexArrayModel::draw () const
     62 * @brief Draws the VertexArrayModels of all Groups.
     63 *
     64 * It does this by just calling the Lists that must have been created earlier.
     65 */
     66void VertexArrayModel::draw() const
    8067{
    8168  PRINTF(4)("drawing the 3D-VertexArrayModels\n");
    8269
    83   glEnableClientState(GL_VERTEX_ARRAY);
    84   glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    85   glEnableClientState(GL_NORMAL_ARRAY);
     70  glEnableClientState(GL_VERTEX_ARRAY |
     71                      GL_TEXTURE_COORD_ARRAY |
     72                      GL_NORMAL_ARRAY);
    8673  //  glEnableClientState(GL_INDEX_ARRAY);
    8774
     
    9077  glTexCoordPointer(2, GL_FLOAT, 0, this->texCoords.getArray()); 
    9178
    92   printf("%d\n", this->indices.getCount());
    93   glDrawElements(GL_TRIANGLE_STRIP,
    94                  this->indices.getCount(),
    95                  GL_UNSIGNED_BYTE,
    96                  this->indices.getArray());
    97 
    98 
    99 
    100   /*  const GLfloat* pVertices = NULL;
    101       const GLfloat* pNorm = NULL;
    102      
    103       glBegin(GL_TRIANGLES);
    104       for( int i = 0; i < this->triangleCount; ++i)
    105       {
    106       //printf("int i = %i\n", i);
    107       pNorm = &this->normals->getArray()[this->triangles[i].indexToNormals[0]];
    108       pVertices = &this->vertices->getArray()[this->triangles[i].indexToVertices[0]];
    109       glNormal3f(pNorm[0], pNorm[1], pNorm[2]);
    110       glVertex3f(pVertices[0], pVertices[1], pVertices[2]);
    111      
    112       pNorm = &this->normals->getArray()[this->triangles[i].indexToNormals[1]];
    113       pVertices = &this->vertices->getArray()[this->triangles[i].indexToVertices[1]];
    114       glNormal3f(pNorm[0], pNorm[1], pNorm[2]);
    115       glVertex3f(pVertices[0], pVertices[1], pVertices[2]);
    116      
    117       pNorm = &this->normals->getArray()[this->triangles[i].indexToNormals[2]];
    118       pVertices = &this->vertices->getArray()[this->triangles[i].indexToVertices[2]];
    119       glNormal3f(pNorm[0], pNorm[1], pNorm[2]);
    120       glVertex3f(pVertices[0], pVertices[1], pVertices[2]);
    121      
    122       }
    123       glEnd();
    124   */
     79  for (GLuint i = 0; i+1 < this->stripes.size(); i++)
     80    {
     81      glDrawRangeElements(GL_TRIANGLE_STRIP,
     82                          stripes[i],
     83                          stripes[i+1],
     84                          this->indices.getCount(),
     85                          GL_UNSIGNED_BYTE,
     86                          this->indices.getArray());
     87    }
    12588}
    12689
     
    12992// MESH //
    13093//////////
     94/**
     95 * @brief generates a new Stripe in this Model
     96 */
     97void VertexArrayModel::newStripe()
     98{
     99  this->stripes.push_back(this->vertices.getCount()-1);
     100}
     101
     102
    131103/**
    132104 * @brief parses a vertex-String
     
    180152{
    181153  this->indices.addEntry(indice);
    182 
    183 }
    184 
    185 
    186 ////////////
    187 // openGL //
    188 ////////////
    189 /**
    190  *  reads and includes the Faces/Materials into the openGL state Machine
    191 */
    192 void VertexArrayModel::importToVertexArray()
     154}
     155
     156
     157/**
     158 * @brief Finalizes an Object. This can be done outside of the Class.
     159 */
     160void VertexArrayModel::finalize()
    193161{
    194162  // finalize the Arrays
     
    198166  this->indices.finalizeArray();
    199167
    200   //  glEnableClientState(GL_VERTEX_ARRAY);
    201   //  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    202   //  glEnableClientState(GL_NORMAL_ARRAY);
    203   //  glEnableClientState(GL_INDEX_ARRAY);
     168  this->newStripe();
     169
     170  /*
     171    glEnableClientState(GL_VERTEX_ARRAY |
     172    GL_TEXTURE_COORD_ARRAY |
     173    GL_NORMAL_ARRAY);
     174  */
     175
     176  this->bFinalized = true;
    204177}
    205178
     
    210183/////////////
    211184/**
    212  * Includes a default model
     185 * @brief Includes a default model
    213186 *
    214187 * This will inject a Cube, because this is the most basic model.
    215188 */
    216 void VertexArrayModel::cubeModel()
     189void VertexArrayModel::planeModel()
    217190{
    218191  unsigned int i, j;
     
    232205      this->addIndice(i+20);
    233206    }
    234 
    235   /*
    236   this->addVertex (-0.5, -0.5, 0.5);
    237   this->addVertex (0.5, -0.5, 0.5);
    238   this->addVertex (-0.5, 0.5, 0.5);
    239   this->addVertex (0.5, 0.5, 0.5);
    240   this->addVertex (-0.5, 0.5, -0.5);
    241   this->addVertex (0.5, 0.5, -0.5);
    242   this->addVertex (-0.5, -0.5, -0.5);
    243   this->addVertex (0.5, -0.5, -0.5);
    244 
    245   this->addTexCoor (0.0, 0.0);
    246   this->addTexCoor (1.0, 0.0);
    247   this->addTexCoor (0.0, 1.0);
    248   this->addTexCoor (1.0, 1.0);
    249   this->addTexCoor (0.0, 2.0);
    250   this->addTexCoor (1.0, 2.0);
    251   this->addTexCoor (0.0, 3.0);
    252   this->addTexCoor (1.0, 3.0);
    253   this->addTexCoor (0.0, 4.0);
    254   this->addTexCoor (1.0, 4.0);
    255   this->addTexCoor (2.0, 0.0);
    256   this->addTexCoor (2.0, 1.0);
    257   this->addTexCoor (-1.0, 0.0);
    258   this->addTexCoor (-1.0, 1.0);
    259 
    260   this->addNormal (0.0, 0.0, 1.0);
    261   this->addNormal (0.0, 0.0, 1.0);
    262   this->addNormal (0.0, 0.0, 1.0);
    263   this->addNormal (0.0, 0.0, 1.0);
    264   this->addNormal (0.0, 1.0, 0.0);
    265   this->addNormal (0.0, 1.0, 0.0);
    266   this->addNormal (0.0, 1.0, 0.0);
    267   this->addNormal (0.0, 1.0, 0.0);
    268   this->addNormal (0.0, 0.0, -1.0);
    269   this->addNormal (0.0, 0.0, -1.0);
    270   this->addNormal (0.0, 0.0, -1.0);
    271   this->addNormal (0.0, 0.0, -1.0);
    272   this->addNormal (0.0, -1.0, 0.0);
    273   this->addNormal (0.0, -1.0, 0.0);
    274   this->addNormal (0.0, -1.0, 0.0);
    275   this->addNormal (0.0, -1.0, 0.0);
    276   this->addNormal (1.0, 0.0, 0.0);
    277   this->addNormal (1.0, 0.0, 0.0);
    278   this->addNormal (1.0, 0.0, 0.0);
    279   this->addNormal (1.0, 0.0, 0.0);
    280   this->addNormal (-1.0, 0.0, 0.0);
    281   this->addNormal (-1.0, 0.0, 0.0);
    282   this->addNormal (-1.0, 0.0, 0.0);
    283   this->addNormal (-1.0, 0.0, 0.0);
    284   */
    285 }
     207}
  • trunk/src/lib/graphics/importer/vertex_array_model.h

    r6022 r6037  
    1212
    1313#include "array.h"
    14 #include <list>
     14#include <vector>
    1515
    1616/* Forward Declaration */
     
    2222/////////////
    2323//! Class that handles 3D-Models. it can also read them in and display them.
     24/**
     25 * this renders models with help of the OpenGL glVertexArray
     26 */
    2427class VertexArrayModel : public Model
    2528{
     
    3033  void draw() const;
    3134
     35
     36  void newStripe();
     37
    3238  void addVertex(float x, float y, float z);
    33 
    3439  void addNormal(float x, float y, float z);
    35 
    3640  void addTexCoor(float u, float v);
    37 
    3841  void addIndice(GLubyte indice);
    3942
    4043  void finalize();
    4144
    42 
    43   void cubeModel();
     45  //
     46  void planeModel();
    4447
    4548 private:
     
    4750
    4851 private:
    49   bool                       finalized;       //!< Sets the Object to be finalized.
     52  bool                       bFinalized;       //!< Sets the Object to be finalized.
    5053
    5154  tArray<GLfloat>            vertices;        //!< The Array that handles the Vertices.
     
    5457
    5558  tArray<GLubyte>            indices;         //!< The Array that tells us what Vertex is connected to which other one.
     59
     60  std::vector<GLuint>        stripes;         //!< A lsit of Stripes of this Model.
     61
    5662};
    5763
Note: See TracChangeset for help on using the changeset viewer.