Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6262 in orxonox.OLD for branches/height_map/src


Ignore:
Timestamp:
Dec 22, 2005, 6:38:54 PM (19 years ago)
Author:
bensch
Message:

heightmap: better stripes (vector instead of tArray)

Location:
branches/height_map/src/lib/graphics/importer
Files:
2 edited

Legend:

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

    r6261 r6262  
    7575
    7676
    77   glVertexPointer(3, GL_FLOAT, 0, this->vertices.getArray());
    78   glNormalPointer(GL_FLOAT, 0, this->normals.getArray());
    79   glTexCoordPointer(2, GL_FLOAT, 0, this->texCoords.getArray());
    80   glColorPointer(3, GL_FLOAT, 0, this->colors.getArray());
    81 
    82   for (GLuint i = 1; i < this->stripes.size(); ++i)
    83     {
    84       glDrawElements(GL_TRIANGLE_STRIP, this->stripes[i] - this->stripes[i-1], GL_UNSIGNED_BYTE, this->indices.getArray()+this->stripes[i-1]);
    85 //       glDrawRangeElements(GL_TRIANGLE_STRIP,
    86 //                        this->stripes[i-1],
    87 //                        this->stripes[i],
    88 //                        this->indices.getCount(),
    89 //                        GL_UNSIGNED_BYTE,
    90 //                        this->indices.getArray());
     77  glVertexPointer(3, GL_FLOAT, 0, &this->vertices[0]);
     78  glNormalPointer(GL_FLOAT, 0, &this->normals[0]);
     79  glTexCoordPointer(2, GL_FLOAT, 0, &this->texCoords[0]);
     80  glColorPointer(3, GL_FLOAT, 0, &this->colors[0]);
     81
     82  for (GLuint i = 1; ++i < this->stripes.size(); ++i)
     83    {
     84      glDrawElements( GL_TRIANGLES,
     85                      this->stripes[i] - this->stripes[i-1],
     86                      GL_UNSIGNED_BYTE,
     87                      &this->indices[this->stripes[i-1]] );
    9188    }
    9289    glEnable(GL_LIGHTING);
     
    10299void VertexArrayModel::newStripe()
    103100{
    104   this->stripes.push_back(this->indices.getCount());
     101  // no stripes of size 0
     102  if (this->stripes.empty() || this->indices.size() != this->stripes.back())
     103    this->stripes.push_back(this->indices.size());
    105104}
    106105
     
    114113void VertexArrayModel::addVertex(float x, float y, float z)
    115114{
    116   this->vertices.addEntry(x, y, z);
     115  this->vertices.push_back(x);
     116  this->vertices.push_back(y);
     117  this->vertices.push_back(z);
    117118  this->pModelInfo.numVertices++;
    118119}
     
    129130void VertexArrayModel::addNormal(float x, float y, float z)
    130131{
    131   this->normals.addEntry(x, y, z);
     132  this->normals.push_back(x);
     133  this->normals.push_back(y);
     134  this->normals.push_back(z);
    132135  this->pModelInfo.numNormals++;
    133136}
     
    143146void VertexArrayModel::addTexCoor(float u, float v)
    144147{
    145   this->texCoords.addEntry(u);
    146   this->texCoords.addEntry(v);
     148  this->texCoords.push_back(u);
     149  this->texCoords.push_back(v);
    147150  this->pModelInfo.numTexCoor++;
    148151}
     
    156159void VertexArrayModel::addColor(float r, float g, float b)
    157160{
    158   this->colors.addEntry(r, g, b);
     161  this->colors.push_back(r);
     162  this->colors.push_back(g);
     163  this->colors.push_back(b);
    159164  // FIXME
    160165}
     
    168173void VertexArrayModel::addIndice(GLubyte indice)
    169174{
    170   this->indices.addEntry(indice);
     175  this->indices.push_back(indice);
    171176}
    172177
     
    178183{
    179184  // finalize the Arrays
    180   this->vertices.finalizeArray();
    181   this->texCoords.finalizeArray();
    182   this->normals.finalizeArray();
    183   this->colors.finalizeArray();
    184   this->indices.finalizeArray();
    185 
    186185  this->newStripe();
    187 
    188   for (int i = 0 ; i < this->stripes.size(); i++)
    189   {
    190     printf("== %d ==\n", stripes[i]);
    191 
    192   }
    193186
    194187  /*
     
    213206void VertexArrayModel::planeModel()
    214207{
    215   unsigned int sizeX = 20, sizeY = 10;
     208  unsigned int sizeX = 20, sizeY = 20;
    216209
    217210  unsigned int i, j;
     
    220213      for (j = 0; j < sizeX; j++)
    221214        {
    222           this->addVertex((float)i - sizeY/2.0, sin(-(float)i/(float)sizeY*5.0) * cos((float)j/(float)sizeX*5.0) * 10.0 , (float)(j) - sizeX/2.0);
    223           this->addNormal((float)i/(float)sizeY, 1, (float)j/(float)sizeX);
     215          this->addVertex((float)i - (float)sizeY/2.0, sin((float)i/(float)sizeY*5.0)*cos((float)j/(float)sizeX*5.0)*5.0, (float)j - (float)sizeX/2.0);
     216          this->addNormal(0.0, 1, 0.0);
    224217          this->addTexCoor((float)i/(float)sizeY, (float)j/(float)sizeY);
    225218          this->addColor((float)i/20.0, 0.0, (float)j/20.0);
     
    231224    for (j = 0; j < sizeX; j++)
    232225    {
    233       this->addIndice(sizeX*i + j);
    234       this->addIndice(sizeX*(i+1) + j);
    235     }
    236     if (i < sizeY -1 )
    237       this->newStripe();
    238   }
    239 }
     226      this->addIndice(sizeY*i + j);
     227      this->addIndice(sizeY*(i+1) + j);
     228    }
     229    this->debug();
     230    this->newStripe();
     231  }
     232}
     233
     234#include <cmath>
     235
     236void VertexArrayModel::spiralSphere(const float radius, const unsigned int loops, const unsigned int segmentsPerLoop)
     237{
     238  for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber)
     239  {
     240    float theta = 0;
     241    float phi = loopSegmentNumber * 2 * PI / segmentsPerLoop;
     242    float sinTheta = std::sin(theta);
     243    float sinPhi = std::sin(phi);
     244    float cosTheta = std::cos(theta);
     245    float cosPhi = std::cos(phi);
     246    this->addVertex(radius * cosPhi * sinTheta, radius * sinPhi * sinTheta, radius * cosTheta);
     247    this->addNormal(1,1,1);
     248    this->addTexCoor(0,0);
     249    this->addColor(.125,.436,.246);
     250  }
     251  for (unsigned int loopNumber = 0; loopNumber <= loops; ++loopNumber)
     252  {
     253    for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber)
     254    {
     255      float theta = (loopNumber * PI / loops) + ((PI * loopSegmentNumber) / (segmentsPerLoop * loops));
     256      if (loopNumber == loops)
     257      {
     258        theta = PI;
     259      }
     260      float phi = loopSegmentNumber * 2 * PI / segmentsPerLoop;
     261      float sinTheta = std::sin(theta);
     262      float sinPhi = std::sin(phi);
     263      float cosTheta = std::cos(theta);
     264      float cosPhi = std::cos(phi);
     265      this->addVertex(radius * cosPhi * sinTheta, radius * sinPhi * sinTheta, radius * cosTheta);
     266      this->addNormal(1,1,1);
     267      this->addTexCoor(0,0);
     268      this->addColor(.125,.436,.246);
     269
     270    }
     271  }
     272  for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber)
     273  {
     274    this->addIndice(loopSegmentNumber);
     275    this->addIndice(segmentsPerLoop + loopSegmentNumber);
     276  }
     277  for (unsigned int loopNumber = 0; loopNumber < loops; ++loopNumber)
     278  {
     279    for (unsigned int loopSegmentNumber = 0; loopSegmentNumber < segmentsPerLoop; ++loopSegmentNumber)
     280    {
     281      this->addIndice( ((loopNumber + 1) * segmentsPerLoop) + loopSegmentNumber);
     282      this->addIndice( ((loopNumber + 2) * segmentsPerLoop) + loopSegmentNumber);
     283    }
     284  }
     285}
     286
     287
     288
     289void VertexArrayModel::debug() const
     290{
     291  PRINT(0)("VertexArrayModel (%s): debug\n", this->getName());
     292  PRINT(0)("Stripes: %d; Indices: %d; Vertices: %d; Normals %d; TextCoords %d; Colors %d\n",
     293            this->stripes.size(),
     294            this->indices.size(),
     295            this->vertices.size()/3,
     296            this->normals.size()/3,
     297            this->texCoords.size()/2,
     298            this->colors.size() )/3;
     299  for (GLuint i = 1; i < this->stripes.size(); ++i)
     300  {
     301    PRINT(0)("Stripe-%d ::", i);
     302    for (GLuint j = this->stripes[i-1] ; j < this->stripes[i]; j++)
     303    {
     304      PRINT(0)("%d->", this->indices[j]);
     305    }
     306    PRINT(0)("\n");
     307  }
     308}
  • branches/height_map/src/lib/graphics/importer/vertex_array_model.h

    r6259 r6262  
    4747  //
    4848  void planeModel();
     49  void spiralSphere(const float radius, const unsigned int loops, const unsigned int segmentsPerLoop);
     50
     51  void debug() const;
    4952
    5053 private:
     
    5457  bool                       bFinalized;       //!< Sets the Object to be finalized.
    5558
    56   tArray<GLfloat>            vertices;        //!< The Array that handles the Vertices.
    57   tArray<GLfloat>            normals;         //!< The Array that handles the Normals.
    58   tArray<GLfloat>            texCoords;       //!< The Array that handles the VertexTextureCoordinates.
    59   tArray<GLfloat>            colors;          //!< The Array that handles Colors.
     59  std::vector<GLfloat>       vertices;        //!< The Array that handles the Vertices.
     60  std::vector<GLfloat>       normals;         //!< The Array that handles the Normals.
     61  std::vector<GLfloat>       texCoords;       //!< The Array that handles the VertexTextureCoordinates.
     62  std::vector<GLfloat>       colors;          //!< The Array that handles Colors.
    6063
    61   tArray<GLubyte>            indices;         //!< The Array that tells us what Vertex is connected to which other one.
     64  std::vector<GLubyte>       indices;         //!< The Array that tells us what Vertex is connected to which other one.
    6265
    6366  std::vector<GLuint>        stripes;         //!< A lsit of Stripes of this Model.
Note: See TracChangeset for help on using the changeset viewer.