Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 24, 2006, 12:47:07 PM (18 years ago)
Author:
bensch
Message:

merged back here the terrain.old

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/terrain/src/lib/graphics/importer/md2/md2Model.cc

    r9406 r9414  
    1717#include "md2Model.h"
    1818#include "material.h"
    19 
     19#include "config.h"
     20#ifdef HAVE_SDL_SDL_H
     21#include <SDL/SDL.h>
     22#include <SDL/SDL_endian.h>
     23#else
     24#include <SDL.h>
     25#include <SDL_endian.h>
     26#endif
    2027#include "debug.h"
    2128#include "util/loading/resource_manager.h"
     
    6774  };
    6875
    69 
     76#ifdef SDL_LIL_ENDIAN
     77#define BULK_CONV( _ptr, _num ) do { \
     78        int  _cnt = _num;\
     79        int* _iptr = (int*)_ptr;\
     80        for( int _l = 0; _l<_cnt; ++_l )\
     81                _iptr[_l] = SDL_SwapLE32( _iptr[_l] );\
     82} while( 0 )
     83#define BULK_CONV16( _ptr, _num ) do { \
     84        short  _cnt = _num;\
     85        short* _iptr = (short*)_ptr;\
     86        for( int _l = 0; _l<_cnt; ++_l )\
     87                _iptr[_l] = SDL_SwapLE16( _iptr[_l] );\
     88} while( 0 )
     89#else
     90#define BULK_CONV( _ptr, _num )
     91#define BULK_CONV16( _ptr, _num )
     92#endif
    7093
    7194/********************************************************************************
     
    468491  this->header = new MD2Header;
    469492  fread(this->header, 1, sizeof(MD2Header), pFile);
     493        BULK_CONV( this->header, sizeof(MD2Header)/4 );
    470494  /* check for the header version: make sure its a md2 file :) */
    471   if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))
     495  if( unlikely( this->header->version != MD2_VERSION) && unlikely( this->header->ident != MD2_IDENT))
    472496    {
    473497      PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
     
    475499    }
    476500
    477   this->fileName =fileName;
     501  this->fileName = fileName;
    478502  /* got the data: map it to locals */
    479503  this->numFrames = this->header->numFrames;
     
    494518  fseek(pFile, this->header->offsetFrames, SEEK_SET);
    495519  fread(buffer, this->header->frameSize, this->numFrames, pFile);
     520        //BULK_CONV( buffer, this->header->frameSize*this->numFrames*sizeof(char)/4 );
    496521  /* read opengl commands */
    497522  fseek(pFile, this->header->offsetGlCommands, SEEK_SET);
     523
    498524  fread(this->pGLCommands, sizeof(int), this->numGLCommands, pFile);
     525        BULK_CONV( this->pGLCommands, this->numGLCommands );
    499526  /* triangle list */
    500527  fseek(pFile, this->header->offsetTriangles, SEEK_SET);
    501   fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile);
     528  fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile);       
     529        BULK_CONV16( this->pTriangles, this->numTriangles*sizeof(sTriangle)/2 );
     530
    502531  /*  read in texture coordinates */
    503532  fseek(pFile, this->header->offsetTexCoords, SEEK_SET);
    504533  fread(this->pTexCoor, sizeof(sTexCoor), this->numTexCoor, pFile);
    505 
     534        BULK_CONV16( this->pTexCoor, this->numTexCoor*sizeof(sTexCoor)/2 );
    506535
    507536  for(int i = 0; i < this->numFrames; ++i)
    508537    {
    509538      frame = (sFrame*)(buffer + this->header->frameSize * i);
     539                        //Convert the translate and scale Vec3D if needed.
     540                        BULK_CONV( frame, 6 );
     541                        BULK_CONV( frame->pVertices, 3 );
    510542      pVertex = this->pVertices + this->numVertices  * i;
    511543      pNormals = this->pLightNormals + this->numVertices * i;
Note: See TracChangeset for help on using the changeset viewer.