Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10147 in orxonox.OLD for trunk


Ignore:
Timestamp:
Dec 25, 2006, 1:30:44 PM (18 years ago)
Author:
patrick
Message:

merged the mount_point branche back to trunk to use the new std::* based obj file importer

Location:
trunk/src
Files:
13 edited
7 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/Makefile.am

    r10033 r10147  
    2525                \
    2626                obj/objModel.cc \
     27                \
     28                oif/object_information_file.cc \
     29                oif/resource_oif.cc \
    2730                \
    2831                bsp/bsp_manager.cc \
     
    7982                obj/objModel.h \
    8083                \
     84                oif/object_information_file.h \
     85                oif/resource_oif.h \
     86                \
    8187                md2/md2Model.h \
    8288                md2/resource_md2.h \
  • trunk/src/lib/graphics/importer/model.h

    r9869 r10147  
    8383    inline unsigned int getTriangleCount() const { return this->pModelInfo.numTriangles; };
    8484
     85    /** function to extract the mount points from the model data */
     86    virtual void extractMountPoints() {}
     87
     88
    8589  protected:
    8690    Model();
  • trunk/src/lib/graphics/importer/obj/objModel.cc

    r10033 r10147  
    4444
    4545  this->finalize();
     46
     47  this->extractMountPoints();
    4648}
    4749
     
    138140          this->addVertexTexture(buffer+3);
    139141        }
    140       // case group
    141       else if (!strncmp(buffer, "g ", 2))
     142      // case group or object (depends on the exporter program)
     143      else if (!strncmp(buffer, "g ", 2) || !strncmp(buffer, "o ", 2))
    142144        {
    143145          this->addGroup (buffer+2);
  • trunk/src/lib/graphics/importer/obj/objModel.h

    r10033 r10147  
    1616  OBJModel(const std::string& fileName, float scaling = 1.0);
    1717  virtual ~OBJModel();
     18
    1819
    1920private:
  • trunk/src/lib/graphics/importer/static_model.cc

    r9869 r10147  
    9191  this->updateBase();
    9292}
     93
     94
     95
     96/**
     97 * extract the mount points from this file: looking at each group and checking if the group realy is a mountpoint marker
     98 * if so get place and orientation
     99 */
     100void StaticModel::extractMountPoints()
     101{
     102
     103  // go through all groups and check if they are mounts
     104  std::vector<StaticModelData::Group>::const_iterator groupIt = this->data->getGroups().begin();
     105  for( ; groupIt != this->data->getGroups().end(); groupIt++)
     106  {
     107    //PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str());
     108
     109    // get the name of this group and check if it's a mout point identifier
     110    std::string groupName = (*groupIt).name;
     111    std::vector<Vector> vertices;
     112
     113    if( groupName.find("MP.", 0) != std::string::npos)
     114    {
     115      PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str());
     116
     117      // now check if it is a mount point identifier
     118      if( this->data->getGroups().size() != 5) {
     119        PRINTF(1)("the face count of %s is wrong, perhaps you missnamed this object or used the wrong mount point object\n", groupName.c_str());
     120      }
     121
     122      // now extract the direction from the length:
     123      std::vector<StaticModelData::Face>::const_iterator faceIt = (*groupIt)._faces.begin();
     124      for( ; faceIt < (*groupIt)._faces.end(); faceIt++)
     125      {
     126        // now go through all modelfaceelements
     127        std::vector<StaticModelData::FaceElement>::const_iterator faceElementIt = (*faceIt)._elements.begin();
     128        for( ; faceElementIt < (*faceIt)._elements.end(); faceElementIt++)
     129        {
     130          int vert = (*faceElementIt).vertexNumber;
     131          vertices.push_back(Vector(this->data->getVertices()[vert*3],
     132                             this->data->getVertices()[vert*3 + 1],
     133                             this->data->getVertices()[vert*3 + 2]));
     134        }
     135      }
     136
     137      // vertex with the max count is the up-point
     138      std::vector<Vector>::const_iterator it = vertices.begin();
     139      Vector tmpPoint;
     140      int tmpCount;
     141      Vector upPoint;
     142      int maxCount = 0;
     143      for( ; it < vertices.end(); it++)
     144      {
     145        tmpCount = 0;
     146        tmpPoint = (*it);
     147        //
     148        std::vector<Vector>::const_iterator it2 = vertices.begin();
     149        for( ; it2 < vertices.end(); it2++)
     150          if( tmpPoint == *it2)
     151            tmpCount++;
     152
     153        // if this is the vertex with the most surrounding vertices
     154        if( tmpCount > maxCount)
     155        {
     156          upPoint = tmpPoint;
     157          maxCount = tmpCount;
     158        }
     159      }
     160
     161      // now get the center of the object
     162      Vector center;
     163      it = vertices.begin();
     164      for( ; it < vertices.end(); it++)
     165        center += (*it);
     166      // scale
     167      center /= vertices.size();
     168
     169
     170    }
     171
     172  }
     173
     174
     175}
     176
     177
    93178
    94179/**
  • trunk/src/lib/graphics/importer/static_model.h

    r10141 r10147  
    5858
    5959  void finalize();
     60  void extractMountPoints();
    6061
    6162  void acquireData(const StaticModelData::Pointer& data);
  • trunk/src/lib/graphics/importer/static_model_data.cc

    r10141 r10147  
    276276bool StaticModelData::addGroup(const std::string& groupString)
    277277{
    278   PRINTF(5)("Read Group: %s.\n", groupString.c_str());
     278  PRINTF(4)("Read Group: %s.\n", groupString.c_str());
    279279  if (!_modelGroups.empty() && !_modelGroups.back()._faces.empty())
    280280    _modelGroups.push_back(Group());
    281281
    282   if (groupString == "default")
    283     _modelGroups.back().name = groupString;
    284   // setting the group name if not default.
     282  _modelGroups.back().name = groupString;
    285283  return true;
    286284}
  • trunk/src/lib/graphics/importer/static_model_data.h

    r10141 r10147  
    129129  ///! HACK SOLUTION sTriangleExt should be const in the modelInfo.
    130130  sTriangleExt* getTrianglesExt() { return &this->triangles[0]; };
     131  const std::vector<Group>& getGroups() { return this->_modelGroups; }
    131132
    132133  float getScaleFactor() const  { return scaleFactor; }
  • trunk/src/world_entities/WorldEntities.am

    r9869 r10147  
    2424                world_entities/planet.cc \
    2525                world_entities/bsp_entity.cc \
     26                world_entities/mount_point.cc \
    2627                \
    2728                world_entities/weapons/test_gun.cc \
     
    127128                planet.h \
    128129                bsp_entity.h \
     130                mount_point.h \
    129131                \
    130132                weapons/test_gun.h \
  • trunk/src/world_entities/mount_point.cc

    r10143 r10147  
    2424#include "debug.h"
    2525#include "state.h"
    26 #include "class_id_DEPRECATED.h"
    2726
    2827
  • trunk/src/world_entities/npcs/npc_test.cc

    r10114 r10147  
    3939  this->registerObject(this, NPC2::_objectList);
    4040
    41   if ((float)rand()/RAND_MAX > .5f)
    42     this->loadModel("models/ships/bolido.obj", 6);
    43   else
    44     this->loadModel("models/ships/gobblin.obj", 6);
     41//   if ((float)rand()/RAND_MAX > .5f)
     42//     this->loadModel("models/ships/bolido.obj", 6);
     43//   else
     44//     this->loadModel("models/ships/gobblin.obj", 6);
    4545
    4646
     
    8484 * Just override this function with whatever you want to be drawn.
    8585 */
    86 void NPC2::draw() const
    87 {
    88   glMatrixMode(GL_MODELVIEW);
    89   glPushMatrix();
    90   float matrix[4][4];
    91 
    92   /* translate */
    93   glTranslatef (this->getAbsCoor ().x,
    94                 this->getAbsCoor ().y,
    95                 this->getAbsCoor ().z);
    96   /* rotate */
    97   this->getAbsDir ().matrix (matrix);
    98   glMultMatrixf((float*)matrix);
    99 
    100 //   if (this->shader != NULL && this->shader != Shader::getActiveShader())
    101 //     shader->activateShader();
    102 
    103   this->getModel()->draw();
    104 //   shader->deactivateShader();
    105 
    106 
    107 /*  if (this->model)
    108     this->model->draw();*/
    109   glPopMatrix();
    110 }
     86// void NPC2::draw() const
     87// {
     88//   glMatrixMode(GL_MODELVIEW);
     89//   glPushMatrix();
     90//   float matrix[4][4];
     91//
     92//   /* translate */
     93//   glTranslatef (this->getAbsCoor ().x,
     94//                 this->getAbsCoor ().y,
     95//                 this->getAbsCoor ().z);
     96//   /* rotate */
     97//   this->getAbsDir ().matrix (matrix);
     98//   glMultMatrixf((float*)matrix);
     99//
     100// //   if (this->shader != NULL && this->shader != Shader::getActiveShader())
     101// //     shader->activateShader();
     102//
     103//   if( this->getModel())
     104//     this->getModel()->draw();
     105// //   shader->deactivateShader();
     106//
     107//
     108// /*  if (this->model)
     109//     this->model->draw();*/
     110//   glPopMatrix();
     111// }
    111112
    112113
  • trunk/src/world_entities/npcs/npc_test.h

    r9869 r10147  
    2222
    2323  virtual void tick(float dt);
    24   virtual void draw() const;
     24//   virtual void draw() const;
    2525
    2626 private:
  • trunk/src/world_entities/world_entity.cc

    r10013 r10147  
    1212
    1313   ### File Specific:
    14    main-programmer: Patrick Boenzli
    15    co-programmer: Christian Meyer
     14   main-programmer: Patrick Boenzli, Benjamin Grauer
     15   co-programmer: Christian Meier
    1616*/
    1717#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
     
    2424#include "md2/md2Model.h"
    2525#include "md3/md3_model.h"
     26
     27#include "oif/object_information_file.h"
     28#include "mount_point.h"
    2629
    2730#include "aabb_tree_node.h"
     
    6972  this->damage = 0.0f; // no damage dealt by a default entity
    7073  this->scaling = 1.0f;
     74  this->oiFile = NULL;
    7175
    7276  /* OSOLETE */
     
    103107  for (unsigned int i = 0; i < this->models.size(); i++)
    104108    this->setModel(NULL, i);
     109
     110  // remove the object information file
     111  if( this->oiFile)
     112    delete this->oiFile;
     113  // and clear all monut points
     114  this->mountPoints.clear();
    105115
    106116  // Delete the obbTree
     
    191201    {
    192202      PRINTF(4)("fetching OBJ file: %s\n", fileName.c_str());
     203      // creating the model and loading it
    193204      StaticModel* model = new StaticModel();
    194205      *model = ResourceOBJ(fileName, this->scaling);
     
    201212      else
    202213        delete model;
     214
     215      // now get the object information file for this model, if any
     216      std::string oifName = fileName.substr(0, fileName.length() - 4) + ".oif";
     217      this->loadObjectInformationFile( oifName);
    203218    }
    204219    /// LOADING AN MD2-model
     
    249264
    250265
     266
     267/**
     268 * loads the object information file for this model
     269 * @param fileName the name of the file
     270 */
     271void WorldEntity::loadObjectInformationFile(const std::string& fileName)
     272{
     273  PRINTF(4)("loading the oif File: %s\n", fileName.c_str());
     274
     275  this->oiFile = new ObjectInformationFile(fileName);
     276}
     277
     278
    251279/**
    252280 * builds the obb-tree
     
    290318  }
    291319  return true;
     320}
     321
     322
     323/**
     324 * adds a mount point to the end of the list
     325 * @param mountPoint point to be added
     326 */
     327void WorldEntity::addMountPoint(MountPoint* mountPoint)
     328{
     329  // add the mount point at the last position
     330  this->mountPoints.push_back(mountPoint);
     331}
     332
     333/**
     334 * adds a mount point to a world entity
     335 * @param mountPoint point to be added
     336 */
     337void WorldEntity::addMountPoint(int slot, MountPoint* mountPoint)
     338{
     339  if( this->mountPoints[slot] != NULL)
     340  {
     341    PRINTF(0)("adding a mount point to a slot, that already exists! ignoring - maybe some object do not get connected well (object: %s)\n", this->getClassCName());
     342  }
     343
     344  // just connect the mount point
     345  this->mountPoints[slot] = mountPoint;
     346}
     347
     348
     349/**
     350 * mounts a world entity on a specified mount point (~socket)
     351 * @param entity entity to be connected
     352 */
     353void WorldEntity::mount(int slot, WorldEntity* entity)
     354{
     355  if( this->mountPoints[slot] == NULL)
     356  {
     357    PRINTF(0)("you tried to add an entity to a mount point that doesn't exist (slot %i)\n", slot);
     358    return;
     359  }
     360
     361  // mount the entity
     362  this->mountPoints[slot]->mount(entity);
     363}
     364
     365
     366/**
     367 * removes a mount point from a specified mount point
     368 * @param mountPoint entity to be unconnected
     369 */
     370void WorldEntity::unmount(int slot)
     371{
     372    if( this->mountPoints[slot] == NULL)
     373  {
     374    PRINTF(0)("you tried to remove an entity from a mount point that doesn't exist (slot %i)\n", slot);
     375    return;
     376  }
     377
     378  // unmount the entity
     379  this->mountPoints[slot]->unmount();
    292380}
    293381
  • trunk/src/world_entities/world_entity.h

    r10013 r10147  
    1515#include "object_manager.h"
    1616#include "glincl.h"
     17
     18#include "aabb_tree_node.h"
     19
     20#include "physics_interface.h"
     21
    1722#include <vector>
    18 
    19 #include "aabb_tree_node.h"
    20 
    21 #include "physics_interface.h"
    22 
    2323
    2424
     
    3333class Model;
    3434
     35class ObjectInformationFile;
     36class MountPoint;
     37
    3538
    3639//! Basis-class all interactive stuff in the world is derived from
     
    5053  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
    5154
     55  void loadObjectInformationFile(const std::string& fileName);
    5256  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
     57
     58  void addMountPoint(MountPoint* mountPoint);
     59  void addMountPoint(int slot, MountPoint* mountPoint);
     60  void mount(int slot, WorldEntity* entity);
     61  void unmount(int slot);
    5362
    5463  /** @param visibility if the Entity should be visible (been draw) */
     
    185194
    186195  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
     196  ObjectInformationFile*  oiFile;             //!< Reference to the object information file discribing the model of this WE
     197  std::vector<MountPoint*> mountPoints;       //!< A list with mount points for this model
    187198  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
    188199  std::string             modelLODName;       //!< the name of the model lod file
Note: See TracChangeset for help on using the changeset viewer.