Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3398 in orxonox.OLD


Ignore:
Timestamp:
Feb 6, 2005, 11:02:45 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Made the Model-class externalizable
meaning:

  1. There is now a possibility to initialize a Model without adding default vertex info
  2. Then you can add your vertices
  3. Then you can add any other model-specific stuff, like normals/texcoords/Faces
  4. For the time-being Materials have to be handled externaly, but this will change.

PATRICK: if you read this, you should be able, to implement this into the loading-screen, look at src/importer/framework.cc→main and then the big table.

with this aproach the Developer is farther away from OpenGL and closer to logic.

Location:
orxonox/trunk/src
Files:
5 edited

Legend:

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

    r3396 r3398  
    1515
    1616#include "framework.h"
    17 
     17int verbose;
    1818void DrawGLScene()
    1919{
     
    5353{
    5454  verbose = 2;
    55 
    56   PRINTF(2)("This is The big verbose-Test %i, %s\n", 1, "cool");
    5755
    5856  Uint8* keys; // This variable will be used in the keyboard routine
     
    7573    obj = new OBJModel(argv[1]);
    7674  else
    77     obj = (OBJModel*) new Model();
    78  
     75    {
     76      // This is an example, of how it is possible, to create a new Model, and adding some vertex-information.
     77      // This also packs everything into a DisplayList, and can be handled exactly as any other model.
     78      // This is an example of a cube with Texture-Coordinates, but without explicite Vertex-Normals. (they are soft-created).
     79
     80      obj = (OBJModel*) new Model();
     81      obj->setName("CUBE");
     82      obj->addVertex ("-0.5 -0.5 0.5");
     83      obj->addVertex ("0.5 -0.5 0.5");
     84      obj->addVertex ("-0.5 0.5 0.5");
     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     
     91      obj->addVertexTexture ("0.0 0.0");
     92      obj->addVertexTexture ("1.0 0.0");
     93      obj->addVertexTexture ("0.0 1.0");
     94      obj->addVertexTexture ("1.0 1.0");
     95      obj->addVertexTexture ("0.0 2.0");
     96      obj->addVertexTexture ("1.0 2.0");
     97      obj->addVertexTexture ("0.0 3.0");
     98      obj->addVertexTexture ("1.0 3.0");
     99      obj->addVertexTexture ("0.0 4.0");
     100      obj->addVertexTexture ("1.0 4.0");
     101      obj->addVertexTexture ("2.0 0.0");
     102      obj->addVertexTexture ("2.0 1.0");
     103      obj->addVertexTexture ("-1.0 0.0");
     104      obj->addVertexTexture ("-1.0 1.0");
     105
     106      obj->addFace ("1 2 4 3");
     107      obj->addFace ("3 4 6 5");
     108      obj->addFace ("5 6 8 7");
     109      obj->addFace ("7 8 2 1");
     110      obj->addFace ("2 8 6 4");
     111      obj->addFace ("7 1 3 5");
     112      obj->finalize();
     113    }
    79114  M = Vector(wHandler.screen->w/2, wHandler.screen->h/2, 0);
    80115  rotAxis = Vector (0.0,1.0,0.0);
  • orxonox/trunk/src/importer/model.cc

    r3397 r3398  
    1515
    1616#include "model.h"
    17 int verbose = 1; //! \todo should be GLOBAL
     17
    1818using namespace std;
    1919
    2020/**
    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 
     21   \brief Creates a 3D-Model.
     22
     23   This only initializes a 3D-Model, but does not cleanup the Faces.
     24*/
     25Model::Model(void)
     26{
    2827  this->initialize();
    29 
    30   this->BoxModel();
     28}
     29
     30/**
     31   \brief Creates a 3D-Model of Primitive-Type type
     32
     33   if you want to just display a Cube/Sphere/Cylinder/... without any material.
     34   
     35   \todo implement Cube/Sphere/Cylinder/...
     36*/
     37Model::Model(PRIMITIVE type)
     38{
     39  this->initialize();
     40
     41  if (type == CUBE)
     42    this->BoxModel();
    3143
    3244  this->importToGL ();
     
    3648
    3749/**
     50   \brief Creates a 3D-Model. and assigns it a Name.
     51*/
     52Model::Model(char* modelName)
     53{
     54  this->initialize();
     55  this->setName(modelName);
     56}
     57
     58/**
    3859   \brief deletes an Model.
    3960
    4061   Looks if any from model allocated space is still in use, and if so deleted it.
    4162*/
    42 Model::~Model()
     63Model::~Model(void)
    4364{
    4465  PRINTF(3)("Deleting Model ");
     
    6485  if (this->material)
    6586    delete this->material;
     87}
     88
     89/**
     90   \brief Finalizes an Object. This can be done outside of the Class.
     91*/
     92void Model::finalize(void)
     93{
     94  this->importToGL ();
     95 
     96  this->cleanup();
     97
     98  this->finalized = true;
    6699}
    67100
     
    157190
    158191  this->name = NULL;
     192  this->finalized = false;
    159193  // setting the start group;
    160194  this->firstGroup = new Group;
     
    173207}
    174208
     209void Model::setName(const char* name)
     210{
     211  if (this->name)
     212    delete this->name;
     213  this->name = new char[strlen(name)+1];
     214  strcpy(this->name, name);
     215}
    175216/**
    176217   \brief initializes a new Group model
  • orxonox/trunk/src/importer/model.h

    r3396 r3398  
    1515using namespace std;
    1616
    17 
     17enum PRIMITIVE {PLANE, CUBE, SPHERE, CYLINDER};
    1818
    1919//! Class that handles 3D-Models. it can also read them in and display them.
     
    2222 public:
    2323  Model(void);
     24  Model(PRIMITIVE type);
     25  Model(char* modelName);
    2426  virtual ~Model(void);
     27
     28  void setName(const char* name);
    2529 
    2630  void draw(void) const;
     
    3034
    3135 protected:
    32   char* name;            //!< This is the name of the Model;
     36  char* name;            //!< This is the name of the Model.
     37  bool finalized;        //!< Sets the Object to be finalized.
     38 
    3339  //! This is the placeholder of one Vertex beloning to a Face.
    3440  struct FaceElement
     
    94100  bool cleanupFaceElement(FaceElement* faceElem);
    95101
     102 public:
    96103  bool addGroup (char* groupString);
    97104  bool addVertex (char* vertexString);
     
    100107  bool addVertexTexture (char* vTextureString);
    101108  bool addUseMtl (char* mtlString);
     109  void finalize(void);
    102110
     111 protected:
    103112  bool importToGL (void);
    104113  bool addGLElement (FaceElement* elem);
  • orxonox/trunk/src/importer/objModel.cc

    r3397 r3398  
    109109      PRINTF(0)("Resolved file %s.\n", name);
    110110 
    111   if (this->name) delete this->name;
    112   this->name = new char[strlen(name)+1];
    113   strcpy(this->name, name);
     111  this->setName(name);
    114112  if (this->material)
    115113    this->material->addTexturePath(this->objPath);
  • orxonox/trunk/src/orxonox.cc

    r3365 r3398  
    3131#include "game_loader.h"
    3232#include <string.h>
     33int verbose;
    3334
    3435using namespace std;
Note: See TracChangeset for help on using the changeset viewer.