X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=tools%2Fquake3%2Fq3data%2Fmd3lib.c;h=b4c7d93f4e454a56abb5e55fd6d05f6a55fa6bb1;hb=03be668aca6168191b9adca7aec905c01c436146;hp=aa277126bb2c607e7a1f62a489044a55e38bf27c;hpb=12b372f89ce109a4db9d510884fbe7d05af79870;p=xonotic%2Fnetradiant.git diff --git a/tools/quake3/q3data/md3lib.c b/tools/quake3/q3data/md3lib.c index aa277126..b4c7d93f 100644 --- a/tools/quake3/q3data/md3lib.c +++ b/tools/quake3/q3data/md3lib.c @@ -1,23 +1,23 @@ /* -Copyright (C) 1999-2006 Id Software, Inc. and contributors. -For a list of contributors, see the accompanying CONTRIBUTORS file. + Copyright (C) 1999-2006 Id Software, Inc. and contributors. + For a list of contributors, see the accompanying CONTRIBUTORS file. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ #include #ifdef WIN32 @@ -25,21 +25,22 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #endif #include "md3lib.h" -#if defined (__linux__) || defined (__APPLE__) -#define filelength Q_filelength +#if defined ( __linux__ ) || defined ( __APPLE__ ) +#define filelength(f) Q_filelength(f) +#else +#define filelength(f) filelength(fileno(f)) #endif /* ** MD3_ComputeTagFromTri */ -void MD3_ComputeTagFromTri( md3Tag_t *pTag, const float pTri[3][3] ) -{ - float len[3]; - vec3_t axes[3], sides[3]; - int longestSide, shortestSide, hypotSide; - int origin; - int j; - float d; +void MD3_ComputeTagFromTri( md3Tag_t *pTag, float pTri[3][3] ){ + float len[3]; + vec3_t axes[3], sides[3]; + int longestSide, shortestSide, hypotSide; + int origin; + int j; + float d; memset( axes, 0, sizeof( axes ) ); memset( sides, 0, sizeof( sides ) ); @@ -49,24 +50,21 @@ void MD3_ComputeTagFromTri( md3Tag_t *pTag, const float pTri[3][3] ) // for ( j = 0; j < 3; j++ ) { - sides[j][0] = pTri[(j+1)%3][0] - pTri[j][0]; - sides[j][1] = pTri[(j+1)%3][1] - pTri[j][1]; - sides[j][2] = pTri[(j+1)%3][2] - pTri[j][2]; + sides[j][0] = pTri[( j + 1 ) % 3][0] - pTri[j][0]; + sides[j][1] = pTri[( j + 1 ) % 3][1] - pTri[j][1]; + sides[j][2] = pTri[( j + 1 ) % 3][2] - pTri[j][2]; len[j] = ( float ) sqrt( DotProduct( sides[j], sides[j] ) ); } #if 0 - if ( len[0] > len[1] && len[0] > len[2] ) - { + if ( len[0] > len[1] && len[0] > len[2] ) { longestSide = 0; shortestSide = 1; origin = 2; } - else if ( len[1] > len[0] && len[1] > len[2] ) - { + else if ( len[1] > len[0] && len[1] > len[2] ) { longestSide = 1; shortestSide = 2; origin = 0; } - else if ( len[2] > len[0] && len[2] > len[1] ) - { + else if ( len[2] > len[0] && len[2] > len[1] ) { longestSide = 2; shortestSide = 0; origin = 1; } else @@ -77,10 +75,12 @@ void MD3_ComputeTagFromTri( md3Tag_t *pTag, const float pTri[3][3] ) if ( len[0] > len[1] && len[0] > len[2] ) { hypotSide = 0; origin = 2; - } else if ( len[1] > len[0] && len[1] > len[2] ) { + } + else if ( len[1] > len[0] && len[1] > len[2] ) { hypotSide = 1; origin = 0; - } else if ( len[2] > len[0] && len[2] > len[1] ) { + } + else if ( len[2] > len[0] && len[2] > len[1] ) { hypotSide = 2; origin = 1; } @@ -88,18 +88,22 @@ void MD3_ComputeTagFromTri( md3Tag_t *pTag, const float pTri[3][3] ) if ( len[0] > len[1] && len[0] > len[2] ) { longestSide = 0; - } else if ( len[1] > len[0] && len[1] > len[2] ) { + } + else if ( len[1] > len[0] && len[1] > len[2] ) { longestSide = 1; - } else if ( len[2] > len[0] && len[2] > len[1] ) { + } + else if ( len[2] > len[0] && len[2] > len[1] ) { longestSide = 2; } len[longestSide] = -1; if ( len[0] > len[1] && len[0] > len[2] ) { shortestSide = 0; - } else if ( len[1] > len[0] && len[1] > len[2] ) { + } + else if ( len[1] > len[0] && len[1] > len[2] ) { shortestSide = 1; - } else if ( len[2] > len[0] && len[2] > len[1] ) { + } + else if ( len[2] > len[0] && len[2] > len[1] ) { shortestSide = 2; } len[shortestSide] = -1; @@ -129,12 +133,11 @@ void MD3_ComputeTagFromTri( md3Tag_t *pTag, const float pTri[3][3] ) } /* -============== -MD3_Dump -============== -*/ -void MD3_Dump( const char *filename ) -{ + ============== + MD3_Dump + ============== + */ +void MD3_Dump( const char *filename ){ md3Header_t header; md3Tag_t *pTag; md3Surface_t *pSurface; @@ -144,21 +147,19 @@ void MD3_Dump( const char *filename ) long fileSize; int i; - if ( ( fp = fopen( filename, "rb" ) ) == 0 ) - { + if ( ( fp = fopen( filename, "rb" ) ) == 0 ) { Error( "Unable to open '%s'\n", filename ); } - fileSize = filelength( fileno( fp ) ); - _buffer = malloc( filelength( fileno( fp ) ) ); + fileSize = filelength( fp ); + _buffer = malloc( fileSize ); fread( _buffer, fileSize, 1, fp ); fclose( fp ); buffer = ( char * ) _buffer; header = *( md3Header_t * ) _buffer; - if ( header.ident != MD3_IDENT ) - { + if ( header.ident != MD3_IDENT ) { Error( "Incorrect ident for '%s'\n", filename ); } @@ -169,7 +170,7 @@ void MD3_Dump( const char *filename ) printf( " num tags: %d\n", header.numTags ); printf( " num surfaces: %d\n", header.numSurfaces ); printf( " num skins: %d\n", header.numSkins ); - printf( " file size: %d\n", fileSize ); + printf( " file size: %ld\n", fileSize ); printf( "--- TAGS ---\n" ); pTag = ( md3Tag_t * ) ( ( ( char * ) buffer ) + header.ofsTags ); @@ -197,8 +198,7 @@ void MD3_Dump( const char *filename ) printf( " num tris: %d\n", pSurface->numTriangles ); printf( " num verts: %d\n", pSurface->numVerts ); - if ( pSurface->numShaders > 0 ) - { + if ( pSurface->numShaders > 0 ) { printf( " --- SHADERS ---\n" ); for ( j = 0; j < pSurface->numShaders; j++, pShader++ ) @@ -211,4 +211,3 @@ void MD3_Dump( const char *filename ) free( _buffer ); } -