Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2810 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
Nov 11, 2004, 2:41:03 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/importer: merged the new importer into the source

Location:
orxonox/branches/importer/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/importer/src/array.cc

    r2795 r2810  
    33Array::Array ()
    44{
    5   createArray (2000);
    6 }
    7 Array::Array (unsigned int arraySize)
    8 {
    9   createArray (arraySize);
     5  createArray ();
    106}
    117
    12 void Array::createArray (unsigned int newArraySize)
     8void Array::createArray ()
    139{
    14   array = new GLfloat [newArraySize];
    15   entryCount = -1; //0 means one entry
    16   arraySize = newArraySize;
     10  if (verbose >= 2)
     11    printf ("crating new Array\n");
     12  firstEntry = new Entry;
     13  firstEntry->next =NULL;
     14  currentEntry=firstEntry;
     15  finalized = false;
     16  entryCount = 0; //0 means one entry
    1717  return;
    1818}
    1919
    20 void Array::resizeArray (unsigned int newSize)
    21 {
    22   GLfloat* newArray = new GLfloat [newSize];
    23  
    24   for (int i=0; i<=entryCount; i++)
    25       newArray[i] = array[i];
    26 
    27   delete [] array;
    28   array = newArray;
    29   arraySize = newSize;
    30 
    31   return;
    32 }
    33  
    3420void Array::finalizeArray (void)
    3521{
    36   resizeArray (entryCount+1);
     22  if (verbose >= 3)
     23    printf ("Finalizing array.\n"); 
     24  if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL)
     25    printf ("could not allocate %i data Blocks\n", entryCount);
     26  Entry* walker = firstEntry;
     27  for (int i=0; i<entryCount; i++)
     28    {
     29      array[i] = walker->value;
     30      walker = walker->next;
     31    }
     32  finalized = true;
    3733  return;
    3834}
     
    4137void Array::addEntry (GLfloat entry)
    4238{
    43   entryCount++;
    44 
    45   if (entryCount > arraySize)
    46     resizeArray(arraySize+2000);
    47  
    48   array[entryCount] = entry;
    49 
     39  if (!finalized)
     40    {
     41      if (verbose >= 3)
     42        printf ("adding new Entry to Array: %f\n", entry);
     43     
     44      entryCount++;
     45      currentEntry->value = entry;
     46      currentEntry->next = new Entry;
     47      currentEntry = currentEntry->next;
     48      currentEntry->next = NULL;
     49    }
     50  else
     51    if (verbose >= 1)
     52      printf ("adding failed, because list has been finalized\n");
    5053}
    5154
     
    7275void Array::debug ()
    7376{
    74   printf ("arraySize=%i, entryCount=%i, address=%p\n", arraySize, entryCount, array);
     77  printf ("entryCount=%i, address=%p\n", entryCount, array);
    7578}
  • orxonox/branches/importer/src/array.h

    r2795 r2810  
    11#ifndef _ARRAY_H
    22#define _ARRAY_H
     3
     4extern int verbose;
    35
    46#include <GL/gl.h>
     
    911 public:
    1012  Array ();
    11   Array (unsigned int arraySize);
    1213
    13   void createArray (unsigned int newArraySize);
    14   void resizeArray (unsigned int newSize);
     14  void createArray ();
    1515  void finalizeArray (void);
    1616  void addEntry (GLfloat entry);
     
    2121  void debug(void);
    2222 private:
     23  struct Entry
     24  {
     25    GLfloat value;
     26    Entry* next;
     27  };
     28
    2329  GLfloat* array;
    24   unsigned int arraySize;
    25   unsigned int entryCount;
    26 
     30  int entryCount;
     31  bool finalized;
     32  Entry* firstEntry;
     33  Entry* currentEntry;
     34 
     35 
    2736};
    2837
  • orxonox/branches/importer/src/material.cc

    r2795 r2810  
    1717Material* Material::addMaterial(char* mtlName)
    1818{
     19  if (verbose >=2)
     20    printf ("adding Material %s\n", mtlName);
    1921  Material* newMat = new Material(mtlName);
    2022  Material* tmpMat = this;
     
    3032void Material::init(void)
    3133{
     34  if (verbose >= 3)
     35    printf ("initializing new Material\n");
    3236  nextMat = NULL;
    3337
     
    4246void Material::setName (char* mtlName)
    4347{
     48  if (verbose >= 3)
     49    printf("setting Material Name to %s", mtlName);
    4450  strcpy(name, mtlName);
    4551  //  printf ("adding new Material: %s, %p\n", this->getName(), this);
     
    5460void Material::setIllum (int illum)
    5561{
     62  if (verbose >= 3)
     63    printf("setting illumModel of Material %s to %i", name, illum);
    5664  illumModel = illum;
    5765  //  printf ("setting illumModel to: %i\n", illumModel);
     
    6472void Material::setDiffuse (float r, float g, float b)
    6573{
     74  if (verbose >= 3)
     75    printf ("setting Diffuse Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b);
    6676  diffuse[0] = r;
    6777  diffuse[1] = g;
     
    6979  diffuse[3] = 1.0;
    7080
    71   //  printf ("setting Diffuse Color to r=%f g=%f b=%f\n", r, g, b);
    7281}
    7382void Material::setDiffuse (char* rgb)
     
    8089void Material::setAmbient (float r, float g, float b)
    8190{
     91  if (verbose >=3)
     92    printf ("setting Ambient Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b);
    8293  ambient[0] = r;
    8394  ambient[1] = g;
    8495  ambient[2] = b;
    8596  ambient[3] = 1.0;
    86   //  printf ("setting Ambient Color to r=%f g=%f b=%f\n", r, g, b);
    8797}
    8898void Material::setAmbient (char* rgb)
     
    95105void Material::setSpecular (float r, float g, float b)
    96106{
     107  if (verbose >= 3)
     108    printf ("setting Specular Color of Material %s to r=%f g=%f b=%f\n", name, r, g, b);
    97109  specular[0] = r;
    98110  specular[1] = g;
    99111  specular[2] = b;
    100112  specular[3] = 1.0;
    101   //printf ("setting Specular Color to r=%f g=%f b=%f\n", r, g, b);
    102 }
     113 }
    103114void Material::setSpecular (char* rgb)
    104115{
     
    111122void Material::setTransparency (float trans)
    112123{
     124  if (verbose >= 3)
     125    printf ("setting Transparency of Material %s to %f\n", name, trans);
    113126  transparency = trans;
    114127}
     
    123136Material* Material::search (char* mtlName)
    124137{
     138  if (verbose >=3)
     139    printf ("Searching for material %s", mtlName);
    125140  Material* searcher = this;
    126141  while (searcher != NULL)
    127142    {
     143      if (verbose >= 3)
     144        printf (".");
    128145      if (!strcmp (searcher->getName(), mtlName))
    129         return searcher;
     146        {
     147          if (verbose >= 3)
     148            printf ("found.\n");
     149          return searcher;
     150        }
    130151      searcher = searcher->nextMat;
    131152    }
  • orxonox/branches/importer/src/material.h

    r2795 r2810  
    11#ifndef _MATERIAL_H
    22#define _MATERIAL_H
     3
     4extern int verbose;
     5
    36#include <GL/gl.h>
    47#include <GL/glu.h>
  • orxonox/branches/importer/src/object.cc

    r2795 r2810  
    11#include "object.h"
    22
     3int verbose = 1;
    34Object::Object ()
    45{
     
    2223bool Object::importFile (char* fileName)
    2324{
    24   objFile = fileName;
    25   this->readFromObjFile (objFile);
     25  if (verbose >=3)
     26    printf("preparing to read in file: %s\n", fileName);   
     27  objFileName = fileName;
     28  this->readFromObjFile (objFileName);
    2629  return true;
    2730}
     
    2932bool Object::initialize (void)
    3033{
     34  if (verbose >=3)
     35    printf("new 3D-Object is being created\n");
    3136  faceMode = -1;
    3237  if ( (listNumber = glGenLists(1)) == 0 )
     
    4550bool Object::finalize(void)
    4651{
     52  if (verbose >=3)
     53    printf("finalizing the 3D-Object\n");
    4754  glEndList();
    4855  return true;
     
    5158void Object::draw (void)
    5259{
     60  if (verbose >=3)
     61    printf("drawing the 3D-Object\n");
    5362  glCallList (listNumber);
    5463}
     
    6069  if (!OBJ_FILE->is_open())
    6170    {
    62       printf ("unable to open file: %s\n", fileName);
     71      if (verbose >=1)
     72        printf ("unable to open .OBJ file: %s\n", fileName);
    6373      return false;
    6474    }
    65  
     75  objFileName = fileName;
    6676  char Buffer[500];
    6777  vertices = new Array();
     
    7080    {
    7181      OBJ_FILE->getline(Buffer, 500);
    72       //      printf("%s\n", Buffer);
     82      if (verbose >=4)
     83        printf ("Read input line: %s\n",Buffer);
    7384     
    7485
     
    125136  char subbuffer3[20];
    126137  sscanf (vertexString, "%s %s %s", subbuffer1, subbuffer2, subbuffer3);
     138  if (verbose >= 3)
     139    printf ("reading in a vertex: %s %s %s\n", subbuffer1, subbuffer2, subbuffer3);
    127140  vertices->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3));
    128141  return true;
     
    145158  char subbuffer4[20] ="";
    146159  sscanf (faceString, "%s %s %s %s", subbuffer1, subbuffer2, subbuffer3, subbuffer4);
    147   //  printf("%s, %s, %s\n", subbuffer1,subbuffer2,subbuffer3);
    148160  if (!strcmp(subbuffer4, ""))
    149161    {
     
    156168     
    157169      faceMode = 3;
    158       //printf ("triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3);
     170      if (verbose >=3)
     171        printf ("found triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3);
    159172      addGLElement(subbuffer1);
    160173      addGLElement(subbuffer2);
     
    171184        }
    172185      faceMode = 4;
    173       //      printf ("quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4);
     186      if (verbose >=3 )
     187        printf ("found quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4);
    174188      addGLElement(subbuffer1);
    175189      addGLElement(subbuffer2);
     
    191205  normal[0] = '\0';
    192206  normal ++;
    193  
     207  if (verbose >= 4)
     208    printf ("importing grafical Element.... including to openGL\n");
    194209  glNormal3fv(normals->getArray() +(atoi(normal)-1)*3);
    195210  glArrayElement(atoi(vertex)-1); //  glVertex3fv(vertices->getArray() +(atoi(vertex)-1)*3);
     
    204219  char subbuffer3[20];
    205220  sscanf (normalString, "%s %s %s", subbuffer1, subbuffer2, subbuffer3);
    206   //  printf("%s, %s, %s\n", subbuffer1,subbuffer2,subbuffer3);
     221  if (verbose >=3 )
     222    printf("found vertex-Normal %s, %s, %s\n", subbuffer1,subbuffer2,subbuffer3);
    207223  normals->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3));
    208224  return true;
     
    214230  if (!MTL_FILE->is_open())
    215231    {
    216       printf ("unable to open file: %s\n", mtlFile);
     232      if (verbose >= 1)
     233        printf ("unable to open file: %s\n", mtlFile);
    217234      return false;
    218235    }
    219  
     236  mtlFileName = mtlFile;
     237  if (verbose >=2)
     238    printf ("Opening mtlFile: %s\n", mtlFileName);
    220239  char Buffer[500];
    221240  vertices = new Array();
     
    225244    {
    226245      MTL_FILE->getline(Buffer, 500);
    227       //      printf("%s\n", Buffer);
     246      if (verbose >= 4)
     247        printf("found line in mtlFile: %s\n", Buffer);
    228248     
    229249
     
    264284    glEnd();
    265285  faceMode = 0;
    266   //printf ("%s\n", matString);
    267   //  glColor3f((float)rand()/2000000000.0,(float)rand()/2000000000.0,(float)rand()/2000000000.0);
     286  if (verbose >= 2)
     287    printf ("using material %s for coming Faces.\n", matString);
    268288  material->search(matString)->select();
    269289}
  • orxonox/branches/importer/src/object.h

    r2795 r2810  
    3030  Array* colors;
    3131  Array* normals;
    32   char* objFile;
     32  char* objFileName;
     33  char* mtlFileName;
    3334  int faceMode;
    3435  bool readVertices;
Note: See TracChangeset for help on using the changeset viewer.