Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4139 in orxonox.OLD for orxonox/branches/md2_loader/src/lib/graphics


Ignore:
Timestamp:
May 10, 2005, 10:39:01 AM (19 years ago)
Author:
patrick
Message:

orxonox/branches/md2_loader: merged trunk into branche using: svn merge ../trunk/ md2_loader -r 4063:HEAD

Location:
orxonox/branches/md2_loader/src/lib/graphics
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/md2_loader/src/lib/graphics/Makefile.in

    r4063 r4139  
    113113PACKAGE_VERSION = @PACKAGE_VERSION@
    114114PATH_SEPARATOR = @PATH_SEPARATOR@
     115PKG_CONFIG = @PKG_CONFIG@
    115116RANLIB = @RANLIB@
    116117SET_MAKE = @SET_MAKE@
  • orxonox/branches/md2_loader/src/lib/graphics/graphics_engine.cc

    r4126 r4139  
    1717
    1818#include "graphics_engine.h"
     19#include "resource_manager.h"
    1920
    2021#include "debug.h"
     
    3435  this->maxFPS = 0;
    3536  this->setClassName ("GraphicsEngine");
     37
     38  this->fullscreen = false;
     39
    3640  this->initVideo();
    3741
     
    105109 
    106110  // TO DO: Create a cool icon and use it here
    107   SDL_WM_SetIcon(SDL_LoadBMP("../data/pictures/orxonox-icon32x32.bmp"), NULL); 
    108 
     111  char* loadPic = new char[strlen(ResourceManager::getInstance()->getDataDir())+ 100];
     112  sprintf(loadPic, "%s%s", ResourceManager::getInstance()->getDataDir(),  "pictures/orxonox-icon32x32.bmp");
     113  SDL_WM_SetIcon(SDL_LoadBMP(loadPic), NULL); 
     114  delete loadPic;
    109115  // Enable default GL stuff
    110116  glEnable(GL_DEPTH_TEST);
     
    141147int GraphicsEngine::setResolution(int width, int height, int bpp)
    142148{
     149  Uint32 fullscreenFlag;
    143150  this->resolutionX = width;
    144151  this->resolutionY = height;
    145152  this->bitsPerPixel = bpp;
     153  if (this->fullscreen)
     154    fullscreenFlag = SDL_FULLSCREEN;
     155  else
     156    fullscreenFlag = 0;
    146157 
    147158  printf ("ok\n");
    148   if((this->screen = SDL_SetVideoMode(this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags)) == NULL)
     159  if((this->screen = SDL_SetVideoMode(this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags | fullscreenFlag)) == NULL)
    149160    {
    150161      PRINTF(1)("Could not SDL_SetVideoMode(%d, %d, %d, %d): %s\n", this->resolutionX, this->resolutionY, this->bitsPerPixel, this->videoFlags, SDL_GetError());
     
    152163      //    return -1;
    153164    }
    154 
     165}
     166
     167void GraphicsEngine::setFullscreen(bool fullscreen)
     168{
     169  this->fullscreen = fullscreen;
     170  this->setResolution(this->resolutionX, this->resolutionY, this->bitsPerPixel);
    155171}
    156172
     
    258274  /* Check if our resolution is restricted */
    259275  if(this->videoModes == (SDL_Rect **)-1){
    260     PRINTF(1)("All resolutions available.\n");
     276    PRINTF(2)("All resolutions available.\n");
    261277  }
    262278  else{
     
    264280    PRINT(0)("Available Resoulution Modes are\n");
    265281    for(int i = 0; this->videoModes[i]; ++i)
    266       PRINT(0)(" |  %d x %d\n", this->videoModes[i]->w, this->videoModes[i]->h);
     282      PRINT(4)(" |  %d x %d\n", this->videoModes[i]->w, this->videoModes[i]->h);
    267283  }
    268284}
  • orxonox/branches/md2_loader/src/lib/graphics/graphics_engine.h

    r4070 r4139  
    2626  int setGLattribs(void);
    2727  int setResolution(int width, int height, int bpp);
     28  void setFullscreen(bool fullscreen = false);
    2829  /** \returns the x resolution */
    2930  inline int getResolutionX(void) {return this->resolutionX;}
  • orxonox/branches/md2_loader/src/lib/graphics/importer/Makefile.in

    r4078 r4139  
    4242subdir = src/lib/graphics/importer
    4343DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
    44         $(srcdir)/Makefile.in TODO
     44        $(srcdir)/Makefile.in
    4545ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
    4646am__aclocal_m4_deps = $(top_srcdir)/configure.ac
     
    144144PACKAGE_VERSION = @PACKAGE_VERSION@
    145145PATH_SEPARATOR = @PATH_SEPARATOR@
     146PKG_CONFIG = @PKG_CONFIG@
    146147RANLIB = @RANLIB@
    147148SET_MAKE = @SET_MAKE@
  • orxonox/branches/md2_loader/src/lib/graphics/importer/array.cc

    r3590 r4139  
    112112 
    113113/**
    114    \brief Gives back the array !! MUST be executed AFTER finalize.
    115    \returns The created array.
    116 */
    117 GLfloat* Array::getArray ()
    118 {
    119   return this->array;
    120 }
    121 
    122 /**
    123    \returns The Count of entries in the Array
    124 */
    125 int Array::getCount()
    126 {
    127   return this->entryCount;
    128 }
    129 
    130 /**
    131114   \brief Simple debug info about the Array
    132115*/
    133 void Array::debug ()
     116void Array::debug (void) const
    134117{
    135118  PRINT(0)("entryCount=%i, address=%p\n", this->entryCount, this->array);
  • orxonox/branches/md2_loader/src/lib/graphics/importer/array.h

    r3590 r4139  
    2323  void addEntry(GLfloat entry0, GLfloat entry1, GLfloat entry2);
    2424 
    25   GLfloat* getArray ();
    26   int getCount();
    27   void debug(void);
     25  /** \returns The array */
     26  inline const GLfloat* getArray () const {return this->array;}
     27  /**   \returns The Count of entries in the Array*/
     28  inline int getCount(void)const {return this->entryCount;}
     29  void debug(void) const ;
    2830 private:
    2931  //! One entry of the Array
  • orxonox/branches/md2_loader/src/lib/graphics/importer/framework.cc

    r3910 r4139  
    7979    obj = new OBJModel(argv[1]);
    8080  else
    81     obj = new PrimitiveModel(SPHERE);
     81    obj = new PrimitiveModel(CYLINDER);
    8282
    8383  M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0);
  • orxonox/branches/md2_loader/src/lib/graphics/importer/material.cc

    r3966 r4139  
    4545  this->setTransparency(1.0);
    4646
    47 
    4847  this->diffuseTexture = NULL;
    4948  this->ambientTexture = NULL;
    5049  this->specularTexture = NULL;
    51 
    52   this->diffuseTextureSet = false;
    53   this->ambientTextureSet = false;
    54   this->specularTextureSet = false;
    5550
    5651  this->setName(mtlName);
     
    107102    glShadeModel(GL_SMOOTH);
    108103
    109   if (this->diffuseTextureSet)
     104  if (this->diffuseTexture)
    110105    {
    111106      glEnable(GL_TEXTURE_2D);
     
    300295{
    301296  PRINTF(4)("setting Diffuse Map %s\n", dMap);
    302   //    diffuseTexture = new Texture();
    303   //    this->diffuseTextureSet = diffuseTexture->loadImage(dMap);
    304297
    305298  //! \todo check if RESOURCE MANAGER is availiable
    306299  //! \todo Textures from .mtl-file need special care.
    307   this->diffuseTextureSet = this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE);
     300  this->diffuseTexture = (Texture*)ResourceManager::getInstance()->load(dMap, IMAGE);
    308301}
    309302
  • orxonox/branches/md2_loader/src/lib/graphics/importer/material.h

    r3914 r4139  
    6767  Texture* ambientTexture; //!< The ambient texture of the Material.
    6868  Texture* specularTexture;//!< The specular texture of the Material.
    69  
    70   bool diffuseTextureSet; //!< Chekcs if the diffuse texture is Set.
    71   bool ambientTextureSet; //!< Chekcs if the ambient texture is Set.
    72   bool specularTextureSet;//!< Chekcs if the specular texture is Set.
    73 
    7469};
    7570#endif
  • orxonox/branches/md2_loader/src/lib/graphics/importer/model.cc

    r4063 r4139  
    3636ModelFaceElement::ModelFaceElement()
    3737{
     38  this->vertexNumber = -1;
     39  this->normalNumber = -1;
     40  this->texCoordNumber = -1;   
     41
    3842  this->next = NULL;
    3943}
     
    140144  this->currentGroup = this->firstGroup = new ModelGroup;
    141145  this->groupCount = 0;
     146  this->vertexCount = 0;
     147  this->normalCount = 0;
     148  this->texCoordCount = 0;
    142149 
    143150  this->scaleFactor = 1;
     
    355362Material* Model::addMaterial(const char* materialName)
    356363{
    357  
    358364  Material* newMat = new Material();
    359365  newMat->setName(materialName);
     
    424430  PRINTF(5)("reading in a vertex: %f %f %f\n", &subbuffer1, &subbuffer2, &subbuffer3);
    425431  this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor);
     432  this->vertexCount++;
    426433  return true;
    427434}
     
    438445  PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z);
    439446  this->vertices->addEntry(x*scaleFactor, y*scaleFactor, z*scaleFactor);
     447  this->vertexCount++;
    440448  return true;
    441449}
     
    455463  PRINTF(5)("found vertex-Normal %f, %f, %f\n", &subbuffer1,&subbuffer2,&subbuffer3);
    456464  this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3);
     465  this->normalCount++;
    457466  return true;
    458467}
     
    470479  PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z);
    471480  this->normals->addEntry(x, y, z);
     481  this->normalCount++;
     482  return true;
    472483}
    473484
     
    487498  this->vTexture->addEntry(subbuffer1);
    488499  this->vTexture->addEntry(subbuffer2);
     500  this->texCoordCount++;
    489501  return true;
    490502}
     
    502514  this->vTexture->addEntry(u);
    503515  this->vTexture->addEntry(v);
     516  this->texCoordCount++;
     517  return true;
    504518}
    505519
     
    509523
    510524   If a face line is found this function will add it to the glList.
     525
     526   String is different from the argument addFace, in this that the first Vertex/Normal/Texcoord is 1 instead of 0
    511527*/
    512528bool Model::addFace (const char* faceString)
     
    546562      if (vertex)
    547563        tmpElem->vertexNumber = atoi(vertex)-1;
    548       else
    549         tmpElem->vertexNumber = -1;
    550564      if (texture)
    551565        tmpElem->texCoordNumber = atoi(texture)-1;
    552       else
    553         tmpElem->texCoordNumber = -1;
    554566      if (normal)
    555567        tmpElem->normalNumber = atoi(normal)-1;
    556       else
    557         tmpElem->normalNumber = -1;
    558568
    559569      faceString += tmpLen;
     
    569579   \brief adds a new Face
    570580   \param faceElemCount the number of Vertices to add to the Face.
    571    \param type 0: vertex only, 1: vertex and normal, 2: vertex and Texture, 3 vertex, normal and texture
     581   \param type The information Passed with each Vertex
    572582*/
    573583bool Model::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
     
    583593  for (int i = 0; i < faceElemCount; i++)
    584594    {
    585       if (this->currentGroup->currentFace->vertexCount>0)
     595      if (this->currentGroup->currentFace->vertexCount > 0)
    586596        tmpElem = tmpElem->next = new ModelFaceElement;
    587597
    588       tmpElem->vertexNumber = va_arg (itemlist, int) -1;
     598      tmpElem->vertexNumber = va_arg (itemlist, int);
    589599      if (type & TEXCOORD)
    590         tmpElem->texCoordNumber = va_arg (itemlist, int) -1;
     600        tmpElem->texCoordNumber = va_arg (itemlist, int);
    591601      if (type & NORMAL)
    592         tmpElem->normalNumber = va_arg(itemlist, int) -1;
     602        tmpElem->normalNumber = va_arg(itemlist, int);
    593603      this->currentGroup->currentFace->vertexCount++;
    594604    }
     
    693703    }
    694704
    695   for (int i=0; i<vertices->getCount()/3;i++)
     705  for (int i=0; i < vertices->getCount()/3;i++)
    696706    {
    697707      normArray[i].normalize();
    698708      PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
    699709     
    700       this->normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z);
     710      this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z);
    701711
    702712    }
     
    834844
    835845  if (elem->texCoordNumber != -1)
    836     glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2);
     846    {
     847      if (likely(elem->texCoordNumber < this->texCoordCount))
     848        glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2);
     849      else
     850        PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",
     851                  elem->texCoordNumber, this->texCoordCount);
     852    }
    837853  if (elem->normalNumber != -1)
    838     glNormal3fv(this->normals->getArray() + elem->normalNumber * 3);
     854    {
     855    if (likely(elem->normalNumber < this->normalCount))
     856      glNormal3fv(this->normals->getArray() + elem->normalNumber * 3);
     857    else
     858        PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",
     859                  elem->normalNumber, this->normalCount);     
     860    }
    839861  if (elem->vertexNumber != -1)
    840     glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3);
     862    {
     863      if (likely(elem->vertexNumber < this->vertexCount))
     864          glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3);
     865      else
     866        PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",
     867                  elem->vertexNumber, this->vertexCount);     
     868    }   
     869
    841870}
    842871
     
    897926  this->addVertexNormal (-1.0, 0.0, 0.0);
    898927
    899   /* normaleLess-testingMode
    900   this->addFace ("1 2 4 3");
    901   this->addFace ("3 4 6 5");
    902   this->addFace ("5 6 8 7");
    903   this->addFace ("7 8 2 1");
    904   this->addFace ("2 8 6 4");
    905   this->addFace ("7 1 3 5");
    906   */
    907 
    908   this->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,1, 2,2,2, 4,4,3, 3,3,4);
    909   this->addFace (4, VERTEX_TEXCOORD_NORMAL, 3,3,5, 4,4,6, 6,6,7, 5,5,8);
    910   this->addFace (4, VERTEX_TEXCOORD_NORMAL, 5,5,9, 6,6,10, 8,8,11, 7,7,12);
    911   this->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,7,13, 8,8,14, 2,10,15, 1,9,16);
    912   this->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,2,17, 8,11,18, 6,12,19, 4,4,20);
    913   this->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,13,21, 1,1,22, 3,3,23, 5,14,24);
    914 
    915 }
     928  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,1, 3,3,2, 2,2,3);
     929  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,2,4, 3,3,5, 5,5,6, 4,4,7);
     930  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,4,8, 5,5,9, 7,7,10, 6,6,11);
     931  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,6,12, 7,7,13, 1,9,14, 0,8,15);
     932  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,16, 7,10,17, 5,11,18, 3,3,19);
     933  this->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,12,20, 0,0,21, 2,2,22, 4,13,23);
     934
     935}
  • orxonox/branches/md2_loader/src/lib/graphics/importer/model.h

    r4065 r4139  
    100100  bool finalized;             //!< Sets the Object to be finalized.
    101101
     102  int vertexCount;            //!< A modelwide Counter for vertices.
     103  int normalCount;            //!< A modelwide Counter for the normals.
     104  int texCoordCount;          //!< A modelwide Counter for the texCoord.
    102105  Array* vertices;            //!< The Array that handles the Vertices.
    103   int verticesCount;          //!< A global Counter for vertices.
    104106  Array* normals;             //!< The Array that handles the Normals.
    105107  Array* vTexture;            //!< The Array that handles the VertexTextureCoordinates.
     
    159161  bool setMaterial(Material* mtl);
    160162  void finalize(void);
     163
     164  /** \returns The number of Vertices of the Model */
     165  inline int getVertexCount(void) const {return this->vertexCount;}
     166  /** \returns The number of Normals of the Model */
     167  inline int getNormalCount(void) const {return this->normalCount;}
     168  /** \returns The number of Texture Coordinates of the Model*/
     169  inline int getTexCoordCount(void) const {return this->texCoordCount;}
    161170};
    162171
  • orxonox/branches/md2_loader/src/lib/graphics/importer/objModel.cc

    r4063 r4139  
    3434OBJModel::OBJModel(const char* fileName, float scaling) : Model(fileName)
    3535{
    36   this->initializeOBJ();
     36  this->objPath = "./";
     37
    3738  this->scaleFactor = scaling;
    3839
     
    5253  if (this->objPath)
    5354    delete []this->objPath;
    54   if (this->objFileName)
    55     delete []this->objFileName;
    56   if (this->mtlFileName)
    57     delete []this->mtlFileName;
    58 }
    59 
    60 /**
    61    \brief Initializes an obj-model
    62 */
    63 void OBJModel::initializeOBJ(void)
    64 {
    65   this->objPath = NULL;
    66   this->objFileName = NULL;
    67   this->mtlFileName = NULL;
    6855}
    6956
     
    7158   \brief Imports a obj file and handles the the relative location
    7259   \param fileName The file to import
     60
     61   Splits the FileName from the DirectoryName
    7362*/
    7463bool OBJModel::importFile (const char* fileName)
    7564{
    7665  PRINTF(4)("preparing to read in file: %s\n", fileName);
    77 
    78 
    79 #ifdef __WIN32__
    80   // win32 path reading
    81   char pathSplitter= '\\';
    82 #else /* __WIN32__ */
    83   // unix path reading
    84   char pathSplitter='/';
    85 #endif /* __WIN32__ */
    86   char* tmpName;
    87   strcpy(tmpName, fileName);
    88   if (tmpName[0] == pathSplitter)
    89     tmpName++;
    90   char* name = tmpName;
    91   while (( tmpName = strchr (tmpName+1, pathSplitter)))
    92     {
    93       name = tmpName+1;
    94     }
    95   this->objPath = new char[name-fileName+1];
    96   strncpy(this->objPath, fileName, name-fileName);
    97   this->objPath[name-fileName] = '\0';
    98   if (strlen(objPath)> 0)
    99     PRINTF(5)("Resolved file %s to folder: %s.\n", name, objPath);
    100   else
    101     PRINTF(5)("Resolved file %s.\n", name);
    102  
    103   this->setName(name);
    104 
    105   this->objFileName = new char[strlen(name)+1];
    106   strcpy (this->objFileName, name);
    107   this->readFromObjFile ();
     66  // splitting the
     67  char* split = NULL;
     68
     69  if (!(split = strrchr(fileName, '/')))
     70    split = strrchr(fileName, '\\'); // windows Case
     71  if (split)
     72    {
     73      int len = split - fileName+1;
     74      this->objPath = new char[len +2];
     75      strncpy(this->objPath, fileName, len);
     76      this->objPath[len] = '\0';
     77      PRINTF(1)("Resolved file %s to Path %s.\n", fileName, this->objPath);
     78    }
     79  this->readFromObjFile (fileName);
    10880  return true;
    10981}
     
    11385   This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks
    11486*/
    115 bool OBJModel::readFromObjFile (void)
    116 {
    117   char* fileName = new char [strlen(objPath)+strlen(objFileName)+1];
    118   if (this->objFileName != NULL && !strcmp(this->objFileName, ""))
    119     return false;
    120   strcpy(fileName, this->objPath);
    121   strcat(fileName, this->objFileName);
    122 
     87bool OBJModel::readFromObjFile(const char* fileName)
     88{
    12389  FILE* stream;
    12490  if( (stream = fopen (fileName, "r")) == NULL)
    12591    {
    126       printf("IniParser could not open %s\n", fileName);
     92      printf("Object File Could not be Opened %s\n", fileName);
    12793      return false;
    12894    }
     
    179145    }
    180146  fclose (stream);
    181   delete []fileName;
    182147  return true;
    183148}
     
    194159bool OBJModel::readMtlLib (const char* mtlFile)
    195160{
    196   this->mtlFileName = new char [strlen(mtlFile)+1];
    197   strcpy(this->mtlFileName, mtlFile);
    198   char* fileName = new char [strlen(this->objPath) + strlen(this->mtlFileName)+1];
    199   sprintf(fileName, "%s%s", this->objPath, this->mtlFileName);
    200  
     161  char* fileName = new char [strlen(this->objPath) + strlen(mtlFile)+1];
     162  sprintf(fileName, "%s%s", this->objPath, mtlFile);
    201163
    202164  FILE* stream;
    203165  if( (stream = fopen (fileName, "r")) == NULL)
    204166    {
    205       printf("IniParser could not open %s\n", fileName);
     167      PRINTF(2)("MaterialLibrary could not be opened %s\n", fileName);
     168      delete []fileName;
    206169      return false;
    207170    }
  • orxonox/branches/md2_loader/src/lib/graphics/importer/objModel.h

    r3916 r4139  
    1515  OBJModel(const char* fileName, float scaling = 1.0);
    1616  virtual ~OBJModel();
    17   void initializeOBJ(void);
    1817
    1918 private:
    2019  // Variables
    2120  char* objPath;        //!< The Path where the obj and mtl-file are located.
    22   char* objFileName;    //!< The Name of the obj-file.
    23   char* mtlFileName;    //!< The Name of the mtl-file (parsed out of the obj-file)
    2421
    2522  ///// readin /////
    2623  bool importFile (const char* fileName);
    27   bool readFromObjFile (void);
     24  bool readFromObjFile (const char* fileName);
    2825  bool readMtlLib (const char* matFile);
    2926};
  • orxonox/branches/md2_loader/src/lib/graphics/importer/primitive_model.cc

    r3911 r4139  
    7171void PrimitiveModel::sphereModel(float size, unsigned int detail)
    7272{
    73   int vertexCount = 0;
    7473  if (detail <= 0)
    7574    detail = 1;
     
    8988                          size * sin(vi) * cos(vj));
    9089          this->addVertexTexture(i / (df *2.0), (j-1.0)/(df)+.5);
    91           vertexCount++;
    9290        }
    9391    }
    9492  this->addVertex(0, -size, 0);
     93  this->addVertexTexture(0,0);
    9594  this->addVertex(0, size, 0);
     95  this->addVertexTexture(0 ,1);
    9696
    9797  // defining the binding Faces.
     
    102102        {
    103103         
    104           v1 = i*detail + j;
    105           v4 = i*detail + (j+1);
     104          v1 = i*detail + j-1;
     105          v4 = i*detail + j;
    106106         
    107107          if (i == detail*2 -1)
    108108            {
    109               v2 = j;
    110               v3 = j+1;
     109              v2 = j-1;
     110              v3 = j;
    111111            }
    112112          else
    113113            {
    114               v2 = (i+1)*detail + j;
    115               v3 = (i+1)*detail + (j+1);
    116             }
    117          
     114              v2 = (i+1)*detail + j-1;
     115              v3 = (i+1)*detail + j;
     116            }
     117
    118118          if (j == 0)
    119119            {
    120               v1 = vertexCount+1;
     120              v1 = this->getVertexCount()-2;
    121121              this->addFace(3, VERTEX_TEXCOORD, v1, v1, v3, v3, v4, v4);
    122122            }
    123123          else if (j == detail)
    124124            {
    125               v3 = vertexCount+2;
     125              v3 = this->getVertexCount()-1;
    126126              this->addFace(3, VERTEX_TEXCOORD, v1, v1, v2, v2, v3, v3);
    127127            }
     
    157157    {
    158158      int p1, p2, p3, p4;
    159       p1 = 2*i+1;
    160       p2 = 2*i+2;
    161       p3 = 2*i+4;
    162       p4 = 2*i+3;
     159      p1 = 2*i;
     160      p2 = 2*i+1;
     161      p3 = 2*i+3;
     162      p4 = 2*i+2;
    163163      // something is wrong here
    164164      this->addFace(4, VERTEX_ONLY, p1, p2, p3, p4);
    165       this->addFace(3, VERTEX_ONLY, p4, p1, 2*detail+1);
    166       this->addFace(3, VERTEX_ONLY, p2, p3, 2*detail+2);
     165      this->addFace(3, VERTEX_ONLY, p4, p1, 2*detail);
     166      this->addFace(3, VERTEX_ONLY, p2, p3, 2*detail+1);
    167167    }
    168168  // caps
    169   this->addFace(4, VERTEX_ONLY, 2*detail-1, 2*detail, 2, 1);
    170   this->addFace(3, VERTEX_ONLY, 1, 2*detail-1, 2*detail+1);
    171   this->addFace(3, VERTEX_ONLY, 2*detail, 2, 2*detail+2);
     169  this->addFace(4, VERTEX_ONLY, 2*detail-2, 2*detail-1, 1, 0);
     170  this->addFace(3, VERTEX_ONLY, 0, 2*detail-2, 2*detail);
     171  this->addFace(3, VERTEX_ONLY, 2*detail-1, 1, 2*detail+1);
    172172}
    173173
     
    198198    {
    199199      unsigned int v1, v2;
    200       v1 = i+3;
     200      v1 = i+2;
    201201      if (i == detail -1)
    202         v2 = 3;
     202        v2 = 2;
    203203      else
    204         v2 = i+4;
    205       this->addFace(3, VERTEX_ONLY, 1, v1, v2);
    206       this->addFace(3, VERTEX_ONLY, 2, v1, v2);
     204        v2 = i+3;
     205      this->addFace(3, VERTEX_ONLY, 0, v1, v2);
     206      this->addFace(3, VERTEX_ONLY, 1, v1, v2);
    207207    }
    208208}
     
    228228  unsigned int v1, v2, v3, v4;
    229229  for (int i = 0; i < detail-1; i++)
    230     for (int j = 1; j < detail; j++)
     230    for (int j = 0; j < detail-1; j++)
    231231      {
    232232        v1 = i*detail + j;
  • orxonox/branches/md2_loader/src/lib/graphics/particles/particle_system.cc

    r4017 r4139  
    4040   this->particleType = type;
    4141   this->particles = NULL;
     42   this->deadList = NULL;
    4243   this->setConserve(.8);
    4344   this->setLifeSpan(.1);
     
    5758  // delete what has to be deleted here
    5859   ParticleEngine::getInstance()->removeSystem(this);
     60
     61   // deleting all the living Particles
     62   while (this->particles)
     63     {
     64       Particle* tmpDelPart = this->particles;
     65       this->particles = this->particles->next;
     66       delete tmpDelPart;
     67     }
     68
     69   // deleting all the dead particles
     70   while (this->deadList)
     71     {
     72       Particle* tmpDelPart = this->deadList;
     73       this->deadList = this->deadList->next;
     74       delete tmpDelPart;
     75     }
    5976}
    6077
     
    199216            {
    200217              prevPart->next = tickPart->next;
    201               delete tickPart;
     218              tickPart->next = this->deadList;
     219              this->deadList = tickPart;
    202220              tickPart = prevPart->next;
    203221            }
     
    206224              prevPart = NULL;
    207225              this->particles = tickPart->next;
    208               delete tickPart;
     226              tickPart->next = this->deadList;
     227              this->deadList = tickPart;
    209228              tickPart = this->particles;
    210229            }
     
    266285      if (unlikely(particles == NULL))
    267286        {
    268           this->particles = new Particle;
     287          if (likely(deadList != NULL))
     288            {
     289              this->particles = this->deadList;
     290              deadList = deadList->next;
     291            }
     292          else
     293            this->particles = new Particle;
    269294          this->particles->next = NULL;
    270295        }
     
    272297      else
    273298        {
    274           Particle* tmpPart = new Particle;
     299          Particle* tmpPart;
     300          if (likely(deadList != NULL))
     301            {
     302              tmpPart = this->deadList;
     303              deadList = deadList->next;
     304            }
     305          else
     306            tmpPart = new Particle;
    275307          tmpPart->next = this->particles;
    276308          this->particles = tmpPart;
     
    300332  PRINT(0)("  ParticleSystem %s\n", this->name);
    301333  PRINT(0)("  ParticleCount: %d, maximumCount: %d :: filled %d%%\n", this->count, this->maxCount, 100*this->count/this->maxCount);
    302 }
     334  if (deadList)
     335    {
     336      PRINT(0)("  - ParticleDeadList is used: ");
     337      int i = 1;
     338      Particle* tmpPart = this->deadList;
     339      while (tmpPart = tmpPart->next) ++i;
     340      PRINT(0)("count: %d\n", i);
     341    }
     342}
  • orxonox/branches/md2_loader/src/lib/graphics/particles/particle_system.h

    r4017 r4139  
    9292  Material* material;        //!< A Material for all the Particles.
    9393  Particle* particles;       //!< A list of particles of this System.
     94  Particle* deadList;        //!< A list of dead Particles in the System.
    9495
    9596  GLuint* glID;              //!< A List of different gl-List-ID's
Note: See TracChangeset for help on using the changeset viewer.