Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3418 in orxonox.OLD for orxonox/trunk


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

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

Location:
orxonox/trunk/src/importer
Files:
3 edited

Legend:

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

    r3400 r3418  
    5252int main(int argc, char *argv[])
    5353{
    54   verbose = 3;
     54  verbose = 1;
    5555
    5656  Uint8* keys; // This variable will be used in the keyboard routine
     
    7777      // This also packs everything into a DisplayList, and can be handled exactly as any other model.
    7878      // This is an example of a cube with Texture-Coordinates, but without explicite Vertex-Normals. (they are soft-created).
    79 
     79      /*
    8080      obj = (OBJModel*) new Model();
    8181      obj->setName("CUBE");
     
    111111      obj->addFace ("7 1 3 5");
    112112      obj->finalize();
     113      */
     114      obj = (OBJModel*) new Model(SPHERE);
    113115    }
    114116  M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0);
     
    252254              obj = new OBJModel(argv[1]);
    253255            break;
     256          case SDLK_a:
     257            zoomTo /=2;
     258            break;
     259          case SDLK_z:
     260            zoomTo *=2;
     261
    254262          }
    255263        break;
  • 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{
  • orxonox/trunk/src/importer/model.h

    r3400 r3418  
    4747
    4848  //! This is the placeholder of a Face belonging to a Group of Faces.
    49   /**
    50      \todo take Material to a call for itself.
    51 
    52      This can also be a Material-Change switch.
    53      That means if you want to change a Material inside of a group,
    54      you can create an empty face and apply a material to it, and the Importer will cahnge Colors
    55   */
    56   struct Face
     49  struct Face
    5750  {
    5851    int vertexCount;        //!< The Count of vertices this Face has.
     
    10598  bool addVertex(const float x, const float y, const float z);
    10699  bool addFace(char* faceString);
    107   bool addFace(const float faceElemCount, ...);
     100  bool addFace(const float faceElemCount, int type, ...);
    108101  bool addVertexNormal(char* normalString);
    109102  bool addVertexNormal(const float x, const float y, const float z);
     
    120113
    121114  void cubeModel(void);
     115  void sphereModel(void);
    122116  void cylinderModel(void);
    123117};
Note: See TracChangeset for help on using the changeset viewer.