7 #if defined (__linux__) || defined (__APPLE__)
\r
8 #define filelength Q_filelength
\r
12 ** MD3_ComputeTagFromTri
\r
14 void MD3_ComputeTagFromTri( md3Tag_t *pTag, const float pTri[3][3] )
\r
17 vec3_t axes[3], sides[3];
\r
18 int longestSide, shortestSide, hypotSide;
\r
23 memset( axes, 0, sizeof( axes ) );
\r
24 memset( sides, 0, sizeof( sides ) );
\r
29 for ( j = 0; j < 3; j++ )
\r
31 sides[j][0] = pTri[(j+1)%3][0] - pTri[j][0];
\r
32 sides[j][1] = pTri[(j+1)%3][1] - pTri[j][1];
\r
33 sides[j][2] = pTri[(j+1)%3][2] - pTri[j][2];
\r
35 len[j] = ( float ) sqrt( DotProduct( sides[j], sides[j] ) );
\r
39 if ( len[0] > len[1] && len[0] > len[2] )
\r
41 longestSide = 0; shortestSide = 1; origin = 2;
\r
43 else if ( len[1] > len[0] && len[1] > len[2] )
\r
45 longestSide = 1; shortestSide = 2; origin = 0;
\r
47 else if ( len[2] > len[0] && len[2] > len[1] )
\r
49 longestSide = 2; shortestSide = 0; origin = 1;
\r
53 Error( "invalid tag triangle, must be a right triangle with unequal length sides" );
\r
56 if ( len[0] > len[1] && len[0] > len[2] ) {
\r
59 } else if ( len[1] > len[0] && len[1] > len[2] ) {
\r
62 } else if ( len[2] > len[0] && len[2] > len[1] ) {
\r
66 len[hypotSide] = -1;
\r
68 if ( len[0] > len[1] && len[0] > len[2] ) {
\r
70 } else if ( len[1] > len[0] && len[1] > len[2] ) {
\r
72 } else if ( len[2] > len[0] && len[2] > len[1] ) {
\r
75 len[longestSide] = -1;
\r
77 if ( len[0] > len[1] && len[0] > len[2] ) {
\r
79 } else if ( len[1] > len[0] && len[1] > len[2] ) {
\r
81 } else if ( len[2] > len[0] && len[2] > len[1] ) {
\r
84 len[shortestSide] = -1;
\r
88 // VectorNormalize( sides[shortestSide], axes[0] );
\r
89 // VectorNormalize( sides[longestSide], axes[1] );
\r
90 VectorNormalize( sides[longestSide], axes[0] );
\r
91 VectorNormalize( sides[shortestSide], axes[1] );
\r
93 // project shortest side so that it is exactly 90 degrees to the longer side
\r
94 d = DotProduct( axes[0], axes[1] );
\r
95 VectorMA( axes[0], -d, axes[1], axes[0] );
\r
96 VectorNormalize( axes[0], axes[0] );
\r
98 CrossProduct( sides[longestSide], sides[shortestSide], axes[2] );
\r
99 VectorNormalize( axes[2], axes[2] );
\r
101 pTag->origin[0] = pTri[origin][0];
\r
102 pTag->origin[1] = pTri[origin][1];
\r
103 pTag->origin[2] = pTri[origin][2];
\r
105 VectorCopy( axes[0], pTag->axis[0] );
\r
106 VectorCopy( axes[1], pTag->axis[1] );
\r
107 VectorCopy( axes[2], pTag->axis[2] );
\r
115 void MD3_Dump( const char *filename )
\r
117 md3Header_t header;
\r
119 md3Surface_t *pSurface;
\r
126 if ( ( fp = fopen( filename, "rb" ) ) == 0 )
\r
128 Error( "Unable to open '%s'\n", filename );
\r
131 fileSize = filelength( fileno( fp ) );
\r
132 _buffer = malloc( filelength( fileno( fp ) ) );
\r
133 fread( _buffer, fileSize, 1, fp );
\r
136 buffer = ( char * ) _buffer;
\r
137 header = *( md3Header_t * ) _buffer;
\r
139 if ( header.ident != MD3_IDENT )
\r
141 Error( "Incorrect ident for '%s'\n", filename );
\r
144 printf( "Contents of '%s'\n", filename );
\r
145 printf( " version: %d\n", header.version );
\r
146 printf( " name: %s\n", header.name );
\r
147 printf( " num frames: %d\n", header.numFrames );
\r
148 printf( " num tags: %d\n", header.numTags );
\r
149 printf( " num surfaces: %d\n", header.numSurfaces );
\r
150 printf( " num skins: %d\n", header.numSkins );
\r
151 printf( " file size: %d\n", fileSize );
\r
153 printf( "--- TAGS ---\n" );
\r
154 pTag = ( md3Tag_t * ) ( ( ( char * ) buffer ) + header.ofsTags );
\r
155 for ( i = 0; i < header.numTags; i++, pTag++ )
\r
157 printf( " tag %d ('%s')\n", i, pTag->name );
\r
158 printf( " origin: %f,%f,%f\n", pTag->origin[0], pTag->origin[1], pTag->origin[2] );
\r
159 printf( " vf: %f,%f,%f\n", pTag->axis[0][0], pTag->axis[0][1], pTag->axis[0][2] );
\r
160 printf( " vr: %f,%f,%f\n", pTag->axis[1][0], pTag->axis[1][1], pTag->axis[1][2] );
\r
161 printf( " vu: %f,%f,%f\n", pTag->axis[2][0], pTag->axis[2][1], pTag->axis[2][2] );
\r
164 printf( "--- SURFACES ---\n" );
\r
165 pSurface = ( md3Surface_t * ) ( ( ( char * ) buffer ) + header.ofsSurfaces );
\r
167 for ( i = 0; i < header.numSurfaces; i++ )
\r
171 md3Shader_t *pShader = ( md3Shader_t * ) ( ( ( char * ) pSurface ) + pSurface->ofsShaders );
\r
173 printf( "\n surface %d ('%s')\n", i, pSurface->name );
\r
174 printf( " num frames: %d\n", pSurface->numFrames );
\r
175 printf( " num shaders: %d\n", pSurface->numShaders );
\r
176 printf( " num tris: %d\n", pSurface->numTriangles );
\r
177 printf( " num verts: %d\n", pSurface->numVerts );
\r
179 if ( pSurface->numShaders > 0 )
\r
181 printf( " --- SHADERS ---\n" );
\r
183 for ( j = 0; j < pSurface->numShaders; j++, pShader++ )
\r
185 printf( " shader %d ('%s')\n", j, pShader->name );
\r
188 pSurface = ( md3Surface_t * ) ( ( ( char * ) pSurface ) + pSurface->ofsEnd );
\r