Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6222 in orxonox.OLD for trunk/src/lib/graphics/importer


Ignore:
Timestamp:
Dec 21, 2005, 1:49:06 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the christmas branche to the trunk
merged with command:
svn merge -r6165:HEAD christmas_branche/ ../trunk/
no conflicts

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore set to
      Makefile.in
      Makefile
      configure
      *.kdevelop
      Doxyfile
      config.log
      config.h
      config.status
      stamp-h1
      autom4te.cache
      aclocal.m4
  • trunk/src

    • Property svn:ignore set to
      .deps
      orxonox
      Makefile
      Makefile.in

  • trunk/src/lib

    • Property svn:ignore set to
      Makefile
      Makefile.in
      .deps
      libORXlibs.a
  • trunk/src/lib/graphics

    • Property svn:ignore set to
      Makefile
      Makefile.in
      .deps
      libORX*

  • trunk/src/lib/graphics/importer

    • Property svn:ignore set to
      Makefile
      Makefile.in
      .deps
      libORX*

  • trunk/src/lib/graphics/importer/md2Model.cc

    r6022 r6222  
    2121#include "resource_manager.h"
    2222
    23 //#include <fstream>
    24 
    2523
    2624using namespace std;
     
    3634};
    3735
    38 //! again one of these strange id software parts
    39 static float *shadeDots = MD2Model::anormsDots[0];
    4036
    4137//! the angle under which the model is viewd, used internaly
     
    4642sAnim MD2Model::animationList[21] =
    4743  {
    48  // begin, end, fps
    49     {   0,  39,  9 },   //!< STAND
    50     {  40,  45, 10 },   //!< RUN
    51     {  46,  53, 10 },   //!< ATTACK
    52     {  54,  57,  7 },   //!< PAIN_A
    53     {  58,  61,  7 },   //!< PAIN_B
    54     {  62,  65,  7 },   //!< PAIN_C
    55     {  66,  71,  7 },   //!< JUMP
    56     {  72,  83,  7 },   //!< FLIP
    57     {  84,  94,  7 },   //!< SALUTE
    58     {  95, 111, 10 },   //!< FALLBACK
    59     { 112, 122,  7 },   //!< WAVE
    60     { 123, 134,  6 },   //!< POINTT
    61     { 135, 153, 10 },   //!< CROUCH_STAND
    62     { 154, 159,  7 },   //!< CROUCH_WALK
    63     { 160, 168, 10 },   //!< CROUCH_ATTACK
    64     { 196, 172,  7 },   //!< CROUCH_PAIN
    65     { 173, 177,  5 },   //!< CROUCH_DEATH
    66     { 178, 183,  7 },   //!< DEATH_FALLBACK
    67     { 184, 189,  7 },   //!< DEATH_FALLFORWARD
    68     { 190, 197,  7 },   //!< DEATH_FALLBACKSLOW
    69     { 198, 198,  5 },   //!< BOOM
     44 // begin, end, fps, interruptable
     45    {   0,  39,  9, 1 },   //!< STAND
     46    {  40,  45, 10, 1 },   //!< RUN
     47    {  46,  53, 10, 0 },   //!< ATTACK
     48    {  54,  57,  7, 1 },   //!< PAIN_A
     49    {  58,  61,  7, 1 },   //!< PAIN_B
     50    {  62,  65,  7, 1 },   //!< PAIN_C
     51    {  66,  71,  7, 0 },   //!< JUMP
     52    {  72,  83,  7, 1 },   //!< FLIP
     53    {  84,  94,  7, 1 },   //!< SALUTE
     54    {  95, 111, 10, 1 },   //!< FALLBACK
     55    { 112, 122,  7, 1 },   //!< WAVE
     56    { 123, 134,  6, 1 },   //!< POINTT
     57    { 135, 153, 10, 1 },   //!< CROUCH_STAND
     58    { 154, 159,  7, 1 },   //!< CROUCH_WALK
     59    { 160, 168, 10, 1 },   //!< CROUCH_ATTACK
     60    { 196, 172,  7, 1 },   //!< CROUCH_PAIN
     61    { 173, 177,  5, 0 },   //!< CROUCH_DEATH
     62    { 178, 183,  7, 0 },   //!< DEATH_FALLBACK
     63    { 184, 189,  7, 0 },   //!< DEATH_FALLFORWARD
     64    { 190, 197,  7, 0 },   //!< DEATH_FALLBACKSLOW
     65    { 198, 198,  5, 1 },   //!< BOOM
    7066  };
    7167
     
    8783
    8884  this->scaleFactor = this->data->scaleFactor;
     85
     86  shadeDots = MD2Model::anormsDots[0];
     87  /* set the animation stat mannualy */
     88  this->animationState.type = STAND;
     89  this->animationState.numPlays = 1;
    8990  this->setAnim(STAND);
     91
     92  this->debug();
    9093}
    9194
     
    103106/**
    104107 *  initializes an array of vert with the current frame scaled vertices
    105  * @param verticesList: the list of vertices to interpolate between
     108 * @param this->verticesList: the list of vertices to interpolate between
    106109
    107110   we won't use the pVertices array directly, since its much easier and we need
    108111   saving of data anyway
    109112*/
    110 void MD2Model::interpolate(sVec3D* verticesList)
     113void MD2Model::interpolate(/*sVec3D* this->verticesList*/)
    111114{
    112115  sVec3D* currVec;
     
    118121  for( int i = 0; i < this->data->numVertices; ++i)
    119122    {
    120       verticesList[i][0] = currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0]);
    121       verticesList[i][1] = currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1]);
    122       verticesList[i][2] = currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2]);
     123      this->verticesList[i][0] = currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0]);
     124      this->verticesList[i][1] = currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1]);
     125      this->verticesList[i][2] = currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2]);
    123126    }
    124127}
     
    135138  if( (type < 0) || (type > MAX_ANIMATIONS) )
    136139    type = STAND;
     140
     141  if( MD2Model::animationList[this->animationState.type].bStoppable == 0)
     142  {
     143    if( this->animationState.numPlays == 0 )
     144      return;
     145  }
    137146
    138147  this->animationState.startFrame = animationList[type].firstFrame;
     
    141150  this->animationState.fps = animationList[type].fps;
    142151  this->animationState.type = type;
     152  this->animationState.numPlays = 0;
    143153
    144154  this->animationState.interpolationState = 0.0f;
     
    155165void MD2Model::tick(float time)
    156166{
    157   this->animationState.localTime += time;
     167  this->animate(time);
     168  this->processLighting();
     169  this->interpolate(/*this->verticesList*/);
    158170}
    159171
     
    164176 * FIXME
    165177 */
    166 void MD2Model::draw()
    167 {
    168   if( likely(this->animationState.localTime > 0.0))
    169     this->animate();
    170 
     178void MD2Model::draw() const
     179{
    171180  glPushMatrix();
    172 
    173181  this->renderFrame();
    174 
     182  // renderFrameTriangles();
    175183  glPopMatrix();
    176184}
     
    180188  \brief this is an internal function to render this special frame selected by animate()
    181189*/
    182 void MD2Model::renderFrame()
    183 {
    184   static sVec3D verticesList[MD2_MAX_VERTICES]; /* performance: created only once in a lifetime */
     190void MD2Model::renderFrame() const
     191{
    185192  int* pCommands = this->data->pGLCommands;
    186193
     
    191198  glCullFace(GL_BACK);
    192199
    193   this->processLighting();
    194   this->interpolate(verticesList);
    195200  this->data->material->select();
    196201
     
    208213        }
    209214
    210 
    211215      for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */
    212216        {
    213217          glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] );
    214218          glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]);
    215           glVertex3fv(verticesList[pCommands[2]]);
     219          glVertex3fv(this->verticesList[pCommands[2]]);
    216220        }
    217221      glEnd();
     
    223227
    224228
     229void MD2Model::renderFrameTriangles() const
     230{
     231  //static sVec3D this->verticesList[MD2_MAX_VERTICES]; /* performance: created only once in a lifetime */
     232  int* pCommands = this->data->pGLCommands;
     233  /* some face culling stuff */
     234//   glPushAttrib(GL_POLYGON_BIT);
     235//   glFrontFace(GL_CW);
     236//   glEnable(GL_CULL_FACE);
     237//   glCullFace(GL_BACK);
     238//
     239//   this->processLighting();
     240//   this->interpolate(/*this->verticesList*/);
     241  this->data->material->select();
     242
     243  /* draw the triangles */
     244  glBegin(GL_TRIANGLES);
     245
     246  for( int i = 0, k = 0; i < this->data->numTriangles; ++i, k += 3)
     247  {
     248    float* v = this->data->pVertices[this->data->pTriangles[i].indexToVertices[0]];
     249
     250    printf("triangle: %i\n", i);
     251    printf("     v0: (%f, %f, %f)\n", v[0], v[1], v[2]);
     252    v = this->data->pVertices[this->data->pTriangles[i].indexToVertices[1]];
     253    printf("     v1: (%f, %f, %f)\n", v[0], v[1], v[2]);
     254    v = this->data->pVertices[this->data->pTriangles[i].indexToVertices[2]];
     255    printf("     v2: (%f, %f, %f)\n", v[0], v[1], v[2]);
     256
     257
     258    glNormal3f(anorms[i][0], anorms[i][1], anorms[i][2]);
     259    glVertex3fv(this->data->pVertices[this->data->pTriangles[i].indexToVertices[0]]);
     260
     261    glNormal3f(anorms[i][0], anorms[i][1], anorms[i][2]);
     262    glVertex3fv(this->data->pVertices[this->data->pTriangles[i].indexToVertices[1]]);
     263
     264    glNormal3f(anorms[i][0], anorms[i][1], anorms[i][2]);
     265    glVertex3fv(this->data->pVertices[this->data->pTriangles[i].indexToVertices[2]]);
     266  }
     267
     268  glEnd();
     269}
     270
     271
    225272/**
    226273  \brief animates the current model
     
    228275  depending on the time passed (tick function), the player will select another model
    229276*/
    230 void MD2Model::animate()
    231 {
     277void MD2Model::animate(float time)
     278{
     279  this->animationState.localTime += time;
     280
    232281  if( this->animationState.localTime - this->animationState.lastTime > (1.0f / this->animationState.fps))
    233282    {
     
    236285
    237286      if( this->animationState.nextFrame > this->animationState.endFrame)
     287      {
    238288        this->animationState.nextFrame = this->animationState.startFrame;
     289        this->animationState.numPlays++;
     290      }
    239291      this->animationState.lastTime = this->animationState.localTime;
    240292    }
     
    297349  this->numTexCoor = 0;
    298350
    299   this->scaleFactor = 0.2f;
     351//   this->scaleFactor = 1.0f;
     352  this->scaleFactor = 0.1f;
    300353
    301354  this->fileName = NULL;
     
    399452        {
    400453          /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)...  */
    401           pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor;
    402           pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor;
    403           pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor;
     454           pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor;
     455           pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor;
     456           pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor;
     457
     458          //printf("vertex %i/%i: (%f, %f, %f)\n", j, this->numVertices, pVertex[j][0], pVertex[j][1], pVertex[j][2]);
    404459
    405460          pNormals[j] = frame->pVertices[j].lightNormalIndex;
    406461        }
    407462    }
     463    PRINTF(4)("Finished loading the md2 file\n");
    408464
    409465  delete [] buffer;
  • trunk/src/lib/graphics/importer/md2Model.h

    r6022 r6222  
    6565};
    6666
     67
     68//! compressed vertex data: char insetead of float, the value will be expanded by the scale value. only for loading
     69typedef struct
     70{
     71  unsigned char    v[3];                 //!< the vector of the vertex
     72  unsigned char    lightNormalIndex;     //!< the index of the light normal
     73} sVertex;
     74
     75
     76//! compressed texture offset data: coords scaled by the texture size. Only for loading
     77typedef struct
     78{
     79  short            s;                    //!< the s,t coordinates of a texture
     80  short            t;                    //!< the s,t coordinates of a texture
     81} sTexCoor;
     82
     83
     84//! holds tha informations about a md2 frame
     85typedef struct
     86{
     87  sVec3D           scale;                //!< scales values of the model
     88  sVec3D           translate;            //!< translates the model
     89  char             name[16];             //!< frame name: something like "run32"
     90  sVertex          pVertices[1];         //!< first vertex of thes frame
     91} sFrame;
     92
     93
     94//! holds the information about a triangle
     95typedef struct
     96{
     97  unsigned short   indexToVertices[3];   //!< index to the verteces of the triangle
     98  unsigned short   indexToTexCoor[3];    //!< index to the texture coordinates
     99} sTriangle;
     100
     101
     102
     103//! the command list of the md2 model, very md2 specific
     104typedef struct
     105{
     106  float            s;                    //!< texture coordinate 1
     107  float            t;                    //!< texture coordinate 2
     108  int              vertexIndex;          //!< index of the vertex in the vertex list
     109} glCommandVertex;
     110
     111
     112//! a md2 animation definition
     113typedef struct
     114{
     115  int              firstFrame;           //!< first frame of the animation
     116  int              lastFrame;            //!< last frame of the animation
     117  int              fps;                  //!< speed: number of frames per second
     118  int              bStoppable;           //!< 1 if the animation is stoppable 0 else
     119} sAnim;
     120
     121
     122//! animation state definition
     123typedef struct
     124{
     125  int              startFrame;           //!< the start frame of an animation
     126  int              endFrame;             //!< last frame of the animation
     127  int              fps;                  //!< fps of the animaion (speed)
     128
     129  float            localTime;            //!< the local time
     130  float            lastTime;             //!< last time stamp
     131  float            interpolationState;   //!< the state of the animation [0..1]
     132
     133  int              type;                 //!< animation type
     134
     135  int              currentFrame;         //!< the current frame
     136  int              nextFrame;            //!< the next frame in the list
     137  int              numPlays;             //!< the number of times, this has been played in series
     138} sAnimState;
    67139
    68140
     
    143215  virtual ~MD2Model();
    144216
    145   void draw();
     217  virtual void draw() const;
     218  void renderFrameTriangles() const;
     219
    146220
    147221  void setAnim(int type);
    148   /**
    149    *  scales the current model
    150    * @param scaleFactor: the factor [0..1] to use for scaling
    151   */
     222  /**  returns the current animation @returns animation type */
     223  inline int MD2Model::getAnim() { return this->animationState.type; }
     224  /**  scales the current model @param scaleFactor: the factor [0..1] to use for scaling */
    152225  void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;}
    153226
    154   void tick(float dtS);
     227  virtual void tick(float dtS);
    155228  void debug();
    156229
    157230
    158231private:
    159   void animate();
     232  void animate(float time);
    160233  void processLighting();
    161   void interpolate(sVec3D* verticesList);
    162   void renderFrame();
     234  void interpolate(/*sVec3D* verticesList*/);
     235  void renderFrame() const ;
    163236
    164237
     
    168241  static float        anormsDots[SHADEDOT_QUANT][256];  //!< the anormals dot products
    169242  static sAnim        animationList[21];                //!< the anomation list
     243   //! again one of these strange id software parts
     244  float*              shadeDots;
    170245
    171246  MD2Data*            data;                             //!< the md2 data pointer
     
    174249  float               scaleFactor;                      //!< the scale factor (individual)
    175250  sAnimState          animationState;                   //!< animation state of the model
     251  sVec3D              verticesList[MD2_MAX_VERTICES];   //!< place to temp sav the vert
    176252};
    177253
  • trunk/src/lib/graphics/importer/model.h

    r6033 r6222  
    2929
    3030
    31 
    32 //! compressed vertex data: char insetead of float, the value will be expanded by the scale value. only for loading
    33 typedef struct
    34 {
    35   char             v[3];                 //!< the vector of the vertex
    36   unsigned char    lightNormalIndex;     //!< the index of the light normal
    37 } sVertex;
    38 
    39 
    40 //! compressed texture offset data: coords scaled by the texture size. Only for loading
    41 typedef struct
    42 {
    43   short            s;                    //!< the s,t coordinates of a texture
    44   short            t;                    //!< the s,t coordinates of a texture
    45 } sTexCoor;
    46 
    47 
    48 //! holds tha informations about a md2 frame
    49 typedef struct
    50 {
    51   sVec3D           scale;                //!< scales values of the model
    52   sVec3D           translate;            //!< translates the model
    53   char             name[16];             //!< frame name: something like "run32"
    54   sVertex          pVertices[1];         //!< first vertex of thes frame
    55 } sFrame;
    56 
    57 
    58 //! holds the information about a triangle
    59 typedef struct
    60 {
    61   unsigned short   indexToVertices[3];   //!< index to the verteces of the triangle
    62   unsigned short   indexToTexCoor[3];    //!< index to the texture coordinates
    63 } sTriangle;
    64 
    65 
    6631//! holds the information about a triangle
    6732typedef struct
     
    7237} sTriangleExt;
    7338
    74 
    75 //! the command list of the md2 model, very md2 specific
    76 typedef struct
    77 {
    78   float            s;                    //!< texture coordinate 1
    79   float            t;                    //!< texture coordinate 2
    80   int              vertexIndex;          //!< index of the vertex in the vertex list
    81 } glCommandVertex;
    82 
    83 
    84 //! a md2 animation definition
    85 typedef struct
    86 {
    87   int              firstFrame;           //!< first frame of the animation
    88   int              lastFrame;            //!< last frame of the animation
    89   int              fps;                  //!< speed: number of frames per second
    90 } sAnim;
    91 
    92 
    93 //! animation state definition
    94 typedef struct
    95 {
    96   int              startFrame;           //!< the start frame of an animation
    97   int              endFrame;             //!< last frame of the animation
    98   int              fps;                  //!< fps of the animaion (speed)
    99 
    100   float            localTime;            //!< the local time
    101   float            lastTime;             //!< last time stamp
    102   float            interpolationState;   //!< the state of the animation [0..1]
    103 
    104   int              type;                 //!< animation type
    105 
    106   int              currentFrame;         //!< the current frame
    107   int              nextFrame;            //!< the next frame in the list
    108 } sAnimState;
    10939
    11040//! Model Information definitions
     
    12252
    12353} modelInfo;
    124 
    12554
    12655
Note: See TracChangeset for help on using the changeset viewer.