Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10314 in orxonox.OLD for trunk/src/lib/graphics


Ignore:
Timestamp:
Jan 24, 2007, 12:45:39 AM (18 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/lib/graphics/importer
Files:
12 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;
Note: See TracChangeset for help on using the changeset viewer.