Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3418 in orxonox.OLD for orxonox/trunk/src/importer/model.cc


Ignore:
Timestamp:
Feb 22, 2005, 6:14:44 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk/importer: added primitive sphere, but it still has some errors on it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/importer/model.cc

    r3400 r3418  
    1616#include "model.h"
    1717#include <math.h>
     18#include <stdarg.h>
    1819
    1920using namespace std;
     
    4748      break;
    4849    case SPHERE:
     50      this->sphereModel();
    4951      break;
    5052    case CYLINDER:
     
    456458
    457459/**
    458    \brief imports a new Face.
    459    \param faceElemCount The Cout of Vertices this Face has.
    460    \param ... The Elements by number.
    461 
    462    \todo hmmpf... this also has to parse normals and vertices... sounds like stress...
    463 */
    464 bool Model::addFace(const float faceElemCount, ...)
    465 {
    466   // TODO
    467 
     460   \brief adds a new Face
     461   \param faceElemCount the number of Vertices to add to the Face.
     462   \param type 0: vertex only, 1: vertex and normal, 2: vertex and Texture, 3 vertex, normal and texture
     463*/
     464bool Model::addFace(const float faceElemCount, int type, ...)
     465{
     466   if (this->currentGroup->faceCount > 0)
     467    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
     468  this->initFace (this->currentGroup->currentFace);
     469
     470  FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement;
     471  tmpElem->next = NULL;
     472 
     473  va_list itemlist;
     474  va_start (itemlist, type);
     475
     476  for (int i = 0; i < faceElemCount; i++)
     477    {
     478      if (this->currentGroup->currentFace->vertexCount>0)
     479          tmpElem = tmpElem->next = new FaceElement;
     480      tmpElem->next = NULL;
     481
     482      tmpElem->vertexNumber = va_arg (itemlist, int) -1;
     483      if (type >= 2)
     484        tmpElem->texCoordNumber = va_arg (itemlist, int) -1;
     485      if (type == 1 || type ==3)
     486        tmpElem->normalNumber = va_arg(itemlist, int) -1;
     487      this->currentGroup->currentFace->vertexCount++;
     488    }
     489  va_end(itemlist);
     490
     491  this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount - 2;
    468492}
    469493
     
    830854
    831855
     856void Model::sphereModel()
     857{
     858  int detail = 30;
     859  if (detail <= 0) detail = 1;
     860  float df = (float)detail;
     861  for (float i = 0.0; i < df/2; i+=1.0)
     862    {
     863      for (float j = 0.0; j < df; j+=1.0)
     864      {
     865        float vz = i/df *2.0*PI - PI/2.0;
     866        this->addVertex(cos(j/df*2.0*PI) * cos(vz) ,
     867                        sin(j/df*2.0*PI) * cos(vz),
     868                        sin(vz));
     869        //if (j==0.0)
     870        //printf ("%f %f\n", vz, sin (vz));
     871        if (i==0.0)
     872                  printf("%f, %f\n", j/df*2.0*PI, cos(j/df*PI));
     873      }
     874    }
     875  vertices->debug();
     876  for (int i = 0; i < detail/2; i++)
     877    for (int j = 1; j < detail; j++)
     878      {
     879        unsigned int v1,v2,v3,v4;
     880        v1 = i*detail +j;
     881
     882        /*      if (j+1 == detail)
     883          {
     884            v2 = i*detail +1;
     885            v3 = i*detail+detail + 1;
     886          }
     887          else*/
     888          {
     889            v2 = i*detail +j+1;
     890            v3 = i*detail+detail + j+1;
     891          }
     892        v4 = i*detail+detail + j;
     893        //printf("%i %i %i %i\n", v1, v2, v3, v4);
     894        this->addFace(4, 0, v1, v2, v3, v4);
     895      }
     896}
     897
    832898void Model::cylinderModel()
    833899{
Note: See TracChangeset for help on using the changeset viewer.