Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10314 in orxonox.OLD


Ignore:
Timestamp:
Jan 24, 2007, 12:45:39 AM (17 years ago)
Author:
patrick
Message:

merged branche mount_point to trunk. this will add mount point abilities, bsp transparency fix and some other smaller stuff to this trunk

Location:
trunk/src
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/bsp/bsp_file.cc

    r10033 r10314  
    430430  char fileName [500];
    431431  char ext [500];
    432   struct stat results;
    433432
    434433
     
    660659  int      errorCode = 0;           //!< the error code for the texture loading functions
    661660  unsigned int   lightMap;          //!< the OpenGL texture handle
    662   int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
    663   int      mipmapWidth = 0;         //!< the width of the mipmap
    664   int      mipmapHight = 0;         //!< the height of the mipmap3
     661  //int      mipmapLevel = 0;         //!< the maximum mipmap level for this texture
     662  //int      mipmapWidth = 0;         //!< the width of the mipmap
     663  //int      mipmapHight = 0;         //!< the height of the mipmap3
    665664  float sc, scale, temp;
    666665  for(int i = 0; i < 128*128*3 ; i++)
     
    11011100  {
    11021101    int sto  =  array[0];
    1103     array[0] =  scale * array[1] ;
    1104     array[1] =  scale * array[2];
    1105     array[2] =  scale * sto ;
     1102    array[0] =  (int) scale * array[1] ;
     1103    array[1] =  (int) scale * array[2];
     1104    array[2] =  (int) scale * sto ;
    11061105  }
    11071106
  • trunk/src/lib/graphics/importer/bsp/bsp_manager.cc

    r10076 r10314  
    298298  }//else
    299299
     300
     301  // now sort the transparent faces in the right order
     302  int size = this->trasparent.size();
     303
     304  // bubble sort
     305  bool hasSwapped = true;
     306  Vector v1, v2;
     307
     308  while( hasSwapped)
     309  {
     310    hasSwapped = false;
     311
     312    for( int i = 0; i < size - 1; i++)
     313    {
     314      // sorting test
     315      face& fac1 =  (this->bspFile->faces)[this->trasparent[i]];
     316      face& fac2 =  (this->bspFile->faces)[this->trasparent[i+1]];
     317
     318      // get center of face 1
     319      const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;
     320
     321      // assign the values of the vertices
     322      v1(curVertex[fac1.vertex].position[0], curVertex[fac1.vertex].position[1], curVertex[fac1.vertex].position[2]);
     323      v2(curVertex[fac2.vertex].position[0], curVertex[fac2.vertex].position[1], curVertex[fac2.vertex].position[2]);
     324      // relativly to observer
     325      v1 = this->cam - v1;
     326      v2 = this->cam - v2;
     327
     328      // swap if necessary
     329      if( v1 > v2)
     330      {
     331        // swap elements
     332        int tmp = this->trasparent[i+1];
     333        this->trasparent[i+1] = this->trasparent[i];
     334        this->trasparent[i] = tmp;
     335
     336        hasSwapped = true;
     337      }
     338    }
     339  }
     340
     341
     342
     343  // draw all solid faces
    300344  while(!this->opal.empty()) {
    301     this->draw_face(this->opal.front());
    302     this->opal.pop_front();
    303   }
     345    this->draw_face(this->opal.back()); // front()
     346    this->opal.pop_back();              // pop_back()
     347  }
     348
     349  // draw all transparent faces
    304350  while(!this->trasparent.empty()) {
    305351    this->draw_face(this->trasparent.back());
  • trunk/src/lib/graphics/importer/bsp/bsp_manager.h

    r10033 r10314  
    128128  bool * alreadyVisible;
    129129  // Deques to store the visible faces
    130   ::std::deque<int> trasparent; //!< the ones with transparancy go here
    131   ::std::deque<int> opal; //!< the others here.
     130  ::std::vector<int> trasparent; //!< the ones with transparancy go here
     131  ::std::vector<int> opal; //!< the others here.
    132132
    133133  Vector out;  //!< Stores collision coordinates
  • trunk/src/lib/graphics/importer/model.cc

    r9869 r10314  
    1717
    1818#include "model.h"
    19 
     19#include "debug.h"
    2020#include "glincl.h"
    2121
     
    8888  glEnd();
    8989}
     90
     91
     92/**
     93 * adds a mounting point to the model
     94 * @param up up vector
     95 * @param forward forward vector
     96 * @param center center vector
     97 */
     98void Model::addMountPoint(const Vector& up, const Vector& forward, const Vector& center, const std::string& name)
     99{
     100  mountPointSkeleton mps;
     101  mps.up = up;
     102  mps.forward = forward;
     103  mps.center = center;
     104  mps.name = name;
     105
     106  this->mountPoints.push_back(mps);
     107}
  • trunk/src/lib/graphics/importer/model.h

    r10147 r10314  
    5252
    5353
     54//! skeleton informations for all mount points
     55typedef struct
     56{
     57  std::string      name;                 //!< the name of the mount point
     58  Vector           up;                   //!< the up vector
     59  Vector           forward;              //!< the forward vector
     60  Vector           center;               //!< the center vector
     61} mountPointSkeleton;
     62
     63
     64
    5465//! This class defines the basic components of a model
    5566class Model : virtual public BaseObject {
    5667  ObjectListDeclaration(Model);
     68
     69  typedef std::list<mountPointSkeleton>   mpList;
    5770
    5871  public:
     
    8598    /** function to extract the mount points from the model data */
    8699    virtual void extractMountPoints() {}
     100    /** @returns a list of mounting points */
     101    inline const mpList& getMountPoints() const { return this->mountPoints; }
     102    void addMountPoint(const Vector& up, const Vector& forward, const Vector& center, const std::string& name);
    87103
    88104
     
    92108
    93109  protected:
    94     modelInfo      pModelInfo;      //!< Reference to the modelInfo
     110    modelInfo                        pModelInfo;      //!< Reference to the modelInfo
     111    mpList                           mountPoints;     //!< a list of all mounting point skeletons
    95112};
    96113
  • trunk/src/lib/graphics/importer/obj/objModel.cc

    r10147 r10314  
    4444
    4545  this->finalize();
    46 
    47   this->extractMountPoints();
    4846}
    4947
  • trunk/src/lib/graphics/importer/oif/object_information_file.cc

    r10147 r10314  
    2424
    2525
     26
     27/**
     28 * constructor
     29 */
     30OIFData::OIFData()
     31{
     32  this->_root = NULL;
     33}
     34
     35
    2636/**
    2737 * constructor
     
    3040OIFData::OIFData(const std::string& fileName)
    3141{
     42  this->_root = NULL;
    3243  this->load(fileName);
     44}
     45
     46
     47OIFData::~OIFData()
     48{
     49  if( this->_root)
     50    delete this->_root;
    3351}
    3452
     
    4058void OIFData::load(const std::string& fileName)
    4159{
    42   //
    43     if( fileName.empty())
     60  if( fileName.empty())
    4461  {
    45     PRINTF(3)("No filename specified for object information loading");
     62    PRINTF(1)("No filename specified for object information loading");
    4663    return;
    4764  }
    4865
    49   TiXmlDocument XMLDoc(fileName);
     66  TiXmlDocument* XMLDoc = new TiXmlDocument(fileName);
    5067  // load the campaign document
    51   if( !XMLDoc.LoadFile(fileName))
     68  if( !XMLDoc->LoadFile(fileName))
    5269  {
    5370    // report an error
    54     PRINTF(3)("Could not load XML File %s: %s @ %d:%d\n", fileName.c_str(), XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());
     71    PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName.c_str(), XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol());
    5572    return;
    5673  }
    5774
    5875  // check basic validity
    59   TiXmlElement* root = XMLDoc.RootElement();
    60   assert( root != NULL);
     76  this->_root = XMLDoc->RootElement();
     77  assert( this->_root != NULL);
    6178
    62   if( strcmp( root->Value(), "ObjectInformationFile"))
     79  if( strcmp( this->_root->Value(), "ObjectInformationFile"))
    6380  {
    6481    // report an error
    65     PRINTF(2)("Specified XML File is not an orxonox object information file (<ObjectInformationFile> element missing)\n");
     82    PRINTF(1)("Specified XML File is not an orxonox object information file (<ObjectInformationFile> element missing)\n");
    6683    return;
    6784  }
    6885
    69   // construct campaign
    70 //   return new Campaign( root);
     86//   this->initMountPoint( this->_root);
    7187}
    7288
    7389
    74 
    7590/**
    76  * standard constructor
     91 * constructor
     92 * @param fileName name of the file
    7793 */
    7894ObjectInformationFile::ObjectInformationFile()
     95  : data(new OIFData)
    7996{
    8097  this->init();
     
    107124
    108125/**
     126 * the definition of the assignment operator
     127 * @param oif
     128 * @return
     129 */
     130ObjectInformationFile& ObjectInformationFile::operator=(const ObjectInformationFile& oif)
     131{
     132  this->init();
     133  this->data = oif.data;
     134
     135  return *this;
     136}
     137
     138/**
    109139 * initizlizing function
    110140 */
     
    112142{
    113143
     144}
     145
     146
     147void ObjectInformationFile::load(const std::string& fileName)
     148{
     149  this->data = OIFData::Pointer(new OIFData(fileName));
    114150}
    115151
     
    124160
    125161
     162/**
     163 * this initializes the mount point
     164 * @param mountPoint to be initialized
     165 */
     166// void ObjectInformationFile::initMountPoint(MountPoint* mountPoint)
     167// {
     168//   TiXmlElement* root = this->data->root();
     169//
     170// }
    126171
    127 ObjectInformationFile& ObjectInformationFile::operator=(const ObjectInformationFile& oif)
    128 {
    129   this->data = oif.data;
    130   return *this;
    131 }
    132 
    133 
    134 
  • trunk/src/lib/graphics/importer/oif/object_information_file.h

    r10147 r10314  
    2020
    2121public:
     22  OIFData();
    2223  OIFData(const std::string& fileName);
    23   virtual ~OIFData() {}
     24  virtual ~OIFData();
    2425
    2526  void load(const std::string& fileName);
     27  void initMountPoint(const TiXmlElement* root);
     28
     29  inline const TiXmlElement* root() { return this->_root; }
    2630
    2731
    2832private:
    29 
     33  TiXmlElement* _root;           //!< root of the xml file
    3034};
    3135
     
    4044  virtual ~ObjectInformationFile();
    4145
     46  void load(const std::string& fileName);
     47
    4248  ObjectInformationFile& operator=(const ObjectInformationFile& oif);
     49
     50  /** @returns a reference to the xml oif file */
     51  inline const TiXmlElement* getMountPointDescription() { return this->data->root(); }
     52
     53  inline void acquireData(const OIFData::Pointer& data) { this->data = data; }
     54  const OIFData::Pointer& dataPointer() const { return this->data; };
     55
     56
    4357
    4458  private:
  • trunk/src/lib/graphics/importer/oif/resource_oif.cc

    r10147 r10314  
    2626  Resources::StorePointer* ptr = this->acquireResource(fileName);
    2727
     28
    2829  if (ptr)
    2930  {
    30     PRINTF(0)("FOUND OIF: %s\n", fileName.c_str());
    31     //this->acquireData(static_cast<ResourceOIF::OIFResourcePointer*>(ptr)->ptr());
     31    PRINTF(5)("FOUND OIF: %s\n", fileName.c_str());
     32    this->acquireData(static_cast<ResourceOIF::OIFResourcePointer*>(ptr)->ptr());
    3233  }
    3334  else
    3435  {
    35     PRINTF(4)("NOT FOUND OIF: %s\n", fileName.c_str());
    36 //     std::string modelFileName = this->Resource::locateFile(modelName);
    37 //     //std::string skinFileName = this->Resource::locateFile(skinName);
    38 //     this->MD2Model::load(modelFileName, skinName, scale);
    39 //     this->Resource::addResource(new ResourceOIF::OIFResourcePointer(loadString(modelName, skinName, scale), keepLevel, this->MD2Model::dataPointer()));
     36    PRINTF(5)("NOT FOUND OIF: %s\n", fileName.c_str());
     37    std::string fullName = this->Resource::locateFile(fileName);
     38    PRINTF(5)("trying loading of: %s\n", fullName.c_str());
     39    this->load(fullName);
     40    this->Resource::addResource(new ResourceOIF::OIFResourcePointer(fileName, keepLevel, this->ObjectInformationFile::dataPointer()));
    4041  }
    4142
  • trunk/src/lib/graphics/importer/oif/resource_oif.h

    r10147 r10314  
    1515{
    1616public:
    17   ResourceOIF(const std::string& fileName, const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
     17  ResourceOIF(const std::string& fileName,
     18              const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
    1819  static ResourceOIF createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel = Resources::KeepLevel());
    1920
  • trunk/src/lib/graphics/importer/static_model.cc

    r10147 r10314  
    4545
    4646StaticModel::StaticModel(const StaticModel& staticModel)
    47   : data(staticModel.data)
     47    : data(staticModel.data)
    4848{
    4949  this->registerObject(this, StaticModel::_objectList);
     
    111111    std::vector<Vector> vertices;
    112112
    113     if( groupName.find("MP.", 0) != std::string::npos)
     113    // check if the name has a "MP" prefix or else it won't work
     114    if( groupName.find("MP.", 0) == std::string::npos)
     115      continue;
     116
     117
     118    PRINTF(5)("Found a MountPoint: %s\n", groupName.c_str());
     119
     120    StaticModelData::Face triangle[3];
     121
     122    // now check if it is a mount point identifier
     123    if( (*groupIt)._faces.size() != 11)
    114124    {
    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());
     125      PRINTF(1)("the face count of %s is wrong, perhaps you missnamed this object or used the wrong mount point object (got %i faces)\n",
     126                groupName.c_str(), (*groupIt)._faces.size());
     127    }
     128
     129    // now iterate through all faces
     130    std::vector<StaticModelData::Face>::const_iterator faceIt = (*groupIt)._faces.begin();
     131    for( int i = 0; faceIt < (*groupIt)._faces.end(); faceIt++)
     132    {
     133      if( (*faceIt)._elements.size() == 3)
     134      {
     135        triangle[i++] = (*faceIt);
    120136      }
    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++)
     137    }
     138
     139
     140    Vector center;
     141    Vector xAxis;
     142    Vector yAxis;
     143    Vector zAxis;
     144    // now process all points
     145    for( int i = 0; i < 3; i++)
     146    {
     147      // convert the float vertices to vectors
     148      Vector a( this->data->getVertices()[triangle[i]._elements[0].vertexNumber * 3],
     149                this->data->getVertices()[triangle[i]._elements[0].vertexNumber * 3 + 1],
     150                this->data->getVertices()[triangle[i]._elements[0].vertexNumber * 3 + 2]);
     151      Vector b( this->data->getVertices()[triangle[i]._elements[1].vertexNumber * 3],
     152                this->data->getVertices()[triangle[i]._elements[1].vertexNumber * 3 + 1],
     153                this->data->getVertices()[triangle[i]._elements[1].vertexNumber * 3 + 2]);
     154      Vector c( this->data->getVertices()[triangle[i]._elements[2].vertexNumber * 3],
     155                this->data->getVertices()[triangle[i]._elements[2].vertexNumber * 3 + 1],
     156                this->data->getVertices()[triangle[i]._elements[2].vertexNumber * 3 + 2]);
     157
     158      Vector ab = a - b;
     159      Vector ac = a - c;
     160      Vector bc = b - c;
     161
     162      Vector  axis1;
     163      Vector  axis2;
     164      // now find the center point (the one with the 90degree angle)
     165      if( fabs(ab.dot( ac)) < 0.0001)
    125166      {
    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         }
     167        center = a;
     168        axis1 = b - a;
     169        axis2 = c - a;
    135170      }
    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++)
     171      else if( fabs(ab.dot(bc)) < 0.0001)
    144172      {
    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         }
     173        center = b;
     174        axis1 = a - b;
     175        axis2 = c - b;
    159176      }
    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 
     177      else if( fabs(bc.dot(ac)) < 0.0001)
     178      {
     179        center = c;
     180        axis1 = b - c;
     181        axis2 = a - c;
     182      }
     183
     184
     185      // get the longest axis (without defining a max() funciton :D
     186      if( xAxis.len() < axis1.len() )
     187        xAxis = axis1;
     188      if( xAxis.len() < axis2.len())
     189        xAxis = axis2;
     190
     191
     192      // find the 2nd longest axis to be y-axis
     193      if( xAxis.len() > axis1.len() && yAxis.len() < axis1.len())
     194        yAxis = axis1;
     195      if( xAxis.len() > axis2.len() && yAxis.len() < axis2.len())
     196        yAxis = axis2;
     197
     198
     199      // needed... no explanation here..
     200      if( zAxis.len() == 0.)
     201        zAxis = yAxis;
     202
     203      // find the shortest axis to be z-axis
     204      if( yAxis.len() > axis1.len() )
     205        zAxis = axis1;
     206      if( yAxis.len() > axis2.len() )
     207        zAxis = axis2;
    170208    }
    171209
     210    // now add the mount point
     211     this->addMountPoint( zAxis, yAxis, center, groupName);
    172212  }
    173 
    174 
    175213}
    176214
  • trunk/src/lib/graphics/importer/static_model.h

    r10147 r10314  
    5858
    5959  void finalize();
    60   void extractMountPoints();
     60  virtual void extractMountPoints();
    6161
    6262  void acquireData(const StaticModelData::Pointer& data);
     
    7171private:
    7272  void updateBase();
     73
     74
    7375private:
    7476  StaticModelData::Pointer         data;
  • trunk/src/lib/math/vector.h

    r9110 r10314  
    4747  /** @param v: the Vecor to compare with this one @returns true, if the Vecors are different, false otherwise */
    4848  inline bool operator!= (const Vector& v) const { return (this->x!=v.x||this->y!=v.y||this->z!=v.z)?true:false; };
     49  inline bool operator> (const Vector& v) const  { return (this->len() > v.len()); }
     50  inline bool operator< (const Vector& v) const  { return (this->len() < v.len()); }
     51
    4952  /** @param index The index of the "array" @returns the x/y/z coordinate */
    5053  inline float operator[] (float index) const {if( index == 0) return this->x; if( index == 1) return this->y; if( index == 2) return this->z; }
     
    8285  inline const Vector& operator= (const sVec3D& v) { this->x = v[0]; this->y = v[1]; this->z = v[2]; return *this; }
    8386  inline const Vector& operator= (const float* v) { this->x = v[0]; this->y = v[1]; this->z = v[2]; return *this; }
     87
     88  /** this operator can be used to assign values to the vector */
     89  inline void operator() (float x, float y, float z) { this->x = x; this->y = y; this->z = z;}
     90
     91
     92
     93
    8494  /** @param v: the other vector \return the dot product of the vectors */
    8595  float dot (const Vector& v) const { return x*v.x+y*v.y+z*v.z; };
  • trunk/src/story_entities/game_world.cc

    r10013 r10314  
    1111   ### File Specific:
    1212   main-programmer: Patrick Boenzli
     13   main-programmer: Benjamin Grauer
    1314   co-programmer: Christian Meyer
    14    co-programmer: Benjamin Grauer
     15
    1516*/
    1617
     
    7374SHELL_COMMAND(togglePNodeVisibility, GameWorld, togglePNodeVisibility);
    7475SHELL_COMMAND(showBVLevel, GameWorld, toggleBVVisibility);
     76SHELL_COMMAND(showMountPoints, GameWorld, toggleMPVisibility);
    7577
    7678
     
    8890  this->showBV = false;
    8991  this->showBVLevel = 3;
     92  this->showMPV = false;
    9093
    9194  this->dataXML = NULL;
     
    541544  ObjectManager::EntityList::const_iterator entity;
    542545  for (entity = drawList.begin(); entity != drawList.end(); entity++)
     546  {
    543547    if ((*entity)->isVisible())
    544548      (*entity)->draw();
     549
     550    if( unlikely( this->showMPV))
     551      (*entity)->debugDrawMountPoints();
     552  }
    545553}
    546554
     
    666674    }
    667675
     676
    668677    if( unlikely(this->showPNodes))
    669678      PNode::getNullParent()->debugDraw(0);
  • trunk/src/story_entities/game_world.h

    r9869 r10314  
    6262  void togglePNodeVisibility();
    6363  void toggleBVVisibility(int level);
     64  inline void toggleMPVisibility() { this->showMPV = !this->showMPV; }
    6465
    6566  inline void setSky(WorldEntity* sky) { this->dataTank->sky = sky; }
     
    99100  bool                showBV;                       //!< if the Bounding Volumes should be visible.
    100101  int                 showBVLevel;                  //!< the depth level of the displayed bounding volumes
     102  bool                showMPV;                      //!< true if the mounting points should be drawn for debug purposes
    101103
    102104  /* world timing */
  • trunk/src/story_entities/movie_loader.cc

    r10114 r10314  
    6363
    6464
    65 ErrorMessage MovieLoader::init() {}
     65ErrorMessage MovieLoader::init() {  return ErrorMessage();}
    6666
    6767
    68 ErrorMessage MovieLoader::loadData() {}
     68ErrorMessage MovieLoader::loadData() {  return ErrorMessage();}
    6969
    7070
     
    7272{
    7373  this->unsubscribeEvents(ES_GAME);
     74
     75  return ErrorMessage();
    7476}
    7577
     
    8284  this->bRunning = true;
    8385  this->run();
     86
     87  return true;
    8488}
    8589
     
    8993
    9094  this->bRunning = false;
     95
     96  return true;
    9197}
    9298
    93 bool MovieLoader::pause() { }
    94 bool MovieLoader::resume() { }
     99bool MovieLoader::pause() { return false; }
     100bool MovieLoader::resume() { return false; }
    95101
    96102void MovieLoader::run()
  • trunk/src/world_entities/mount_point.cc

    r10147 r10314  
    1010
    1111   ### File Specific
    12    main-programmer: Patrick Boenzli patrick@orxonox.net
     12   main-programmer: Patrick Boenzli, patrick@orxonox.net
    1313   co-programmer:
    1414*/
     
    1919#include "util/loading/factory.h"
    2020#include "util/loading/load_param.h"
     21#include "util/loading/load_param_xml.h"
     22
    2123
    2224
     
    2729
    2830ObjectListDefinition(MountPoint);
    29 CREATE_FACTORY(MountPoint);
    3031
    3132
     
    3334 * construct
    3435 */
    35 MountPoint::MountPoint ()
    36 {
     36MountPoint::MountPoint (const Vector& up, const Vector& forward, const Vector& center, const std::string& name)
     37{
     38  PRINTF(5)("Created mount point %s\n", name.c_str());
     39
     40  this->_name = name;
     41  this->setAbsCoor( center);
     42  this->setAbsDir( Quaternion(forward, up));
     43
    3744  this->init();
    3845}
    3946
    40 
    41 /**
    42  * constructor
    43  * @param root the xml root element
    44  */
    45 MountPoint::MountPoint(const TiXmlElement* root)
    46 {
    47   this->init();
    48 
    49   if( root != NULL)
    50     this->loadParams(root);
    51 }
    5247
    5348
     
    7570 * @param root the XML-element to load the MD2Creature's properties from
    7671 */
    77 void MountPoint::loadParams(const TiXmlElement* root)
    78 {
    79   WorldEntity::loadParams(root);
     72void MountPoint::initMountPoint(const TiXmlElement* root)
     73{
     74  if( root == NULL)
     75  {
     76    PRINTF(1)("MountPoint - initialization failed, since I got no valid xml element\n");
     77    return;
     78  }
     79  // now get the first element
     80  const TiXmlElement* element = root->FirstChildElement("MountPoints");
     81  if( element == NULL)
     82  {
     83    PRINTF(1)("I am in section: %s, Object Information file is missing a proper 'MountPoints' section\n", root->Value());
     84//     element = root->FirstChildElement( );
     85//     PRINTF(0)("first child: %s\n", element->Value());
     86  }
     87  else
     88  {
     89    element = element->FirstChildElement();
     90    // parse the information for this mount point
     91
     92    PRINTF(4)("Loading WorldEntities\n");
     93    while( element != NULL)
     94    {
     95      std::string name = element->Value();
     96
     97      PRINTF(5)("checking %s against local %s\n", name.c_str(), this->_name.c_str());
     98      // check if we got the right mount point
     99      if( this->_name.find(name, 0) != std::string::npos)
     100      {
     101        PRINTF(5)("found mount point %s\n", this->_name.c_str());
     102        // load it
     103        this->loadParam(element);
     104      }
     105
     106      element = element->NextSiblingElement();
     107    }
     108  }
     109}
     110
     111
     112
     113/**
     114 * load the parameters from the xml section
     115 * @param root the root element of this xml branche
     116 */
     117void MountPoint::loadParam(const TiXmlElement* root)
     118{
     119  // first check for the description
     120  LoadParam(root, "Description", this, MountPoint, setDescription)
     121  .describe("Sets this mount point a description");
     122
     123  // now check for the orx class to create
     124  LoadParam(root, "OrxClass", this, MountPoint, setOrxClass)
     125  .describe("Sets the class this mount points should host");
     126
     127  LoadParamXML(root, "Details", this, MountPoint, loadDetails);
     128}
     129
     130
     131/**
     132 * load the parameters from the world entity
     133 * @param root the root element of this xml branche
     134 */
     135void MountPoint::loadDetails(const TiXmlElement* root)
     136{
     137  if( this->_mount != NULL)
     138  {
     139    PRINTF(0)("Got detail informations\n");
     140    this->_mount->loadParams( root);
     141  }
     142}
     143
     144
     145/**
     146 * setst the description (optional) via xml tag
     147 * @param description string containing the description
     148 */
     149void MountPoint::setDescription(const std::string& description)
     150{
     151  this->_description = description;
     152}
     153
     154
     155
     156/**
     157 * sets the class of this mount point
     158 * @param orxClass class
     159 */
     160void MountPoint::setOrxClass(const std::string& orxClass)
     161{
     162  // create the object for this mount point
     163  BaseObject* obj = Factory::fabricate(orxClass);
     164  // check if the object is created correctly
     165  if( obj != NULL)
     166  {
     167    if( obj->isA( WorldEntity::staticClassID()))
     168    {
     169      // cast down the object to WE
     170      this->_mount = dynamic_cast<WorldEntity*>(obj);
     171
     172      // now set the position, direction and reparent it to this node
     173      this->_mount->setAbsCoor( this->getAbsCoor());
     174      this->_mount->setAbsDir( this->getAbsDir());
     175      this->_mount->setParent( this);
     176
     177      this->_mount->toList( (OM_LIST)(this->getOMListNumber()+1));
     178    }
     179  }
     180  else
     181    PRINTF(1)("Couldn't create %s for this mount point (%s)\n", orxClass.c_str(), this->_name.c_str());
    80182}
    81183
     
    89191{
    90192
    91 
    92193}
    93194
     
    98199void MountPoint::draw() const
    99200{
    100 
    101201}
    102202
     
    108208void MountPoint::debugDraw() const
    109209{
    110 
     210  // invoke the underlying pnode debug draw
     211  this->debugDraw();
    111212}
    112213
  • trunk/src/world_entities/mount_point.h

    r10147 r10314  
    1212
    1313  public:
    14     MountPoint ();
    15     MountPoint(const TiXmlElement* root);
     14    MountPoint (const Vector& up, const Vector& forward, const Vector& center, const std::string& name);
    1615    virtual ~MountPoint ();
    1716
    1817    void init();
    19     virtual void loadParams(const TiXmlElement* root);
     18    void initMountPoint(const TiXmlElement* root);
     19    void loadParam(const TiXmlElement* root);
     20    void loadDetails(const TiXmlElement* root);
    2021
     22    void setDescription(const std::string& description);
     23    void setOrxClass(const std::string& orxClass);
    2124
    2225    virtual void tick (float time);
     
    3235  private:
    3336    WorldEntity*         _mount;       //!< the entity mounted at this mount point
     37    std::string          _name;        //!< the name of the mount point
     38
     39    std::string          _description; //!< string containing an optional description
    3440
    3541};
  • trunk/src/world_entities/world_entity.cc

    r10147 r10314  
    1212
    1313   ### File Specific:
    14    main-programmer: Patrick Boenzli, Benjamin Grauer
    15    co-programmer: Christian Meier
     14   main-programmer: Patrick Boenzli
     15   main-programmer: Benjamin Grauer
     16   co-programmer:   Christian Meier
    1617*/
    1718#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
     
    7374  this->scaling = 1.0f;
    7475  this->oiFile = NULL;
     76  // add 10 members to this array
     77  this->mountPoints.reserve(10);
    7578
    7679  /* OSOLETE */
     
    141144  .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)")
    142145  .defaultValues("", 1.0f, 0);
     146
     147  LoadParam(root, "mountpoints", this, WorldEntity, loadMountPoints)
     148  .describe("the fileName of the object information file (optional)");
    143149
    144150  LoadParam(root, "maxHealth", this, WorldEntity, setHealthMax)
     
    204210      StaticModel* model = new StaticModel();
    205211      *model = ResourceOBJ(fileName, this->scaling);
     212
     213      // check if ther is a valid model and load other stuff
    206214      if (model->getVertexCount() > 0)
    207215      {
    208216        this->setModel(model, modelNumber);
    209         if( modelNumber == 0 /* FIXME && !this->isA(CL_WEAPON) */)
     217
     218        if( modelNumber == 0)
     219        {
    210220          this->buildObbTree(obbTreeDepth);
     221        }
    211222      }
    212223      else
    213224        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);
    218225    }
    219226    /// LOADING AN MD2-model
     
    269276 * @param fileName the name of the file
    270277 */
    271 void WorldEntity::loadObjectInformationFile(const std::string& fileName)
    272 {
    273   PRINTF(4)("loading the oif File: %s\n", fileName.c_str());
    274 
     278void WorldEntity::loadMountPoints(const std::string& fileName)
     279{
     280  PRINTF(5)("loading the oif File: %s\n", fileName.c_str());
     281
     282  // now load the object information file
    275283  this->oiFile = new ObjectInformationFile(fileName);
     284
     285  // get the model to load
     286  Model* model = this->getModel();
     287
     288  // extract the mount points
     289  model->extractMountPoints();
     290
     291  // first get all mount points from the model
     292  const std::list<mountPointSkeleton> mpList = model->getMountPoints();
     293  // for each skeleton create a mounting point world entity
     294  std::list<mountPointSkeleton>::const_iterator it = mpList.begin();
     295
     296  for( ; it != mpList.end(); it++)
     297  {
     298    // create the mount points world entity
     299    MountPoint* mp = new MountPoint( (*it).up, (*it).forward, (*it).center, (*it).name);
     300    // parent it to this WE
     301    mp->setParent( this);
     302    // now add to the right group
     303    mp->toList( (OM_LIST)(this->getOMListNumber()+1));
     304    // now get the number and add the mount point to the slot
     305    std::string nrStr = (*it).name.substr(3, 2);
     306    // add the mount point
     307    this->addMountPoint(atoi(nrStr.c_str()), mp);
     308
     309    // now fill the mount point
     310    mp->initMountPoint( this->oiFile->getMountPointDescription());
     311  }
     312
    276313}
    277314
     
    337374void WorldEntity::addMountPoint(int slot, MountPoint* mountPoint)
    338375{
    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());
     376  if( this->mountPoints.capacity() < (unsigned int)slot)
     377  {
     378    // reserve 5 more slots than needed so this function is called as rare as possible
     379    this->mountPoints.reserve(slot + 5);
     380  }
     381  else if( this->mountPoints[slot] != NULL)
     382  {
     383    PRINTF(4)("adding a mount point to a slot, that already is occupied! ignoring - maybe some object did not get connected well (object: %s)\n", this->getClassCName());
    342384  }
    343385
     
    794836
    795837
     838
     839/**
     840 * draw the mounting points
     841 */
     842void WorldEntity::debugDrawMountPoints() const
     843{
     844
     845  std::vector<MountPoint*>::const_iterator it = this->mountPoints.begin();
     846  for( ; it < this->mountPoints.end(); it++)
     847  {
     848    if( (*it) != NULL)
     849    {
     850      (*it)->debugDraw();
     851    }
     852  }
     853}
     854
     855
    796856/**
    797857 * Debug the WorldEntity
  • trunk/src/world_entities/world_entity.h

    r10147 r10314  
    5353  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
    5454
    55   void loadObjectInformationFile(const std::string& fileName);
     55  void loadMountPoints(const std::string& fileName);
    5656  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
    5757
     
    7373  virtual void tick (float time);
    7474  virtual void draw () const;
     75  void debugDrawMountPoints() const;
    7576
    7677  /* --- Collision Detection Block  --- */
Note: See TracChangeset for help on using the changeset viewer.