Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3657 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Mar 27, 2005, 12:22:09 AM (20 years ago)
Author:
bensch
Message:

orxonox.trunk: importer now with subclass PrimitiveModel, taht supports working CONE/CUBE/PLANE/SPHERE/CYLINDER

Location:
orxonox/trunk/src
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/Makefile.am

    r3655 r3657  
    5959                 lib/graphics/importer/array.cc \
    6060                 lib/graphics/importer/objModel.cc \
     61                 lib/graphics/importer/primitive_model.cc \
    6162                 lib/graphics/importer/model.cc \
    6263                 lib/graphics/importer/material.cc \
  • orxonox/trunk/src/Makefile.in

    r3655 r3657  
    6565        data_tank.$(OBJEXT) graphics_engine.$(OBJEXT) light.$(OBJEXT) \
    6666        fontset.$(OBJEXT) array.$(OBJEXT) objModel.$(OBJEXT) \
    67         model.$(OBJEXT) material.$(OBJEXT) texture.$(OBJEXT) \
    68         base_entity.$(OBJEXT) base_object.$(OBJEXT) \
     67        primitive_model.$(OBJEXT) model.$(OBJEXT) material.$(OBJEXT) \
     68        texture.$(OBJEXT) base_entity.$(OBJEXT) base_object.$(OBJEXT) \
    6969        ini_parser.$(OBJEXT) list.$(OBJEXT) resource_manager.$(OBJEXT) \
    7070        vector.$(OBJEXT) curve.$(OBJEXT) glmenu_imagescreen.$(OBJEXT)
     
    9393@AMDEP_TRUE@    ./$(DEPDIR)/orxonox.Po ./$(DEPDIR)/p_node.Po \
    9494@AMDEP_TRUE@    ./$(DEPDIR)/player.Po ./$(DEPDIR)/primitive.Po \
     95@AMDEP_TRUE@    ./$(DEPDIR)/primitive_model.Po \
    9596@AMDEP_TRUE@    ./$(DEPDIR)/projectile.Po \
    9697@AMDEP_TRUE@    ./$(DEPDIR)/resource_manager.Po \
     
    264265                 lib/graphics/importer/array.cc \
    265266                 lib/graphics/importer/objModel.cc \
     267                 lib/graphics/importer/primitive_model.cc \
    266268                 lib/graphics/importer/model.cc \
    267269                 lib/graphics/importer/material.cc \
     
    434436@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/player.Po@am__quote@
    435437@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/primitive.Po@am__quote@
     438@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/primitive_model.Po@am__quote@
    436439@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/projectile.Po@am__quote@
    437440@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/resource_manager.Po@am__quote@
     
    832835@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    833836@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o objModel.obj `if test -f 'lib/graphics/importer/objModel.cc'; then $(CYGPATH_W) 'lib/graphics/importer/objModel.cc'; else $(CYGPATH_W) '$(srcdir)/lib/graphics/importer/objModel.cc'; fi`
     837
     838primitive_model.o: lib/graphics/importer/primitive_model.cc
     839@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT primitive_model.o -MD -MP -MF "$(DEPDIR)/primitive_model.Tpo" -c -o primitive_model.o `test -f 'lib/graphics/importer/primitive_model.cc' || echo '$(srcdir)/'`lib/graphics/importer/primitive_model.cc; \
     840@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/primitive_model.Tpo" "$(DEPDIR)/primitive_model.Po"; else rm -f "$(DEPDIR)/primitive_model.Tpo"; exit 1; fi
     841@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='lib/graphics/importer/primitive_model.cc' object='primitive_model.o' libtool=no @AMDEPBACKSLASH@
     842@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/primitive_model.Po' tmpdepfile='$(DEPDIR)/primitive_model.TPo' @AMDEPBACKSLASH@
     843@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     844@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o primitive_model.o `test -f 'lib/graphics/importer/primitive_model.cc' || echo '$(srcdir)/'`lib/graphics/importer/primitive_model.cc
     845
     846primitive_model.obj: lib/graphics/importer/primitive_model.cc
     847@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT primitive_model.obj -MD -MP -MF "$(DEPDIR)/primitive_model.Tpo" -c -o primitive_model.obj `if test -f 'lib/graphics/importer/primitive_model.cc'; then $(CYGPATH_W) 'lib/graphics/importer/primitive_model.cc'; else $(CYGPATH_W) '$(srcdir)/lib/graphics/importer/primitive_model.cc'; fi`; \
     848@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/primitive_model.Tpo" "$(DEPDIR)/primitive_model.Po"; else rm -f "$(DEPDIR)/primitive_model.Tpo"; exit 1; fi
     849@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='lib/graphics/importer/primitive_model.cc' object='primitive_model.obj' libtool=no @AMDEPBACKSLASH@
     850@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/primitive_model.Po' tmpdepfile='$(DEPDIR)/primitive_model.TPo' @AMDEPBACKSLASH@
     851@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     852@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o primitive_model.obj `if test -f 'lib/graphics/importer/primitive_model.cc'; then $(CYGPATH_W) 'lib/graphics/importer/primitive_model.cc'; else $(CYGPATH_W) '$(srcdir)/lib/graphics/importer/primitive_model.cc'; fi`
    834853
    835854model.o: lib/graphics/importer/model.cc
  • orxonox/trunk/src/lib/graphics/importer/Makefile.am

    r3656 r3657  
    2727                  model.cc \
    2828                  objModel.cc \
     29                  primitive_model.cc \
    2930                  array.cc \
    3031                  material.cc \
     
    3839                model.h \
    3940                objModel.h \
     41                primitive_model.h \
    4042                array.h \
    4143                material.h \
  • orxonox/trunk/src/lib/graphics/importer/Makefile.in

    r3656 r3657  
    5454PROGRAMS = $(bin_PROGRAMS)
    5555am_importer_OBJECTS = framework.$(OBJEXT) windowHandler.$(OBJEXT) \
    56         model.$(OBJEXT) objModel.$(OBJEXT) array.$(OBJEXT) \
    57         material.$(OBJEXT) texture.$(OBJEXT) graphics_engine.$(OBJEXT) \
    58         base_object.$(OBJEXT) vector.$(OBJEXT)
     56        model.$(OBJEXT) objModel.$(OBJEXT) primitive_model.$(OBJEXT) \
     57        array.$(OBJEXT) material.$(OBJEXT) texture.$(OBJEXT) \
     58        graphics_engine.$(OBJEXT) base_object.$(OBJEXT) \
     59        vector.$(OBJEXT)
    5960importer_OBJECTS = $(am_importer_OBJECTS)
    6061importer_LDADD = $(LDADD)
     
    6768@AMDEP_TRUE@    ./$(DEPDIR)/graphics_engine.Po \
    6869@AMDEP_TRUE@    ./$(DEPDIR)/material.Po ./$(DEPDIR)/model.Po \
    69 @AMDEP_TRUE@    ./$(DEPDIR)/objModel.Po ./$(DEPDIR)/texture.Po \
    70 @AMDEP_TRUE@    ./$(DEPDIR)/vector.Po ./$(DEPDIR)/windowHandler.Po
     70@AMDEP_TRUE@    ./$(DEPDIR)/objModel.Po \
     71@AMDEP_TRUE@    ./$(DEPDIR)/primitive_model.Po \
     72@AMDEP_TRUE@    ./$(DEPDIR)/texture.Po ./$(DEPDIR)/vector.Po \
     73@AMDEP_TRUE@    ./$(DEPDIR)/windowHandler.Po
    7174CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
    7275        $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
     
    195198                  model.cc \
    196199                  objModel.cc \
     200                  primitive_model.cc \
    197201                  array.cc \
    198202                  material.cc \
     
    206210                model.h \
    207211                objModel.h \
     212                primitive_model.h \
    208213                array.h \
    209214                material.h \
     
    283288@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Po@am__quote@
    284289@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/objModel.Po@am__quote@
     290@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/primitive_model.Po@am__quote@
    285291@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/texture.Po@am__quote@
    286292@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vector.Po@am__quote@
  • orxonox/trunk/src/lib/graphics/importer/framework.cc

    r3656 r3657  
    1717
    1818#include "vector.h"
     19
     20#include "primitive_model.h"
     21
    1922
    2023int verbose;
     
    7679    obj = new OBJModel(argv[1]);
    7780  else
    78     obj = (OBJModel*) new Model(SPHERE);
     81    obj = new PrimitiveModel(SPHERE);
    7982
    8083  M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0);
  • orxonox/trunk/src/lib/graphics/importer/framework.h

    r3656 r3657  
    3535
    3636WindowHandler wHandler;  // Create an instance of the whandler basecode class
    37 OBJModel* obj;
     37Model* obj;
    3838
    3939
  • orxonox/trunk/src/lib/graphics/importer/model.cc

    r3656 r3657  
    3434{
    3535  this->initialize();
    36 }
    37 
    38 /**
    39    \brief Creates a 3D-Model of Primitive-Type type
    40 
    41    if you want to just display a Cube/Sphere/Cylinder/... without any material.
    42    
    43    \todo implement Cube/Sphere/Cylinder/...
    44 */
    45 Model::Model(PRIMITIVE type)
    46 {
    47   this->initialize();
    48 
    49   switch (type)
    50     {
    51     default:
    52     case CUBE:
    53       this->cubeModel();
    54       break;
    55     case SPHERE:
    56       this->sphereModel();
    57       break;
    58     case CYLINDER:
    59       this->cylinderModel();
    60       break;
    61 
    62     }
    63   this->importToGL ();
    64 
    65   this->cleanup();
    6636}
    6737
     
    492462
    493463      tmpElem->vertexNumber = va_arg (itemlist, int) -1;
    494       if (type >= 2)
     464      if (type & TEXCOORD)
    495465        tmpElem->texCoordNumber = va_arg (itemlist, int) -1;
    496       if (type == 1 || type ==3)
     466      if (type & NORMAL)
    497467        tmpElem->normalNumber = va_arg(itemlist, int) -1;
    498468      this->currentGroup->currentFace->vertexCount++;
     
    863833
    864834}
    865 
    866 /**
    867    \brief Builds a Sphere into the Model.
    868    \param size The radius of the Sphere.
    869    \param detail The detail of the Sphere.
    870 */
    871 void Model::sphereModel(float size, unsigned int detail)
    872 {
    873   int vertexCount = 0;
    874   if (detail <= 0)
    875     detail = 1;
    876   //  detail = 2; // make it even
    877   float df = (float)detail;
    878  
    879   // defining the Vertices
    880   for (float i = 0; i < df *2.0; i+=1.0)
    881     {
    882       float vi = i/df *PI;
    883       for (float j = -df / 2.0 +1.0; j < df / 2.0; j+=1.0 *df/(df+1.0))
    884         {
    885           float vj = j/df *PI;
    886           this->addVertex(size * cos(vi) * cos(vj),
    887                           size * sin(vj),
    888                           size * sin(vi) * cos(vj));
    889           this->addVertexTexture(i / (df *2.0), (j-1.0)/(df)+.5);
    890           vertexCount++;
    891         }
    892     }
    893   this->addVertex(0, -size, 0);
    894   this->addVertex(0, size, 0);
    895 
    896   // defining the binding Faces.
    897   unsigned int v1, v2, v3, v4;
    898   for (int i = 0; i <= detail * 2 -1; i++)
    899     {
    900       for (int j = 0; j <= detail; j++)
    901         {
    902          
    903           v1 = i*detail + j;
    904           v4 = i*detail + (j+1);
    905          
    906           if (i == detail*2 -1)
    907             {
    908               v2 = j;
    909               v3 = j+1;
    910             }
    911           else
    912             {
    913               v2 = (i+1)*detail + j;
    914               v3 = (i+1)*detail + (j+1);
    915             }
    916          
    917           if (j == 0)
    918             {
    919               v1 = vertexCount+1;
    920               this->addFace(3, 2, v1, v1, v3, v3, v4, v4);
    921             }
    922           else if (j == detail)
    923             {
    924               v3 = vertexCount+2;
    925               this->addFace(3, 2, v1, v1, v2, v2, v3, v3);
    926             }
    927           else
    928             this->addFace(4, 2, v1, v1, v2, v2, v3, v3, v4, v4);
    929         }
    930     }
    931 }
    932 /**
    933    \brief Creates a Cylinder.
    934 */
    935 void Model::cylinderModel(void)
    936 {
    937   unsigned int detail = 20;
    938   float size = 1.0;
    939 
    940   // check if devision by zero
    941   if (detail <= 3)
    942     detail = 3;
    943   int count = 0;
    944   // defining Points of the Cylinder.
    945   for (float phi = 0.0; phi < 2.0*PI; phi += 2.0*PI/(float)detail)
    946     {
    947       this->addVertex(size*cos(phi), size*sin(phi), -size);
    948       this->addVertex(size*cos(phi), size*sin(phi), size);
    949       count ++;
    950     }
    951   this->addVertex(0, 0, -size);
    952   this->addVertex(0, 0, size);
    953 
    954  
    955   if (count != detail)
    956     PRINTF(1)("calculation error, count should be %d but is %d.\n", detail, count);
    957   vertices->debug();
    958 
    959   // adding Faces
    960   for (int i = 0; i < detail-1; i++)
    961     {
    962       int p1, p2, p3, p4;
    963       p1 = 2*i+1;
    964       p2 = 2*i+2;
    965       if (i <= detail);
    966       p3 = 2*i+4;
    967       p4 = 2*i+3;
    968       // something is wrong here
    969       this->addFace(4, 0, p1, p2, p3, p4);
    970       this->addFace(3, 0, p4, p1, 2*detail+1);
    971       this->addFace(3, 0, p2, p3, 2*detail+2);
    972     }
    973   addFace(4,0, 2*detail-1, 2*detail, 2, 1);
    974   this->addFace(3, 0, 1, 2*detail-1, 2*detail+1);
    975   this->addFace(3, 0, 2*detail, 2, 2*detail+2);
    976 
    977 }
    978 
    979 
    980 void Model::coneModel(float size, unsigned int detail)
    981 {
    982 
    983  
    984 }
  • orxonox/trunk/src/lib/graphics/importer/model.h

    r3656 r3657  
    1515using namespace std;
    1616
    17 //! Specification of different primitives the Model knows
    18 enum PRIMITIVE {PLANE, CUBE, SPHERE, CYLINDER};
     17// definition of different modes for setting up Faces
     18#define VERTEX 0       //!< If Faces are created WITH Vertex-Coordinate
     19#define NORMAL 1       //!< If Faces are created WITH Normals (otherwise autocalculate)
     20#define TEXCOORD 2     //!< If Faces are created WITH TextureCoordinate
    1921
    2022//! Class that handles 3D-Models. it can also read them in and display them.
     
    2325 public:
    2426  Model(void);
    25   Model(PRIMITIVE type);
    2627  Model(char* modelName);
    2728  virtual ~Model(void);
     
    114115
    115116  void cubeModel(void);
    116   void sphereModel(float size = 1.0, unsigned int detail = 10);
    117   void cylinderModel(void);
    118   void coneModel(float size = 1.0, unsigned int detail = 10);
    119117};
    120118
  • orxonox/trunk/src/lib/graphics/importer/primitive_model.cc

    r3655 r3657  
    1 
    2 
    31/*
    42   orxonox - the future of 3D-vertical-scrollers
     
    1210
    1311   ### File Specific:
    14    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1513   co-programmer: ...
    1614*/
    1715
    18 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
    19 
    20 #include "proto_class.h"
    21 
    22 #include "stdincl.h" // maybe
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_MODEL
     17
     18#include "primitive_model.h"
     19
     20#include <math.h>
     21#include "vector.h"
     22#include "debug.h"
    2323
    2424using namespace std;
     
    2929   \todo this constructor is not jet implemented - do it
    3030*/
    31 ProtoClass::ProtoClass ()
    32 {
    33    this->setClassName ("ProtoClass");
     31PrimitiveModel::PrimitiveModel ()
     32{
     33  this->initialize();
     34
     35  this->cubeModel();
     36
     37  this->importToGL ();
     38
     39  this->cleanup();
     40}
     41
     42/**
     43   \brief Creates a 3D-Model of Primitive-Type type
     44
     45   if you want to just display a Cube/Sphere/Cylinder/... without any material.
     46   
     47   \todo implement Cube/Sphere/Cylinder/...
     48*/
     49PrimitiveModel::PrimitiveModel(PRIMITIVE type, float size, unsigned int detail)
     50{
     51  this->initialize();
     52
     53  switch (type)
     54    {
     55    default:
     56    case CUBE:
     57      this->cubeModel();
     58      break;
     59    case SPHERE:
     60      this->sphereModel(size, detail);
     61      break;
     62    case CYLINDER:
     63      this->cylinderModel();
     64      break;
     65    case CONE:
     66      this->coneModel(size, detail);
     67      break;
     68    case PLANE:
     69      this->planeModel(size, detail);
     70      break;
     71    }
     72  this->importToGL ();
     73
     74  this->cleanup();
    3475}
    3576
     
    3980
    4081*/
    41 ProtoClass::~ProtoClass ()
     82PrimitiveModel::~PrimitiveModel ()
    4283{
    4384  // delete what has to be deleted here
    4485}
    4586
    46 /**
    47    \brief nonsense - delete this method
    48    \param realy nothing to give
    49    \returns true or false - probably nothing?
    50 
    51    this is just to show the doxygen abilities (this for example is an extension for a long comment)
    52 */
    53 bool ProtoClass::doNonSense (int nothing) {}
     87
     88
     89
     90/**
     91   \brief Includes a default model
     92
     93   This will inject a Cube, because this is the most basic model.
     94*/
     95void PrimitiveModel::cubeModel(void)
     96{
     97  this->addVertex (-0.5, -0.5, 0.5);
     98  this->addVertex (0.5, -0.5, 0.5);
     99  this->addVertex (-0.5, 0.5, 0.5);
     100  this->addVertex (0.5, 0.5, 0.5);
     101  this->addVertex (-0.5, 0.5, -0.5);
     102  this->addVertex (0.5, 0.5, -0.5);
     103  this->addVertex (-0.5, -0.5, -0.5);
     104  this->addVertex (0.5, -0.5, -0.5);
     105
     106  this->addVertexTexture (0.0, 0.0);
     107  this->addVertexTexture (1.0, 0.0);
     108  this->addVertexTexture (0.0, 1.0);
     109  this->addVertexTexture (1.0, 1.0);
     110  this->addVertexTexture (0.0, 2.0);
     111  this->addVertexTexture (1.0, 2.0);
     112  this->addVertexTexture (0.0, 3.0);
     113  this->addVertexTexture (1.0, 3.0);
     114  this->addVertexTexture (0.0, 4.0);
     115  this->addVertexTexture (1.0, 4.0);
     116  this->addVertexTexture (2.0, 0.0);
     117  this->addVertexTexture (2.0, 1.0);
     118  this->addVertexTexture (-1.0, 0.0);
     119  this->addVertexTexture (-1.0, 1.0);
     120
     121  this->addVertexNormal (0.0, 0.0, 1.0);
     122  this->addVertexNormal (0.0, 0.0, 1.0);
     123  this->addVertexNormal (0.0, 0.0, 1.0);
     124  this->addVertexNormal (0.0, 0.0, 1.0);
     125  this->addVertexNormal (0.0, 1.0, 0.0);
     126  this->addVertexNormal (0.0, 1.0, 0.0);
     127  this->addVertexNormal (0.0, 1.0, 0.0);
     128  this->addVertexNormal (0.0, 1.0, 0.0);
     129  this->addVertexNormal (0.0, 0.0, -1.0);
     130  this->addVertexNormal (0.0, 0.0, -1.0);
     131  this->addVertexNormal (0.0, 0.0, -1.0);
     132  this->addVertexNormal (0.0, 0.0, -1.0);
     133  this->addVertexNormal (0.0, -1.0, 0.0);
     134  this->addVertexNormal (0.0, -1.0, 0.0);
     135  this->addVertexNormal (0.0, -1.0, 0.0);
     136  this->addVertexNormal (0.0, -1.0, 0.0);
     137  this->addVertexNormal (1.0, 0.0, 0.0);
     138  this->addVertexNormal (1.0, 0.0, 0.0);
     139  this->addVertexNormal (1.0, 0.0, 0.0);
     140  this->addVertexNormal (1.0, 0.0, 0.0);
     141  this->addVertexNormal (-1.0, 0.0, 0.0);
     142  this->addVertexNormal (-1.0, 0.0, 0.0);
     143  this->addVertexNormal (-1.0, 0.0, 0.0);
     144  this->addVertexNormal (-1.0, 0.0, 0.0);
     145
     146  /* normaleLess-testingMode
     147  this->addFace ("1 2 4 3");
     148  this->addFace ("3 4 6 5");
     149  this->addFace ("5 6 8 7");
     150  this->addFace ("7 8 2 1");
     151  this->addFace ("2 8 6 4");
     152  this->addFace ("7 1 3 5");
     153  */
     154
     155  this->addFace (4, 3, 1,1,1, 2,2,2, 4,4,3, 3,3,4);
     156  this->addFace (4, 3, 3,3,5, 4,4,6, 6,6,7, 5,5,8);
     157  this->addFace (4, 3, 5,5,9, 6,6,10, 8,8,11, 7,7,12);
     158  this->addFace (4, 3, 7,7,13, 8,8,14, 2,10,15, 1,9,16);
     159  this->addFace (4, 3, 2,2,17, 8,11,18, 6,12,19, 4,4,20);
     160  this->addFace (4, 3, 7,13,21, 1,1,22, 3,3,23, 5,14,24);
     161
     162}
     163
     164/**
     165   \brief Builds a Sphere into the Model.
     166   \param size The radius of the Sphere.
     167   \param detail The detail of the Sphere.
     168*/
     169void PrimitiveModel::sphereModel(float size, unsigned int detail)
     170{
     171  int vertexCount = 0;
     172  if (detail <= 0)
     173    detail = 1;
     174  //  detail = 2; // make it even
     175  float df = (float)detail;
     176 
     177  // defining the Vertices
     178  for (float i = 0; i < df *2.0; i+=1.0)
     179    {
     180      float vi = i/df *PI;
     181      for (float j = -df / 2.0 +1.0; j < df / 2.0; j+=1.0 *df/(df+1.0))
     182        {
     183          float vj = j/df *PI;
     184          this->addVertex(size * cos(vi) * cos(vj),
     185                          size * sin(vj),
     186                          size * sin(vi) * cos(vj));
     187          this->addVertexTexture(i / (df *2.0), (j-1.0)/(df)+.5);
     188          vertexCount++;
     189        }
     190    }
     191  this->addVertex(0, -size, 0);
     192  this->addVertex(0, size, 0);
     193
     194  // defining the binding Faces.
     195  unsigned int v1, v2, v3, v4;
     196  for (int i = 0; i <= detail * 2 -1; i++)
     197    {
     198      for (int j = 0; j <= detail; j++)
     199        {
     200         
     201          v1 = i*detail + j;
     202          v4 = i*detail + (j+1);
     203         
     204          if (i == detail*2 -1)
     205            {
     206              v2 = j;
     207              v3 = j+1;
     208            }
     209          else
     210            {
     211              v2 = (i+1)*detail + j;
     212              v3 = (i+1)*detail + (j+1);
     213            }
     214         
     215          if (j == 0)
     216            {
     217              v1 = vertexCount+1;
     218              this->addFace(3, TEXCOORD, v1, v1, v3, v3, v4, v4);
     219            }
     220          else if (j == detail)
     221            {
     222              v3 = vertexCount+2;
     223              this->addFace(3, TEXCOORD, v1, v1, v2, v2, v3, v3);
     224            }
     225          else
     226            this->addFace(4, TEXCOORD, v1, v1, v2, v2, v3, v3, v4, v4);
     227        }
     228    }
     229}
     230/**
     231   \brief Creates a Cylinder.
     232*/
     233void PrimitiveModel::cylinderModel(float size, unsigned int detail)
     234{
     235  // check if devision by zero
     236  if (detail <= 3)
     237    detail = 3;
     238  int count = 0;
     239  // defining Points of the Cylinder.
     240  for (float phi = 0.0; phi < 2.0*PI; phi += 2.0*PI/(float)detail)
     241    {
     242      this->addVertex(size*cos(phi), size*sin(phi), -size);
     243      this->addVertex(size*cos(phi), size*sin(phi), size);
     244      count ++;
     245    }
     246  this->addVertex(0, 0, -size);
     247  this->addVertex(0, 0, size);
     248
     249 
     250  if (count != detail)
     251    PRINTF(1)("calculation error, count should be %d but is %d.\n", detail, count);
     252
     253  // adding Faces
     254  for (int i = 0; i < detail-1; i++)
     255    {
     256      int p1, p2, p3, p4;
     257      p1 = 2*i+1;
     258      p2 = 2*i+2;
     259      if (i <= detail);
     260      p3 = 2*i+4;
     261      p4 = 2*i+3;
     262      // something is wrong here
     263      this->addFace(4, 0, p1, p2, p3, p4);
     264      this->addFace(3, 0, p4, p1, 2*detail+1);
     265      this->addFace(3, 0, p2, p3, 2*detail+2);
     266    }
     267  addFace(4,0, 2*detail-1, 2*detail, 2, 1);
     268  this->addFace(3, VERTEX, 1, 2*detail-1, 2*detail+1);
     269  this->addFace(3, VERTEX, 2*detail, 2, 2*detail+2);
     270}
     271
     272/**
     273   \brief creates a cone inside of this Model
     274   \param size The size of the cone
     275   \param detail the Detail-level of this cone
     276*/
     277void PrimitiveModel::coneModel(float size, unsigned int detail)
     278{
     279  this->addVertex(0,-size,0);
     280  this->addVertex(0,size,0);
     281  if (detail <= 0)
     282    detail = 1;
     283  float df = (float)detail;
     284 
     285  // defining the Vertices
     286  for (float i = 0; i < df; i+=1.0)
     287    {
     288      float vi = i/df *2.0*PI;
     289      this->addVertex(size* sin(vi),
     290                      -size,
     291                      size* cos(vi));
     292    }
     293
     294  //defining Faces
     295  for (int i = 0; i < detail; i++)
     296    {
     297      unsigned int v1, v2;
     298      v1 = i+3;
     299      if (i == detail -1)
     300        v2 = 3;
     301      else
     302        v2 = i+4;
     303      this->addFace(3, VERTEX, 1, v1, v2);
     304      this->addFace(3, VERTEX, 2, v1, v2);
     305    }
     306}
     307
     308/**
     309   \brief creates a Plane inside of this Model
     310   \param size The size of this plane
     311   \param detail the Detail-level of this plane.
     312*/
     313void PrimitiveModel::planeModel(float size, unsigned int detail)
     314{
     315  //defining vertices
     316  for (int i = 0; i < detail; i++)
     317    for (int j = 0; j < detail; j++)
     318      {
     319        this->addVertex(((float)i/(float)(detail-1) -.5)*size,
     320                        0,
     321                        ((float)j/(float)(detail-1) -.5)*size);
     322        this->addVertexTexture((float)i/(float)(detail-1),
     323                               (float)j/(float)(detail-1));
     324      }
     325  //defining Faces
     326  unsigned int v1, v2, v3, v4;
     327  for (int i = 0; i < detail-1; i++)
     328    for (int j = 1; j < detail; j++)
     329      {
     330        v1 = i*detail + j;
     331        v2 = (i+1)*detail + j;
     332        v3 = (i+1)*detail + (j+1);
     333        v4 = i*detail + (j+1);
     334        this->addFace(4, TEXCOORD, v1, v1, v2, v2, v3, v3, v4, v4);
     335      }
     336}
  • orxonox/trunk/src/lib/graphics/importer/primitive_model.h

    r3655 r3657  
    11/*!
    2     \file proto_class.h
    3     \brief Definition of the proto class template, used quickly start work
    4     \todo Example: this shows how to use simply add a Marker that here has to be done something.
     2    \file primitive_model.h
    53
    6     The Protoclass exists, to help you quikly getting the run for how to develop in orxonox.
    7     It is an example for the CODING-CONVENTION, and a starting-point for every class.
    84*/
    95
    10 #ifndef _PROTO_CLASS_H
    11 #define _PROTO_CLASS_H
     6#ifndef _PRIMITIVE_MODEL_H
     7#define _PRIMITIVE_MODEL_H
    128
    13 #include "what realy has to be included"
    14 #include "base_object.h"
     9#include "model.h"
     10
     11//! Specification of different primitives the Model knows
     12enum PRIMITIVE {PLANE, CUBE, SPHERE, CYLINDER, CONE};
    1513
    1614// FORWARD DEFINITION \\
    17 class someClassWeNeed;
    1815
    19 
    20 /*class Test;*/ /* forward definition of class Test (without including it here!)*/
    21 
    22 //! A default class that aids you to start creating a new class
    23 /**
    24    here can be some longer description of this class
    25 */
    26 class ProtoClass : public BaseObject {
     16//! A Class to create some default Models
     17class PrimitiveModel : public Model {
    2718
    2819 public:
    29   ProtoClass();
    30   virtual ~ProtoClass();
     20  PrimitiveModel();
     21  PrimitiveModel(PRIMITIVE type, float size = 1.0, unsigned int detail = 10);
    3122
    32   bool doNonSense (int nothing);
     23  virtual ~PrimitiveModel();
    3324
    34  private:
    35   int nonSense;  //!< doxygen tag here like this for all the variables - delete this variable if you use this
    36 
     25 protected:
     26  void cubeModel(void);
     27  void sphereModel(float size = 1.0, unsigned int detail = 10);
     28  void cylinderModel(float size = 1.0, unsigned int detail = 10);
     29  void coneModel(float size = 1.0, unsigned int detail = 10);
     30  void planeModel(float size = 1.0, unsigned int detail = 1);
    3731};
    3832
    39 #endif /* _PROTO_CLASS_H */
     33#endif /* _PRIMITIVE_MODEL_H */
  • orxonox/trunk/src/lib/util/resource_manager.cc

    r3655 r3657  
    2020// different resource Types
    2121#include "objModel.h"
     22#include "primitive_model.h"
    2223#include "texture.h"
    2324
     
    110111        {
    111112          PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", tmpName);
    112           tmpResource = new Model(CUBE);
     113          tmpResource = new PrimitiveModel(CUBE);
    113114        }
    114115      break;
Note: See TracChangeset for help on using the changeset viewer.