Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3430 in orxonox.OLD for orxonox/branches/trackManager/src/importer


Ignore:
Timestamp:
Mar 1, 2005, 9:50:30 AM (20 years ago)
Author:
bensch
Message:

orxonox/branches/trackManager: merged trunk back to trackManager
merged with command
svn merge -r 3369:HEAD trunk/ branches/trackManager
resoloved conflicts in favor of the trunk.

Location:
orxonox/branches/trackManager
Files:
2 deleted
10 edited
2 copied

Legend:

Unmodified
Added
Removed
  • orxonox/branches/trackManager

    • Property svn:externals set to
  • orxonox/branches/trackManager/src/importer/Makefile.am

    r3369 r3430  
    99                  windowHandler.cc \
    1010                  model.cc \
     11                  objModel.cc \
    1112                  array.cc \
    1213                  material.cc \
    1314                  texture.cc \
    14                   vector.cc
     15                  ../vector.cc
    1516
    1617noinst_HEADERS= framework.h \
    1718                windowHandler.h \
    1819                model.h \
     20                objModel.h \
    1921                array.h \
    2022                material.h \
  • orxonox/branches/trackManager/src/importer/Makefile.in

    r3369 r3430  
    5454PROGRAMS = $(bin_PROGRAMS)
    5555am_importer_OBJECTS = framework.$(OBJEXT) windowHandler.$(OBJEXT) \
    56         model.$(OBJEXT) array.$(OBJEXT) material.$(OBJEXT) \
    57         texture.$(OBJEXT) vector.$(OBJEXT)
     56        model.$(OBJEXT) objModel.$(OBJEXT) array.$(OBJEXT) \
     57        material.$(OBJEXT) texture.$(OBJEXT) vector.$(OBJEXT)
    5858importer_OBJECTS = $(am_importer_OBJECTS)
    5959importer_LDADD = $(LDADD)
     
    6363@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/array.Po ./$(DEPDIR)/framework.Po \
    6464@AMDEP_TRUE@    ./$(DEPDIR)/material.Po ./$(DEPDIR)/model.Po \
    65 @AMDEP_TRUE@    ./$(DEPDIR)/texture.Po ./$(DEPDIR)/vector.Po \
    66 @AMDEP_TRUE@    ./$(DEPDIR)/windowHandler.Po
     65@AMDEP_TRUE@    ./$(DEPDIR)/objModel.Po ./$(DEPDIR)/texture.Po \
     66@AMDEP_TRUE@    ./$(DEPDIR)/vector.Po ./$(DEPDIR)/windowHandler.Po
    6767CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
    6868        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
     
    8989CPP = @CPP@
    9090CPPFLAGS = @CPPFLAGS@
     91CURL_CFLAGS = @CURL_CFLAGS@
     92CURL_LIBS = @CURL_LIBS@
    9193CXX = @CXX@
    9294CXXDEPMODE = @CXXDEPMODE@
     
    104106EGREP = @EGREP@
    105107EXEEXT = @EXEEXT@
     108GTHREAD_CFLAGS = @GTHREAD_CFLAGS@
     109GTHREAD_LIBS = @GTHREAD_LIBS@
    106110GTK2_CFLAGS = @GTK2_CFLAGS@
    107111GTK2_LIBS = @GTK2_LIBS@
     112HAVE_CURL_FALSE = @HAVE_CURL_FALSE@
     113HAVE_CURL_TRUE = @HAVE_CURL_TRUE@
     114HAVE_GTHREAD_FALSE = @HAVE_GTHREAD_FALSE@
     115HAVE_GTHREAD_TRUE = @HAVE_GTHREAD_TRUE@
    108116HAVE_GTK2_FALSE = @HAVE_GTK2_FALSE@
    109117HAVE_GTK2_TRUE = @HAVE_GTK2_TRUE@
     
    129137SHELL = @SHELL@
    130138STRIP = @STRIP@
     139SUB_PROJECTS_FALSE = @SUB_PROJECTS_FALSE@
     140SUB_PROJECTS_TRUE = @SUB_PROJECTS_TRUE@
    131141VERSION = @VERSION@
    132142ac_ct_CC = @ac_ct_CC@
     
    178188                  windowHandler.cc \
    179189                  model.cc \
     190                  objModel.cc \
    180191                  array.cc \
    181192                  material.cc \
    182193                  texture.cc \
    183                   vector.cc
     194                  ../vector.cc
    184195
    185196noinst_HEADERS = framework.h \
    186197                windowHandler.h \
    187198                model.h \
     199                objModel.h \
    188200                array.h \
    189201                material.h \
     
    260272@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/material.Po@am__quote@
    261273@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Po@am__quote@
     274@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/objModel.Po@am__quote@
    262275@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texture.Po@am__quote@
    263276@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@
     
    279292@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    280293@am__fastdepCXX_FALSE@  $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
     294
     295vector.o: ../vector.cc
     296@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT vector.o -MD -MP -MF "$(DEPDIR)/vector.Tpo" -c -o vector.o `test -f '../vector.cc' || echo '$(srcdir)/'`../vector.cc; \
     297@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/vector.Tpo" "$(DEPDIR)/vector.Po"; else rm -f "$(DEPDIR)/vector.Tpo"; exit 1; fi
     298@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='../vector.cc' object='vector.o' libtool=no @AMDEPBACKSLASH@
     299@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/vector.Po' tmpdepfile='$(DEPDIR)/vector.TPo' @AMDEPBACKSLASH@
     300@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     301@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vector.o `test -f '../vector.cc' || echo '$(srcdir)/'`../vector.cc
     302
     303vector.obj: ../vector.cc
     304@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT vector.obj -MD -MP -MF "$(DEPDIR)/vector.Tpo" -c -o vector.obj `if test -f '../vector.cc'; then $(CYGPATH_W) '../vector.cc'; else $(CYGPATH_W) '$(srcdir)/../vector.cc'; fi`; \
     305@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/vector.Tpo" "$(DEPDIR)/vector.Po"; else rm -f "$(DEPDIR)/vector.Tpo"; exit 1; fi
     306@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='../vector.cc' object='vector.obj' libtool=no @AMDEPBACKSLASH@
     307@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/vector.Po' tmpdepfile='$(DEPDIR)/vector.TPo' @AMDEPBACKSLASH@
     308@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     309@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vector.obj `if test -f '../vector.cc'; then $(CYGPATH_W) '../vector.cc'; else $(CYGPATH_W) '$(srcdir)/../vector.cc'; fi`
    281310uninstall-info-am:
    282311
  • orxonox/branches/trackManager/src/importer/array.h

    r3196 r3430  
    1212
    1313#include "../stdincl.h"
    14 #include <fstream>
    15 
    1614
    1715//! Array Class that handles dynamic-float arrays.
  • orxonox/branches/trackManager/src/importer/framework.cc

    r3369 r3430  
    1616#include "framework.h"
    1717
     18#include "../vector.h"
     19
     20int verbose;
    1821void DrawGLScene()
    1922{
     
    5255int main(int argc, char *argv[])
    5356{
    54   verbose = 2;
    55 
    56   PRINTF(2)("This is The big verbose-Test %i, %s\n", 1, "cool");
     57  verbose = 3;
    5758
    5859  Uint8* keys; // This variable will be used in the keyboard routine
     
    7172  PRINTF(2)("screensize: %i, %i\n", wHandler.screen->w, wHandler.screen->h);
    7273  if (argc>=3)
    73     obj = new Model (argv[1], atof(argv[2]));
     74    obj = new OBJModel (argv[1], atof(argv[2]));
    7475  else if (argc>=2)
    75     obj = new Model(argv[1]);
     76    obj = new OBJModel(argv[1]);
    7677  else
    77     obj = new Model();
    78  
     78    {
     79      // This is an example, of how it is possible, to create a new Model, and adding some vertex-information.
     80      // This also packs everything into a DisplayList, and can be handled exactly as any other model.
     81      // This is an example of a cube with Texture-Coordinates, but without explicite Vertex-Normals. (they are soft-created).
     82      /*
     83      obj = (OBJModel*) new Model();
     84      obj->setName("CUBE");
     85      obj->addVertex (-0.5, -0.5, 0.5);
     86      obj->addVertex (0.5, -0.5, 0.5);
     87      obj->addVertex (-0.5, 0.5, 0.5);
     88      obj->addVertex (0.5, 0.5, 0.5);
     89      obj->addVertex (-0.5, 0.5, -0.5);
     90      obj->addVertex (0.5, 0.5, -0.5);
     91      obj->addVertex (-0.5, -0.5, -0.5);
     92      obj->addVertex (0.5, -0.5, -0.5);
     93     
     94      obj->addVertexTexture (0.0, 0.0);
     95      obj->addVertexTexture (1.0, 0.0);
     96      obj->addVertexTexture (0.0, 1.0);
     97      obj->addVertexTexture (1.0, 1.0);
     98      obj->addVertexTexture (0.0, 2.0);
     99      obj->addVertexTexture (1.0, 2.0);
     100      obj->addVertexTexture (0.0, 3.0);
     101      obj->addVertexTexture (1.0, 3.0);
     102      obj->addVertexTexture (0.0, 4.0);
     103      obj->addVertexTexture (1.0, 4.0);
     104      obj->addVertexTexture (2.0, 0.0);
     105      obj->addVertexTexture (2.0, 1.0);
     106      obj->addVertexTexture (-1.0, 0.0);
     107      obj->addVertexTexture (-1.0, 1.0);
     108
     109      obj->addFace ("1 2 4 3");
     110      obj->addFace ("3 4 6 5");
     111      obj->addFace ("5 6 8 7");
     112      obj->addFace ("7 8 2 1");
     113      obj->addFace ("2 8 6 4");
     114      obj->addFace ("7 1 3 5");
     115      obj->finalize();
     116      */
     117      obj = (OBJModel*) new Model(CYLINDER);
     118    }
    79119  M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0);
    80120  rotAxis = Vector (0.0,1.0,0.0);
     
    215255          case SDLK_c:
    216256            if (!obj)
    217               obj = new Model(argv[1]);
     257              obj = new OBJModel(argv[1]);
    218258            break;
     259          case SDLK_a:
     260            zoomTo /=2;
     261            break;
     262          case SDLK_z:
     263            zoomTo *=2;
     264
    219265          }
    220266        break;
  • orxonox/branches/trackManager/src/importer/framework.h

    r3369 r3430  
    33 
    44#include "windowHandler.h" // Include the Whandler Basecode
    5 #include "model.h"
    6 #include "vector.h"
     5#include "objModel.h"
     6
     7class Vector;
    78
    89float rotatorP;
     
    3334
    3435WindowHandler wHandler;  // Create an instance of the whandler basecode class
    35 Model* obj;
     36OBJModel* obj;
    3637
    3738
  • orxonox/branches/trackManager/src/importer/material.cc

    r3369 r3430  
    1616
    1717#include "material.h"
     18
     19#include "texture.h"
     20#include <stdlib.h>
     21#include <string.h>
    1822
    1923using namespace std;
     
    112116  while (searcher != NULL)
    113117    {
    114       PRINTF(2)(".");
     118      PRINT(2)(".");
    115119      if (!strcmp (searcher->getName(), mtlName))
    116120        {
    117           PRINTF(2)("found.\n");
     121          PRINT(2)("found.\n");
    118122          return searcher;
    119123        }
    120124      searcher = searcher->nextMat;
    121125    }
    122   PRINTF(2)("not found\n");
     126  PRINT(2)("not found\n");
    123127  return NULL;
    124128}
  • orxonox/branches/trackManager/src/importer/material.h

    r3369 r3430  
    1313extern int verbose; //!< will be obsolete soon.
    1414
    15 #include "../stdincl.h"
    16 #include "texture.h"
    17 
    1815#if HAVE_CONFIG_H
    1916#include <config.h>
    2017#endif /* HAVE_CONFIG_H */
    2118
    22 
     19// FORWARD DEFINITIONS //
     20class Texture;
    2321
    2422
  • orxonox/branches/trackManager/src/importer/model.cc

    r3369 r3430  
    1515
    1616#include "model.h"
    17 int verbose = 1; //! \todo should be GLOBAL
     17
     18#include <math.h>
     19#include <stdarg.h>
     20
     21#include "array.h"
     22#include "../vector.h"
     23
    1824using namespace std;
    1925
    2026/**
    21    \brief Creates a 3D-Model, but does not load any 3D-models.
    22 
    23    This Constructor is pretty useless, because why load no model in an model-loader??
    24 */
    25 Model::Model ()
    26 {
    27 
     27   \brief Creates a 3D-Model.
     28
     29   This only initializes a 3D-Model, but does not cleanup the Faces.
     30*/
     31Model::Model(void)
     32{
    2833  this->initialize();
    29 
    30   this->BoxModel();
    31 
     34}
     35
     36/**
     37   \brief Creates a 3D-Model of Primitive-Type type
     38
     39   if you want to just display a Cube/Sphere/Cylinder/... without any material.
     40   
     41   \todo implement Cube/Sphere/Cylinder/...
     42*/
     43Model::Model(PRIMITIVE type)
     44{
     45  this->initialize();
     46
     47  switch (type)
     48    {
     49    default:
     50    case CUBE:
     51      this->cubeModel();
     52      break;
     53    case SPHERE:
     54      this->sphereModel();
     55      break;
     56    case CYLINDER:
     57      this->cylinderModel();
     58      break;
     59
     60    }
    3261  this->importToGL ();
    3362
     
    3665
    3766/**
    38    \brief Crates a 3D-Model and loads in a File.
    39    \param fileName file to parse and load (must be a .obj file)
    40 */
    41 Model::Model(char* fileName)
     67   \brief Creates a 3D-Model. and assigns it a Name.
     68*/
     69Model::Model(char* modelName)
    4270{
    4371  this->initialize();
    44 
    45   this->importFile (fileName);
    46 
    47   this->importToGL ();
    48 
    49   this->cleanup();
    50 }
    51 
    52 /**
    53    \brief Crates a 3D-Model, loads in a File and scales it.
    54    \param fileName file to parse and load (must be a .obj file)
    55    \param scaling The factor that the model will be scaled with.
    56 */
    57 Model::Model(char* fileName, float scaling)
    58 {
    59   this->initialize();
    60   this->scaleFactor = scaling;
    61 
    62   this->importFile (fileName);
    63 
    64   this->importToGL ();
    65 
    66   this->cleanup();
     72  this->setName(modelName);
    6773}
    6874
     
    7278   Looks if any from model allocated space is still in use, and if so deleted it.
    7379*/
    74 Model::~Model()
    75 {
    76   PRINTF(2)("Deleting display Lists.\n");
     80Model::~Model(void)
     81{
     82  PRINTF(3)("Deleting Model ");
     83  if (this->name)
     84    {
     85      PRINT(3)("%s\n", this->name);
     86      delete []this->name;
     87    }
     88  else
     89      PRINT(3)("\n");
     90
     91  PRINTF(3)("Deleting display Lists.\n");
    7792  Group* walker = this->firstGroup;
    7893  while (walker != NULL)
     
    8499    }
    85100
    86   if (this->objPath)
    87     delete []this->objPath;
    88   if (this->objFileName)
    89     delete []this->objFileName;
    90   if (this->mtlFileName)
    91     delete []this->mtlFileName;
    92   PRINTF(2)("Deleting Materials.\n");
     101  PRINTF(3)("Deleting Materials.\n");
    93102  if (this->material)
    94103    delete this->material;
    95104}
    96105
     106/**
     107   \brief Finalizes an Object. This can be done outside of the Class.
     108*/
     109void Model::finalize(void)
     110{
     111  this->importToGL ();
     112 
     113  this->cleanup();
     114
     115  this->finalized = true;
     116}
    97117
    98118/**
     
    139159      walker = walker->next;
    140160    }
    141   PRINTF(1)("Model number %i in %s not Found.\n", groupNumber, this->objFileName);
     161  PRINTF(1)("Model number %i in %s not Found.\n", groupNumber, this->name);
    142162  return;
    143163
     
    164184      walker = walker->next;
    165185    }
    166   PRINTF(1)("Model Named %s in %s not Found.\n", groupName, this->objFileName);
     186  PRINTF(1)("Model Named %s in %s not Found.\n", groupName, this->name);
    167187  return;
    168188}
     
    186206  PRINTF(2)("new 3D-Model is being created\n");
    187207
     208  this->name = NULL;
     209  this->finalized = false;
    188210  // setting the start group;
    189211  this->firstGroup = new Group;
     
    192214 
    193215  this->initGroup (this->currentGroup);
    194   this->objPath = NULL;
    195   this->objFileName = NULL;
    196   this->mtlFileName = NULL;
    197216  this->scaleFactor = 1;
    198217  this->material = new Material();
     
    205224}
    206225
     226void Model::setName(const char* name)
     227{
     228  if (this->name)
     229    delete this->name;
     230  this->name = new char[strlen(name)+1];
     231  strcpy(this->name, name);
     232}
    207233/**
    208234   \brief initializes a new Group model
     
    317343
    318344/**
    319    \brief Imports a obj file and handles the the relative location
    320    \param fileName The file to import
    321 */
    322 bool Model::importFile (char* fileName)
    323 {
    324   PRINTF(3)("preparing to read in file: %s\n", fileName);
    325 
    326 
    327 #ifdef __WIN32__
    328   // win32 path reading
    329   char pathSplitter= '\\';
    330 #else /* __WIN32__ */
    331   // unix path reading
    332   char pathSplitter='/';
    333 #endif /* __WIN32__ */
    334   char* tmpName = fileName;
    335   if (tmpName[0] == pathSplitter)
    336     tmpName++;
    337   char* name = tmpName;
    338   while (( tmpName = strchr (tmpName+1, pathSplitter)))
    339     {
    340       name = tmpName+1;
    341     }
    342   this->objPath = new char[name-fileName];
    343   strncpy(this->objPath, fileName, name-fileName);
    344   this->objPath[name-fileName] = '\0';
    345   if (verbose >=2)
    346     if (strlen(objPath)> 0)
    347       PRINTF(0)("Resolved file %s to folder: %s.\n", name, objPath);
    348     else
    349       PRINTF(0)("Resolved file %s.\n", name);
    350  
    351   if (this->material)
    352     this->material->addTexturePath(this->objPath);
    353   this->objFileName = new char[strlen(name)+1];
    354   strcpy (this->objFileName, name);
    355   this->readFromObjFile ();
    356   return true;
    357 }
    358 
    359 /**
    360    \brief Reads in the .obj File and sets all the Values.
    361    This function does read the file, parses it for the occurence of things like vertices, faces and so on, and executes the specific tasks
    362 */
    363 bool Model::readFromObjFile (void)
    364 {
    365   char* fileName = new char [strlen(objPath)+strlen(objFileName)+1];
    366   if (this->objFileName != NULL && !strcmp(this->objFileName, ""))
    367     return false;
    368   strcpy(fileName, this->objPath);
    369   strcat(fileName, this->objFileName);
    370 
    371   ifstream* OBJ_FILE = new ifstream(fileName);
    372   if (OBJ_FILE->fail())
    373     {
    374       PRINTF(1)("unable to open .OBJ file: %s\n Loading Box Model instead.\n", fileName);
    375       BoxModel();
    376       OBJ_FILE->close();
    377       delete []fileName;
    378       delete OBJ_FILE;
    379       return false;
    380     }
    381   PRINTF(2)("Reading from opened file %s\n", fileName);
    382   char Buffer[10000];
    383   while(!OBJ_FILE->eof())
    384     {
    385       OBJ_FILE->getline(Buffer, 10000);
    386       PRINTF(3)("Read input line: %s\n", Buffer);
    387      
    388 
    389       // case vertice
    390       if (!strncmp(Buffer, "v ", 2))
    391         {
    392           this->readVertex(Buffer+2);
    393         }
    394 
    395       // case face
    396       else if (!strncmp(Buffer, "f ", 2))
    397         {
    398           this->readFace (Buffer+2);
    399         }
    400      
    401       else if (!strncmp(Buffer, "mtllib ", 7))
    402         {
    403           this->readMtlLib (Buffer+7);
    404         }
    405 
    406       else if (!strncmp(Buffer, "usemtl ", 7))
    407         {
    408           this->readUseMtl (Buffer+7);
    409         }
    410 
    411       // case VertexNormal
    412       else if (!strncmp(Buffer, "vn ", 3))
    413         {
    414           this->readVertexNormal(Buffer+3);
    415         }
    416      
    417       // case VertexTextureCoordinate
    418       else if (!strncmp(Buffer, "vt ", 3))
    419         {
    420           this->readVertexTexture(Buffer+3);
    421         }
    422       // case group
    423       else if (!strncmp(Buffer, "g ", 2))
    424         {
    425           this->readGroup (Buffer+2);
    426         }
    427       else if (!strncmp(Buffer, "s ", 2)) //! \todo smoothing groups have to be implemented
    428         {
    429           if (verbose >= 2)
    430             PRINTF(2)("smoothing groups not supportet yet. line: %s\n", Buffer);
    431         }
    432     }
    433   OBJ_FILE->close();
    434   delete OBJ_FILE;
    435   delete []fileName;
    436   return true;
    437 
    438 }
    439 
    440 /**
    441345   \brief parses a group String
    442346   \param groupString the new Group to create
     
    445349   With it you should be able to import .obj-files with more than one Models inside.
    446350*/
    447 bool Model::readGroup (char* groupString)
     351bool Model::addGroup (char* groupString)
    448352{
    449353  PRINTF(3)("Read Group: %s.\n", groupString);
     
    470374   If a vertex line is found this function will inject it into the vertex-Array
    471375*/
    472 bool Model::readVertex (char* vertexString)
     376bool Model::addVertex (char* vertexString)
    473377{
    474378  float subbuffer1;
     
    482386
    483387/**
     388   \brief parses a vertex-String
     389   \param x the X-coordinate of the Vertex to add.
     390   \param y the Y-coordinate of the Vertex to add.
     391   \param z the Z-coordinate of the Vertex to add.
     392   
     393*/
     394bool Model::addVertex(const float x, const float y, const float z)
     395{
     396  PRINTF(4)("reading in a vertex: %f %f %f\n", x, y, z);
     397  this->vertices->addEntry(x*scaleFactor, y*scaleFactor, z*scaleFactor);
     398  return true;
     399}
     400
     401/**
    484402   \brief parses a face-string
    485403   \param faceString The String that will be parsed.
    486404
    487405   If a face line is found this function will add it to the glList.
    488    The function makes a difference between QUADS and TRIANGLES, and will if changed re-open, set and re-close the gl-processe.
    489 */
    490 bool Model::readFace (char* faceString)
     406*/
     407bool Model::addFace (char* faceString)
    491408{
    492409  if (this->currentGroup->faceCount >0)
     
    546463
    547464/**
     465   \brief adds a new Face
     466   \param faceElemCount the number of Vertices to add to the Face.
     467   \param type 0: vertex only, 1: vertex and normal, 2: vertex and Texture, 3 vertex, normal and texture
     468*/
     469bool Model::addFace(const float faceElemCount, int type, ...)
     470{
     471   if (this->currentGroup->faceCount > 0)
     472    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
     473  this->initFace (this->currentGroup->currentFace);
     474
     475  FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement;
     476  tmpElem->next = NULL;
     477 
     478  va_list itemlist;
     479  va_start (itemlist, type);
     480
     481  for (int i = 0; i < faceElemCount; i++)
     482    {
     483      if (this->currentGroup->currentFace->vertexCount>0)
     484          tmpElem = tmpElem->next = new FaceElement;
     485      tmpElem->next = NULL;
     486
     487      tmpElem->vertexNumber = va_arg (itemlist, int) -1;
     488      if (type >= 2)
     489        tmpElem->texCoordNumber = va_arg (itemlist, int) -1;
     490      if (type == 1 || type ==3)
     491        tmpElem->normalNumber = va_arg(itemlist, int) -1;
     492      this->currentGroup->currentFace->vertexCount++;
     493    }
     494  va_end(itemlist);
     495
     496  this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount - 2;
     497}
     498
     499/**
    548500   \brief parses a vertexNormal-String
    549501   \param normalString The String that will be parsed.
     
    551503   If a vertexNormal line is found this function will inject it into the vertexNormal-Array
    552504*/
    553 bool Model::readVertexNormal (char* normalString)
     505bool Model::addVertexNormal (char* normalString)
    554506{
    555507  float subbuffer1;
     
    563515
    564516/**
     517   \brief adds a VertexNormal.
     518   \param x The x coordinate of the Normal.
     519   \param y The y coordinate of the Normal.
     520   \param z The z coordinate of the Normal.
     521
     522   If a vertexNormal line is found this function will inject it into the vertexNormal-Array
     523*/
     524bool Model::addVertexNormal(const float x, const float y, const float z)
     525{
     526  PRINTF(3)("found vertex-Normal %f, %f, %f\n", x, y, z);
     527  this->normals->addEntry(x, y, z);
     528}
     529
     530/**
    565531   \brief parses a vertexTextureCoordinate-String
    566532   \param vTextureString The String that will be parsed.
     
    569535   this function will inject it into the vertexTexture-Array
    570536*/
    571 bool Model::readVertexTexture (char* vTextureString)
     537bool Model::addVertexTexture (char* vTextureString)
    572538{
    573539  float subbuffer1;
     
    580546}
    581547
    582 /**
    583     \brief Function to read in a mtl File.
    584     \param mtlFile The .mtl file to read
    585 
    586     This Function parses all Lines of an mtl File.
    587     The reason for it not to be in the materials-class is,
    588     that a material does not have to be able to read itself in from a File.
    589 
    590 */
    591 bool Model::readMtlLib (char* mtlFile)
    592 {
    593   this->mtlFileName = new char [strlen(mtlFile)+1];
    594   strcpy(this->mtlFileName, mtlFile);
    595   char* fileName = new char [strlen(objPath) + strlen(this->mtlFileName)+1];
    596   strcpy(fileName, this->objPath);
    597   strcat(fileName, this->mtlFileName);
    598  
    599 
    600   PRINTF(3)("Opening mtlFile: %s\n", fileName);
    601 
    602   ifstream* MTL_FILE = new ifstream (fileName);
    603   if (MTL_FILE->fail())
    604     {
    605       PRINTF(1)("unable to open file: %s\n", fileName);
    606       MTL_FILE->close();
    607       delete []fileName;
    608       delete MTL_FILE;
    609       return false;
    610     }
    611   char Buffer[500];
    612   Material* tmpMat = material;
    613   while(!MTL_FILE->eof())
    614     {
    615       MTL_FILE->getline(Buffer, 500);
    616       PRINTF(4)("found line in mtlFile: %s\n", Buffer);
    617      
    618 
    619       // create new Material
    620       if (!strncmp(Buffer, "newmtl ", 7))
    621         {
    622           tmpMat = tmpMat->addMaterial(Buffer+7);
    623           //      PRINTF(2)("%s, %p\n", tmpMat->getName(), tmpMat);
    624         }
    625       // setting a illumMode
    626       else if (!strncmp(Buffer, "illum ", 6))
    627         {
    628           tmpMat->setIllum(Buffer+6);
    629 
    630         }
    631       // setting Diffuse Color
    632       else if (!strncmp(Buffer, "Kd ", 3))
    633         {
    634           tmpMat->setDiffuse(Buffer+3);
    635         }
    636       // setting Ambient Color
    637       else if (!strncmp(Buffer, "Ka ", 3))
    638         {
    639           tmpMat->setAmbient(Buffer+3);
    640         }
    641       // setting Specular Color
    642       else if (!strncmp(Buffer, "Ks ", 3))
    643         {
    644           tmpMat->setSpecular(Buffer+3);
    645         }
    646       // setting The Specular Shininess
    647       else if (!strncmp(Buffer, "Ns ", 3))
    648         {
    649           tmpMat->setShininess(Buffer+3);
    650         }
    651       // setting up transparency
    652       else if (!strncmp(Buffer, "d ", 2))
    653         {
    654           tmpMat->setTransparency(Buffer+2);
    655         }
    656       else if (!strncmp(Buffer, "Tf ", 3))
    657         {
    658           tmpMat->setTransparency(Buffer+3);
    659         }
    660      
    661       else if (!strncmp(Buffer, "map_Kd ", 7))
    662         {
    663           tmpMat->setDiffuseMap(Buffer+7);
    664         }
    665       else if (!strncmp(Buffer, "map_Ka ", 7))
    666         {
    667           tmpMat->setAmbientMap(Buffer+7);
    668         }
    669       else if (!strncmp(Buffer, "map_Ks ", 7))
    670         {
    671           tmpMat->setSpecularMap(Buffer+7);
    672         }
    673       else if (!strncmp(Buffer, "bump ", 5))
    674         {
    675           tmpMat->setBump(Buffer+7);
    676         }
    677      
    678 
    679     }
    680   MTL_FILE->close();
    681   delete []fileName;
    682   delete MTL_FILE;
    683   return true;
     548/**
     549   \brief adds a Texture Coordinate
     550   \param u The u coordinate of the TextureCoordinate.
     551   \param v The y coordinate of the TextureCoordinate.
     552
     553   If a TextureCoordinate line is found this function will inject it into the TextureCoordinate-Array
     554*/
     555bool Model::addVertexTexture(const float u, const float v)
     556{
     557  PRINTF(3)("found vertex-Texture %f, %f\n", u, v);
     558  this->vTexture->addEntry(u);
     559  this->vTexture->addEntry(v);
    684560}
    685561
     
    688564   \param matString the Material that will be set.
    689565*/
    690 bool Model::readUseMtl (char* matString)
    691 {
     566bool Model::addUseMtl (char* matString)
     567{
     568  /*
    692569  if (!this->mtlFileName)
    693570    {
     
    695572      return false;
    696573    }
    697      
     574  */     
    698575  if (this->currentGroup->faceCount >0)
    699576    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
     
    717594  this->vertices->finalizeArray();
    718595  this->vTexture->finalizeArray();
    719   if (normals->getCount() == 0) // vertices-Array must be uilt for this
     596  if (normals->getCount() == 0) // vertices-Array must be built for this
    720597    this->buildVertexNormals();
    721598  this->normals->finalizeArray();
     
    743620                glEnd();
    744621              this->currentGroup->faceMode = 0;
    745               PRINTF(2)("using material %s for coming Faces.\n", tmpFace->materialString);
    746622              Material* tmpMat;
    747623              if ((tmpMat = material->search(tmpFace->materialString)) != NULL)
    748                 tmpMat->select();
     624                {
     625                  tmpMat->select();
     626                  PRINTF(2)("using material %s for coming Faces.\n", tmpFace->materialString);
     627                }
     628              else
     629                PRINTF(1)("material %s not found.\n", tmpFace->materialString);
     630
    749631
    750632            }
     
    893775      normArray[i].normalize();
    894776      PRINTF(3)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
    895 
     777     
    896778      this->normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z);
    897779
     
    907789   This will inject a Cube, because this is the most basic model.
    908790*/
    909 void Model::BoxModel(void)
    910 {
    911   this->readVertex ("-0.5 -0.5 0.5");
    912   this->readVertex ("0.5 -0.5 0.5");
    913   this->readVertex ("-0.5 0.5 0.5");
    914   this->readVertex ("0.5 0.5 0.5");
    915   this->readVertex ("-0.5 0.5 -0.5");
    916   this->readVertex ("0.5 0.5 -0.5");
    917   this->readVertex ("-0.5 -0.5 -0.5");
    918   this->readVertex ("0.5 -0.5 -0.5");
    919 
    920   this->readVertexTexture ("0.0 0.0");
    921   this->readVertexTexture ("1.0 0.0");
    922   this->readVertexTexture ("0.0 1.0");
    923   this->readVertexTexture ("1.0 1.0");
    924   this->readVertexTexture ("0.0 2.0");
    925   this->readVertexTexture ("1.0 2.0");
    926   this->readVertexTexture ("0.0 3.0");
    927   this->readVertexTexture ("1.0 3.0");
    928   this->readVertexTexture ("0.0 4.0");
    929   this->readVertexTexture ("1.0 4.0");
    930   this->readVertexTexture ("2.0 0.0");
    931   this->readVertexTexture ("2.0 1.0");
    932   this->readVertexTexture ("-1.0 0.0");
    933   this->readVertexTexture ("-1.0 1.0");
    934 
    935   this->readVertexNormal ("0.0 0.0 1.0");
    936   this->readVertexNormal ("0.0 0.0 1.0");
    937   this->readVertexNormal ("0.0 0.0 1.0");
    938   this->readVertexNormal ("0.0 0.0 1.0");
    939   this->readVertexNormal ("0.0 1.0 0.0");
    940   this->readVertexNormal ("0.0 1.0 0.0");
    941   this->readVertexNormal ("0.0 1.0 0.0");
    942   this->readVertexNormal ("0.0 1.0 0.0");
    943   this->readVertexNormal ("0.0 0.0 -1.0");
    944   this->readVertexNormal ("0.0 0.0 -1.0");
    945   this->readVertexNormal ("0.0 0.0 -1.0");
    946   this->readVertexNormal ("0.0 0.0 -1.0");
    947   this->readVertexNormal ("0.0 -1.0 0.0");
    948   this->readVertexNormal ("0.0 -1.0 0.0");
    949   this->readVertexNormal ("0.0 -1.0 0.0");
    950   this->readVertexNormal ("0.0 -1.0 0.0");
    951   this->readVertexNormal ("1.0 0.0 0.0");
    952   this->readVertexNormal ("1.0 0.0 0.0");
    953   this->readVertexNormal ("1.0 0.0 0.0");
    954   this->readVertexNormal ("1.0 0.0 0.0");
    955   this->readVertexNormal ("-1.0 0.0 0.0");
    956   this->readVertexNormal ("-1.0 0.0 0.0");
    957   this->readVertexNormal ("-1.0 0.0 0.0");
    958   this->readVertexNormal ("-1.0 0.0 0.0");
     791void Model::cubeModel(void)
     792{
     793  this->addVertex ("-0.5 -0.5 0.5");
     794  this->addVertex ("0.5 -0.5 0.5");
     795  this->addVertex ("-0.5 0.5 0.5");
     796  this->addVertex ("0.5 0.5 0.5");
     797  this->addVertex ("-0.5 0.5 -0.5");
     798  this->addVertex ("0.5 0.5 -0.5");
     799  this->addVertex ("-0.5 -0.5 -0.5");
     800  this->addVertex ("0.5 -0.5 -0.5");
     801
     802  this->addVertexTexture ("0.0 0.0");
     803  this->addVertexTexture ("1.0 0.0");
     804  this->addVertexTexture ("0.0 1.0");
     805  this->addVertexTexture ("1.0 1.0");
     806  this->addVertexTexture ("0.0 2.0");
     807  this->addVertexTexture ("1.0 2.0");
     808  this->addVertexTexture ("0.0 3.0");
     809  this->addVertexTexture ("1.0 3.0");
     810  this->addVertexTexture ("0.0 4.0");
     811  this->addVertexTexture ("1.0 4.0");
     812  this->addVertexTexture ("2.0 0.0");
     813  this->addVertexTexture ("2.0 1.0");
     814  this->addVertexTexture ("-1.0 0.0");
     815  this->addVertexTexture ("-1.0 1.0");
     816
     817  this->addVertexNormal ("0.0 0.0 1.0");
     818  this->addVertexNormal ("0.0 0.0 1.0");
     819  this->addVertexNormal ("0.0 0.0 1.0");
     820  this->addVertexNormal ("0.0 0.0 1.0");
     821  this->addVertexNormal ("0.0 1.0 0.0");
     822  this->addVertexNormal ("0.0 1.0 0.0");
     823  this->addVertexNormal ("0.0 1.0 0.0");
     824  this->addVertexNormal ("0.0 1.0 0.0");
     825  this->addVertexNormal ("0.0 0.0 -1.0");
     826  this->addVertexNormal ("0.0 0.0 -1.0");
     827  this->addVertexNormal ("0.0 0.0 -1.0");
     828  this->addVertexNormal ("0.0 0.0 -1.0");
     829  this->addVertexNormal ("0.0 -1.0 0.0");
     830  this->addVertexNormal ("0.0 -1.0 0.0");
     831  this->addVertexNormal ("0.0 -1.0 0.0");
     832  this->addVertexNormal ("0.0 -1.0 0.0");
     833  this->addVertexNormal ("1.0 0.0 0.0");
     834  this->addVertexNormal ("1.0 0.0 0.0");
     835  this->addVertexNormal ("1.0 0.0 0.0");
     836  this->addVertexNormal ("1.0 0.0 0.0");
     837  this->addVertexNormal ("-1.0 0.0 0.0");
     838  this->addVertexNormal ("-1.0 0.0 0.0");
     839  this->addVertexNormal ("-1.0 0.0 0.0");
     840  this->addVertexNormal ("-1.0 0.0 0.0");
    959841
    960842  /* normaleLess-testingMode
    961   this->readFace ("1 2 4 3");
    962   this->readFace ("3 4 6 5");
    963   this->readFace ("5 6 8 7");
    964   this->readFace ("7 8 2 1");
    965   this->readFace ("2 8 6 4");
    966   this->readFace ("7 1 3 5");
     843  this->addFace ("1 2 4 3");
     844  this->addFace ("3 4 6 5");
     845  this->addFace ("5 6 8 7");
     846  this->addFace ("7 8 2 1");
     847  this->addFace ("2 8 6 4");
     848  this->addFace ("7 1 3 5");
    967849  */
    968850
    969   this->readFace ("1/1/1 2/2/2 4/4/3 3/3/4");
    970   this->readFace ("3/3/5 4/4/6 6/6/7 5/5/8");
    971   this->readFace ("5/5/9 6/6/10 8/8/11 7/7/12");
    972   this->readFace ("7/7/13 8/8/14 2/10/15 1/9/16");
    973   this->readFace ("2/2/17 8/11/18 6/12/19 4/4/20");
    974   this->readFace ("7/13/21 1/1/22 3/3/23 5/14/24");
    975 
    976 }
     851  this->addFace ("1/1/1 2/2/2 4/4/3 3/3/4");
     852  this->addFace ("3/3/5 4/4/6 6/6/7 5/5/8");
     853  this->addFace ("5/5/9 6/6/10 8/8/11 7/7/12");
     854  this->addFace ("7/7/13 8/8/14 2/10/15 1/9/16");
     855  this->addFace ("2/2/17 8/11/18 6/12/19 4/4/20");
     856  this->addFace ("7/13/21 1/1/22 3/3/23 5/14/24");
     857
     858}
     859
     860
     861void Model::sphereModel()
     862{
     863  int detail = 30;
     864  if (detail <= 0) detail = 1;
     865  float df = (float)detail;
     866  for (float i = 0.0; i < df/2; i+=1.0)
     867    {
     868      for (float j = 0.0; j < df; j+=1.0)
     869      {
     870        float vz = i/df *2.0*PI - PI/2.0;
     871        this->addVertex(cos(j/df*2.0*PI) * cos(vz) ,
     872                        sin(j/df*2.0*PI) * cos(vz),
     873                        sin(vz));
     874        //if (j==0.0)
     875        //printf ("%f %f\n", vz, sin (vz));
     876        if (i==0.0)
     877                  printf("%f, %f\n", j/df*2.0*PI, cos(j/df*PI));
     878      }
     879    }
     880  vertices->debug();
     881  for (int i = 0; i < detail/2; i++)
     882    for (int j = 1; j < detail; j++)
     883      {
     884        unsigned int v1,v2,v3,v4;
     885        v1 = i*detail +j;
     886
     887        /*      if (j+1 == detail)
     888          {
     889            v2 = i*detail +1;
     890            v3 = i*detail+detail + 1;
     891          }
     892          else*/
     893          {
     894            v2 = i*detail +j+1;
     895            v3 = i*detail+detail + j+1;
     896          }
     897        v4 = i*detail+detail + j;
     898        //printf("%i %i %i %i\n", v1, v2, v3, v4);
     899        this->addFace(4, 0, v1, v2, v3, v4);
     900      }
     901}
     902
     903/**
     904   \brief Creates a Cylinder.
     905*/
     906void Model::cylinderModel(void)
     907{
     908  unsigned int detail = 20;
     909  float size = 1.0;
     910
     911  // check if devision by zero
     912  if (detail <= 3)
     913    detail = 3;
     914  int count = 0;
     915  // defining Points of the Cylinder.
     916  for (float phi = 0.0; phi < 2.0*PI; phi += 2.0*PI/(float)detail)
     917    {
     918      this->addVertex(size*cos(phi), size*sin(phi), -size);
     919      this->addVertex(size*cos(phi), size*sin(phi), size);
     920      count ++;
     921    }
     922  this->addVertex(0, 0, -size);
     923  this->addVertex(0, 0, size);
     924
     925 
     926  if (count != detail)
     927    cout << "calculation error, count should be " << detail << " but is " << count << endl;
     928  vertices->debug();
     929
     930  // adding Faces
     931  for (int i = 0; i < detail-1; i++)
     932    {
     933      int p1, p2, p3, p4;
     934      p1 = 2*i+1;
     935      p2 = 2*i+2;
     936      if (i <= detail);
     937      p3 = 2*i+4;
     938      p4 = 2*i+3;
     939      cout <<i+1 <<": "<< p1 <<" "<< p2 <<" "<< p3 <<" "<< p4 <<endl;
     940      this->addFace(4, 0, p1, p2, p3, p4);
     941      this->addFace(3, 0, p4, p1, 2*detail+1);
     942      this->addFace(3, 0, p2, p3, 2*detail+2);
     943    }
     944  addFace(4,0, 2*detail-1, 2*detail, 2, 1);
     945  this->addFace(3, 0, 1, 2*detail-1, 2*detail+1);
     946  this->addFace(3, 0, 2*detail, 2, 2*detail+2);
     947
     948}
  • orxonox/branches/trackManager/src/importer/model.h

    r3369 r3430  
    77#define _MODEL_H
    88
    9 #include "../stdincl.h"
     9//#include "../stdincl.h"
    1010
    11 #include "array.h"
    1211#include "material.h"
    13 #include "vector.h"
    14 #include <fstream>
     12
     13// FORWARD DEFINITION //
     14class Array;
     15class Vector;
    1516
    1617using namespace std;
    1718
    18 
     19enum PRIMITIVE {PLANE, CUBE, SPHERE, CYLINDER};
    1920
    2021//! Class that handles 3D-Models. it can also read them in and display them.
     
    2223{
    2324 public:
    24   Model ();
    25   Model (char* fileName);
    26   Model(char* fileName, float scaling);
    27   ~Model ();
     25  Model(void);
     26  Model(PRIMITIVE type);
     27  Model(char* modelName);
     28  virtual ~Model(void);
     29
     30  void setName(const char* name);
    2831 
    29   void draw (void) const;
    30   void draw (int groupNumber) const;
    31   void draw (char* groupName) const;
     32  void draw(void) const;
     33  void draw(int groupNumber) const;
     34  void draw(char* groupName) const;
    3235  int getGroupCount() const;
    3336
    34  private:
     37 protected:
     38  char* name;            //!< This is the name of the Model.
     39  bool finalized;        //!< Sets the Object to be finalized.
     40 
    3541  //! This is the placeholder of one Vertex beloning to a Face.
    36   struct FaceElement 
     42  struct FaceElement
    3743  {
    3844    int vertexNumber;    //!< The number of the Vertex out of the Array* vertices, this vertex points to.
     
    4349
    4450  //! This is the placeholder of a Face belonging to a Group of Faces.
    45   /**
    46      \todo take Material to a call for itself.
    47 
    48      This can also be a Material-Change switch.
    49      That means if you want to change a Material inside of a group,
    50      you can create an empty face and apply a material to it, and the Importer will cahnge Colors
    51   */
    52   struct Face
     51  struct Face
    5352  {
    5453    int vertexCount;        //!< The Count of vertices this Face has.
     
    6564    char* name;         //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function.
    6665
    67     GLuint listNumber;  //!< The number of the GL-List this Group gets.
     66    unsigned int listNumber;//!< The number of the GL-List this Group gets.
    6867    Face* firstFace;    //!< The first Face in this group.
    6968    Face* currentFace;  //!< The current Face in this Group (the one we are currently working with.)
     
    8887  float scaleFactor;    //!< The Factor with which the Model should be scaled. \todo maybe one wants to scale the Model after Initialisation
    8988
    90   char* objPath;        //!< The Path wher the obj and mtl-file are located.
    91   char* objFileName;    //!< The Name of the obj-file.
    92   char* mtlFileName;    //!< The Name of the mtl-file (parsed out of the obj-file)
    93 
    94   bool initialize (void);
     89  bool initialize(void);
    9590  bool initGroup(Group* group);
    9691  bool initFace (Face* face);
     
    10095  bool cleanupFaceElement(FaceElement* faceElem);
    10196
    102   ///// readin ///
    103   bool importFile (char* fileName);
    104   bool readFromObjFile (void);
    105  
    106   bool readGroup (char* groupString);
    107   bool readVertex (char* vertexString);
    108   bool readFace (char* faceString);
    109   bool readVertexNormal (char* normalString);
    110   bool readVertexTexture (char* vTextureString);
    111   bool readMtlLib (char* matFile);
    112   bool readUseMtl (char* mtlString);
     97 public:
     98  bool addGroup(char* groupString);
     99  bool addVertex(char* vertexString);
     100  bool addVertex(const float x, const float y, const float z);
     101  bool addFace(char* faceString);
     102  bool addFace(const float faceElemCount, int type, ...);
     103  bool addVertexNormal(char* normalString);
     104  bool addVertexNormal(const float x, const float y, const float z);
     105  bool addVertexTexture(char* vTextureString);
     106  bool addVertexTexture(const float u, const float v);
     107  bool addUseMtl(char* mtlString);
     108  void finalize(void);
    113109
    114   bool importToGL (void);
    115   bool addGLElement (FaceElement* elem);
     110 protected:
     111  bool importToGL(void);
     112  bool addGLElement(FaceElement* elem);
    116113
    117   bool buildVertexNormals ();
     114  bool buildVertexNormals(void);
    118115
    119   void BoxModel (void);
     116  void cubeModel(void);
     117  void sphereModel(void);
     118  void cylinderModel(void);
    120119};
    121120
Note: See TracChangeset for help on using the changeset viewer.