Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8597 in orxonox.OLD


Ignore:
Timestamp:
Jun 20, 2006, 1:22:54 AM (18 years ago)
Author:
patrick
Message:

bsp: md3 child models work started

Location:
branches/bsp_model/src/lib/graphics/importer/md3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_data.cc

    r8590 r8597  
    6262
    6363/**
    64  * link a model at the specified tag position to this model. if the position is allready
     64 * link a model at the specified tag position to this model. if the position is already
    6565 * occupied, the old submodel will be replaced
    6666 *
     
    7373  child->parentTagIndex = tagIndex;
    7474}
     75
     76
     77
     78/**
     79 * Return the index of the tag with the given name for this model.
     80 *
     81 * This will return -1 if their is no such tag.
     82 */
     83 int MD3Data::getTagIndexByName(std::string tagName)
     84{
     85   int res = -1;
     86
     87   if( this->header->boneFrameNum > 0) {
     88     MD3Tag** tags = this->boneFrames[0]->tags;
     89     for( int i = 0; i < this->header->tagNum; i++)
     90       if( tags[i]->name.find(tagName) == std::string::npos)
     91         return i;
     92   }
     93
     94   return res;
     95 }
     96
    7597
    7698
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_data.h

    r8566 r8597  
    7777
    7878      void addLinkedModel(int tagIndex, MD3Data* child);
    79 
     79      int getTagIndexByName(std::string name);
    8080
    8181    private:
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_model.cc

    r8592 r8597  
    102102    if( lower != NULL)
    103103    {
    104       PRINTF(0)("Loaded the %s model\n", nameLower.c_str());
    105 //       this->md3Data->addLinkedModel(0, lower);
     104      int tag = this->md3Data->getTagIndexByName("tag_lower");
     105      PRINTF(0)("Loaded the %s model on index %i\n", nameLower.c_str(), tag);
     106      if( tag >= 0)
     107       this->md3Data->addLinkedModel(tag, lower);
     108      else
     109        PRINTF(0)("Could not add %s\n", nameLower.c_str());
    106110    }
    107111
     
    110114    std::string nameHead(filename + "/head.md3");
    111115    MD3Data* head = (MD3Data*)ResourceManager::getInstance()->load(nameHead, MD3, RP_GAME, nameLower, scaling);
    112     if( lower != NULL)
    113     {
    114       PRINTF(0)("Loaded the %s model\n", nameHead.c_str());
    115 //       this->md3Data->addLinkedModel(0, head);
    116     }
    117 
    118 
    119 
    120 
    121     // load torso
    122 //     name = FilenameUtils.getShortFilename(root.loadFilename);
    123 //     if( name.find("lower") == 0 && (tagIndex=root.getTagIndexByName("tag_torso")) != -1) {
    124 //       filename=searchForPath("upper" + FilenameUtils.getLODPostfix(name) + ".md3", false);
    125 //       root=attachModel(root, tagIndex, filename, getInputStreamForPath(filename));
    126 //     }
    127 
    128     // load head
    129 //     name=FilenameUtils.getShortFilename(root.loadFilename);
    130 //     if (name.toLowerCase().startsWith("upper") && (tagIndex=root.getTagIndexByName("tag_head")) != -1) {
    131 //       filename=searchForPath("head" + FilenameUtils.getLODPostfix(name) + ".md3", false);
    132 //       attachModel(root, tagIndex, filename, getInputStreamForPath(filename));
    133 //     }
    134 
    135   }
    136 
    137 
    138 
     116    if( head != NULL)
     117    {
     118      int tag = this->md3Data->getTagIndexByName("tag_head");
     119      PRINTF(0)("Loaded the %s model on index %i\n", nameHead.c_str(), tag);
     120      if( tag >= 0)
     121        this->md3Data->addLinkedModel(tag, head);
     122      else
     123        PRINTF(0)("Could not add %s\n", nameHead.c_str());
     124    }
     125
     126  }
     127
     128
     129
     130  /**
     131   * tick float
     132   * @param time: time elapsed
     133   */
    139134  void MD3Model::tick(float time)
    140135  {
     
    144139
    145140
     141  /**
     142   * tick each data
     143   */
    146144  void MD3Model::tick(float time, MD3Data* data)
    147145  {
     
    210208
    211209      //build transformation array m from matrix, interpolate if necessary
    212       float* m = new float[16];
    213210
    214211      MD3Tag* currFrameTag = data->boneFrames[data->animationState.currentFrame]->tags[child->parentTagIndex];
     
    218215        //we need to interpolate
    219216        MD3Tag* nextFrameTag = data->boneFrames[data->animationState.nextFrame]->tags[child->parentTagIndex];
    220         m = this->interpolateTransformation(currFrameTag, nextFrameTag, data->animationState.interpolationFraction, i);
    221           }
    222           else {
    223             //no interpolation needed, stay with last transformation
    224             //OpenGL matrix is in column-major order
    225             m[0] = currFrameTag->matrix[0][0];
    226             m[1] = currFrameTag->matrix[1][0];
    227             m[2] = currFrameTag->matrix[2][0];
    228             m[3] = 0.0f;
    229             m[4] = currFrameTag->matrix[0][1];
    230             m[5] = currFrameTag->matrix[1][1];
    231             m[6] = currFrameTag->matrix[2][1];
    232             m[7] = 0.0f;
    233             m[8] = currFrameTag->matrix[0][2];
    234             m[9] = currFrameTag->matrix[1][2];
    235             m[10]= currFrameTag->matrix[2][2];
    236             m[11]= 0.0f;
    237             m[12] = currFrameTag->position.x;
    238             m[13] = currFrameTag->position.y;
    239             m[14] = currFrameTag->position.z;
    240             m[15] = 1.0f;
    241           }
    242 
    243           //switch to child coord system
    244           glPushMatrix();
    245           glMultMatrixf(m);
    246 
    247           // and draw child
    248           this->tick(time, child);
    249 
    250           glPopMatrix();
    251           i++;
     217        this->tmpMatrix[i] = this->interpolateTransformation(currFrameTag, nextFrameTag, data->animationState.interpolationFraction, i);
     218      }
     219      else
     220      {
     221        //no interpolation needed, stay with last transformation
     222        //OpenGL matrix is in column-major order
     223        this->tmpMatrix[i][0] = currFrameTag->matrix[0][0];
     224        this->tmpMatrix[i][1] = currFrameTag->matrix[1][0];
     225        this->tmpMatrix[i][2] = currFrameTag->matrix[2][0];
     226        this->tmpMatrix[i][3] = 0.0f;
     227        this->tmpMatrix[i][4] = currFrameTag->matrix[0][1];
     228        this->tmpMatrix[i][5] = currFrameTag->matrix[1][1];
     229        this->tmpMatrix[i][6] = currFrameTag->matrix[2][1];
     230        this->tmpMatrix[i][7] = 0.0f;
     231        this->tmpMatrix[i][8] = currFrameTag->matrix[0][2];
     232        this->tmpMatrix[i][9] = currFrameTag->matrix[1][2];
     233        this->tmpMatrix[i][10]= currFrameTag->matrix[2][2];
     234        this->tmpMatrix[i][11]= 0.0f;
     235        this->tmpMatrix[i][12] = currFrameTag->position.x;
     236        this->tmpMatrix[i][13] = currFrameTag->position.y;
     237        this->tmpMatrix[i][14] = currFrameTag->position.z;
     238        this->tmpMatrix[i][15] = 1.0f;
     239      }
     240
     241      // switch to child coord system
     242
     243      // and tick child
     244      this->tick(time, child);
     245
     246      i++;
     247      it++;
    252248    }
    253249  }
     
    327323      MD3Data* child = it->second;
    328324
    329       //build transformation array m from matrix, interpolate if necessary
    330       float* m = new float[16];
    331 
    332       MD3Tag* currFrameTag = data->boneFrames[data->animationState.currentFrame]->tags[child->parentTagIndex];
    333 
    334       if( data->animationState.interpolationFraction != 0.0 &&
    335           data->animationState.currentFrame != data->animationState.nextFrame) {
    336         //we need to interpolate
    337         m = this->tmpMatrix[i];
    338       }
    339       else {
    340         //no interpolation needed, stay with last transformation
    341         //OpenGL matrix is in column-major order
    342         m[0] = currFrameTag->matrix[0][0];
    343         m[1] = currFrameTag->matrix[1][0];
    344         m[2] = currFrameTag->matrix[2][0];
    345         m[3] = 0.0f;
    346         m[4] = currFrameTag->matrix[0][1];
    347         m[5] = currFrameTag->matrix[1][1];
    348         m[6] = currFrameTag->matrix[2][1];
    349         m[7] = 0.0f;
    350         m[8] = currFrameTag->matrix[0][2];
    351         m[9] = currFrameTag->matrix[1][2];
    352         m[10]= currFrameTag->matrix[2][2];
    353         m[11]= 0.0f;
    354         m[12] = currFrameTag->position.x;
    355         m[13] = currFrameTag->position.y;
    356         m[14] = currFrameTag->position.z;
    357         m[15] = 1.0f;
    358       }
    359 
    360325      //switch to child coord system
    361326      glPushMatrix();
    362       glMultMatrixf(m);
     327      glMultMatrixf(this->tmpMatrix[i]);
    363328
    364329      // and draw child
     
    367332      glPopMatrix();
    368333      i++;
     334      it++;
    369335    }
    370336  }
  • branches/bsp_model/src/lib/graphics/importer/md3/md3_model.h

    r8591 r8597  
    6161    bool                bDrawNormals;      //!< draw the normals
    6262
     63    MD3AnimationCfg*    config;            //!< the config file parsed
     64
    6365    MD3BoneFrame*       tmpBoneFrame;      //!< a temporary bone frame
    6466    sVec3D**            tmpMesh;           //!< a temporary mesh frame
     
    6668    float**             tmpMatrix;         //!< a temporary matrix
    6769
    68     MD3AnimationCfg*    config;            //!< the config file parsed
    6970};
    7071
Note: See TracChangeset for help on using the changeset viewer.