2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
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
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include "token.h"
|
|
|
|
#include "joints.h"
|
|
|
|
#include "angles.h"
|
|
|
|
#include "inout.h"
|
|
|
|
|
|
|
|
char *SKEL_ROOT_NAMES[] =
|
|
|
|
{
|
|
|
|
"RAVEN_SPINE"
|
|
|
|
};
|
|
|
|
|
|
|
|
char *SKEL_NAMES[] =
|
|
|
|
{
|
|
|
|
"RAVEN_WAIST1",
|
|
|
|
"RAVEN_WAIST2",
|
|
|
|
"RAVEN_NECK"
|
|
|
|
};
|
|
|
|
|
|
|
|
int NAME_OFFSETS[] =
|
|
|
|
{
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int numJointsForSkeleton[] =
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
NUM_JOINTS_RAVEN,
|
|
|
|
NUM_JOINTS_BOX
|
|
|
|
};
|
|
|
|
|
|
|
|
float g_scaling[3];
|
|
|
|
float g_rotation[3];
|
|
|
|
float g_translation[3];
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// LoadHRCClustered
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void LoadHRCClustered( char *fileName, int **clusterList, int *num_verts, int skelType ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int i, j;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_OpenSource( fileName );
|
|
|
|
TK_FetchRequire( TK_HRCH );
|
|
|
|
TK_FetchRequire( TK_COLON );
|
|
|
|
TK_FetchRequire( TK_SOFTIMAGE );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_CLUSTERS );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( TK_Search( TK_CLUSTER_NAME ) != TK_EOF )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_STRING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numJointsForSkeleton[skelType]; ++i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( stricmp( tk_String, SKEL_NAMES[NAME_OFFSETS[skelType] + i] ) == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
i = -i + numJointsForSkeleton[skelType] - 1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_BeyondRequire( TK_NUM_CLUSTER_VERTICES, TK_INTNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
num_verts[i + 1] = tk_IntNumber;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
clusterList[i] = (int *) SafeMalloc( num_verts[i + 1] * sizeof( int ), "LoadHRCClustered" );
|
|
|
|
assert( clusterList[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
// currently this function is only called by LoadTriangleListClustered, which in turn is only
|
|
|
|
// called by Cmd_Base in qdata. This is where the only call to free for this memory is being made.
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_LBRACE );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < num_verts[i + 1]; ++j )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_INTNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
clusterList[i][j] = tk_IntNumber;
|
|
|
|
TK_Fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
num_verts[0] = numJointsForSkeleton[skelType];
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void LoadHRCGlobals( char *fileName ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int i;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_OpenSource( fileName );
|
|
|
|
TK_FetchRequire( TK_HRCH );
|
|
|
|
TK_FetchRequire( TK_COLON );
|
|
|
|
TK_FetchRequire( TK_SOFTIMAGE );
|
|
|
|
TK_Beyond( TK_MODEL );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_SCALING );
|
|
|
|
for ( i = 0; i < 3; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
g_scaling[i] = tk_FloatNumber;
|
|
|
|
TK_Fetch();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_ROTATION );
|
|
|
|
for ( i = 0; i < 3; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
g_rotation[i] = tk_FloatNumber;
|
|
|
|
TK_Fetch();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_TRANSLATION );
|
|
|
|
for ( i = 0; i < 3; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
g_translation[i] = tk_FloatNumber;
|
|
|
|
TK_Fetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ParseVec3( vec3_t in ){
|
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[1] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[2] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[0] = tk_FloatNumber;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ParseRotation3( vec3_t in ){
|
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[1] = -tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[2] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[0] = tk_FloatNumber;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ParseTranslation3( vec3_t in ){
|
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[1] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[2] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[0] = tk_FloatNumber;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void LoadHRCJointList( char *fileName, QDataJoint_t *jointList, int skelType ){
|
2007-11-04 03:34:51 +00:00
|
|
|
#define MAX_STACK 64
|
|
|
|
int i, j;
|
|
|
|
vec3_t curTranslation[MAX_STACK], curRotation[MAX_STACK], curScale[MAX_STACK];
|
|
|
|
int curCorrespondingJoint[MAX_STACK];
|
|
|
|
int currentStack = 0, stackSize;
|
|
|
|
int baseJoint;
|
|
|
|
float cx, sx, cy, sy, cz, sz;
|
|
|
|
float rx, ry, rz;
|
|
|
|
float x2, y2, z2;
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_OpenSource( fileName );
|
|
|
|
TK_FetchRequire( TK_HRCH );
|
|
|
|
TK_FetchRequire( TK_COLON );
|
|
|
|
TK_FetchRequire( TK_SOFTIMAGE );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_MODEL );
|
|
|
|
TK_Beyond( TK_MODEL );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/* while(1)
|
2012-03-17 20:01:54 +00:00
|
|
|
{
|
|
|
|
TK_Beyond(TK_MODEL);
|
|
|
|
TK_BeyondRequire(TK_NAME, TK_STRING);
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if(_stricmp(tk_String, SKEL_ROOT_NAMES[skelType]) == 0)
|
|
|
|
break;
|
|
|
|
}*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_SCALING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3( curScale[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_ROTATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseRotation3( curRotation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_TRANSLATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3( curTranslation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// account for global model translation
|
|
|
|
curTranslation[currentStack][1] += g_translation[0];
|
|
|
|
curTranslation[currentStack][2] += g_translation[1];
|
|
|
|
curTranslation[currentStack][0] += g_translation[2];
|
|
|
|
|
|
|
|
++currentStack;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < NUM_JOINTS_RAVEN; ++i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( 1 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_MODEL );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// TK_BeyondRequire(TK_NAME, TK_STRING);
|
|
|
|
|
|
|
|
// if(_stricmp(tk_String, SKEL_NAMES[NAME_OFFSETS[skelType]+i]) == 0)
|
2012-03-17 20:01:54 +00:00
|
|
|
break;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_SCALING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3( curScale[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_ROTATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseRotation3( curRotation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_TRANSLATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3( curTranslation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
curCorrespondingJoint[currentStack] = -1;
|
|
|
|
|
|
|
|
++currentStack;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_SCALING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3( curScale[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_ROTATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseRotation3( curRotation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
jointList[i].rotation[1] = curRotation[currentStack][1];
|
|
|
|
jointList[i].rotation[2] = curRotation[currentStack][2];
|
|
|
|
jointList[i].rotation[0] = curRotation[currentStack][0];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_TRANSLATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3( curTranslation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
jointList[i].placement.origin[1] = curTranslation[currentStack][1];
|
|
|
|
jointList[i].placement.origin[2] = curTranslation[currentStack][2];
|
|
|
|
jointList[i].placement.origin[0] = curTranslation[currentStack][0];
|
|
|
|
|
|
|
|
jointList[i].placement.direction[1] = 7.5;
|
|
|
|
jointList[i].placement.direction[2] = 0.0;
|
|
|
|
jointList[i].placement.direction[0] = 0.0;
|
|
|
|
|
|
|
|
jointList[i].placement.up[1] = 0.0;
|
|
|
|
jointList[i].placement.up[2] = 7.5;
|
|
|
|
jointList[i].placement.up[0] = 0.0;
|
|
|
|
|
|
|
|
curCorrespondingJoint[currentStack] = i;
|
|
|
|
|
|
|
|
++currentStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
stackSize = currentStack;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < NUM_JOINTS_RAVEN; ++i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
rx = jointList[i].rotation[0] * ANGLE_TO_RAD;
|
|
|
|
ry = jointList[i].rotation[1] * ANGLE_TO_RAD;
|
|
|
|
rz = jointList[i].rotation[2] * ANGLE_TO_RAD;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cx = cos( rx );
|
|
|
|
sx = sin( rx );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cy = cos( ry );
|
|
|
|
sy = sin( ry );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cz = cos( rz );
|
|
|
|
sz = sin( rz );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// y-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[i].placement.direction[0] * cy + jointList[i].placement.direction[2] * sy;
|
|
|
|
z2 = -jointList[i].placement.direction[0] * sy + jointList[i].placement.direction[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.direction[0] = x2;
|
|
|
|
jointList[i].placement.direction[2] = z2;
|
|
|
|
|
|
|
|
// y-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[i].placement.up[0] * cy + jointList[i].placement.up[2] * sy;
|
|
|
|
z2 = -jointList[i].placement.up[0] * sy + jointList[i].placement.up[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.up[0] = x2;
|
|
|
|
jointList[i].placement.up[2] = z2;
|
|
|
|
|
|
|
|
// z-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[i].placement.direction[0] * cz - jointList[i].placement.direction[1] * sz;
|
|
|
|
y2 = jointList[i].placement.direction[0] * sz + jointList[i].placement.direction[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.direction[0] = x2;
|
|
|
|
jointList[i].placement.direction[1] = y2;
|
|
|
|
|
|
|
|
// z-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[i].placement.up[0] * cz - jointList[i].placement.up[1] * sz;
|
|
|
|
y2 = jointList[i].placement.up[0] * sz + jointList[i].placement.up[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.up[0] = x2;
|
|
|
|
jointList[i].placement.up[1] = y2;
|
|
|
|
|
|
|
|
// x-axis rotation for direction vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = jointList[i].placement.direction[1] * cx - jointList[i].placement.direction[2] * sx;
|
|
|
|
z2 = jointList[i].placement.direction[1] * sx + jointList[i].placement.direction[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.direction[1] = y2;
|
|
|
|
jointList[i].placement.direction[2] = z2;
|
|
|
|
|
|
|
|
// x-axis rotation for up vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = jointList[i].placement.up[1] * cx - jointList[i].placement.up[2] * sx;
|
|
|
|
z2 = jointList[i].placement.up[1] * sx + jointList[i].placement.up[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.up[1] = y2;
|
|
|
|
jointList[i].placement.up[2] = z2;
|
|
|
|
|
|
|
|
// translate to position in model
|
|
|
|
jointList[i].placement.direction[0] += jointList[i].placement.origin[0];
|
|
|
|
jointList[i].placement.direction[1] += jointList[i].placement.origin[1];
|
|
|
|
jointList[i].placement.direction[2] += jointList[i].placement.origin[2];
|
|
|
|
|
|
|
|
// translate to position in model
|
|
|
|
jointList[i].placement.up[0] += jointList[i].placement.origin[0];
|
|
|
|
jointList[i].placement.up[1] += jointList[i].placement.origin[1];
|
|
|
|
jointList[i].placement.up[2] += jointList[i].placement.origin[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
baseJoint = NUM_JOINTS_RAVEN;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = stackSize /*NUM_JOINTS_RAVEN*/ - 1; i > 0; --i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
rx = curRotation[i - 1][0] * ANGLE_TO_RAD;
|
|
|
|
ry = curRotation[i - 1][1] * ANGLE_TO_RAD;
|
|
|
|
rz = curRotation[i - 1][2] * ANGLE_TO_RAD;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cx = cos( rx );
|
|
|
|
sx = sin( rx );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cy = cos( ry );
|
|
|
|
sy = sin( ry );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cz = cos( rz );
|
|
|
|
sz = sin( rz );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = i - 1; j < stackSize - 1; ++j )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
// y-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.origin[0] * cy + jointList[j].placement.origin[2] * sy;
|
|
|
|
z2 = -jointList[j].placement.origin[0] * sy + jointList[j].placement.origin[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.origin[0] = x2;
|
|
|
|
jointList[j].placement.origin[2] = z2;
|
|
|
|
|
|
|
|
// y-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.direction[0] * cy + jointList[j].placement.direction[2] * sy;
|
|
|
|
z2 = -jointList[j].placement.direction[0] * sy + jointList[j].placement.direction[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.direction[0] = x2;
|
|
|
|
jointList[j].placement.direction[2] = z2;
|
|
|
|
|
|
|
|
// y-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.up[0] * cy + jointList[j].placement.up[2] * sy;
|
|
|
|
z2 = -jointList[j].placement.up[0] * sy + jointList[j].placement.up[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.up[0] = x2;
|
|
|
|
jointList[j].placement.up[2] = z2;
|
|
|
|
|
|
|
|
// z-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.origin[0] * cz - jointList[j].placement.origin[1] * sz;
|
|
|
|
y2 = jointList[j].placement.origin[0] * sz + jointList[j].placement.origin[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.origin[0] = x2;
|
|
|
|
jointList[j].placement.origin[1] = y2;
|
|
|
|
|
|
|
|
// z-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.direction[0] * cz - jointList[j].placement.direction[1] * sz;
|
|
|
|
y2 = jointList[j].placement.direction[0] * sz + jointList[j].placement.direction[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.direction[0] = x2;
|
|
|
|
jointList[j].placement.direction[1] = y2;
|
|
|
|
|
|
|
|
// z-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.up[0] * cz - jointList[j].placement.up[1] * sz;
|
|
|
|
y2 = jointList[j].placement.up[0] * sz + jointList[j].placement.up[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.up[0] = x2;
|
|
|
|
jointList[j].placement.up[1] = y2;
|
|
|
|
|
|
|
|
// x-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = jointList[j].placement.origin[1] * cx - jointList[j].placement.origin[2] * sx;
|
|
|
|
z2 = jointList[j].placement.origin[1] * sx + jointList[j].placement.origin[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.origin[1] = y2;
|
|
|
|
jointList[j].placement.origin[2] = z2;
|
|
|
|
|
|
|
|
// x-axis rotation for direction vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = jointList[j].placement.direction[1] * cx - jointList[j].placement.direction[2] * sx;
|
|
|
|
z2 = jointList[j].placement.direction[1] * sx + jointList[j].placement.direction[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.direction[1] = y2;
|
|
|
|
jointList[j].placement.direction[2] = z2;
|
|
|
|
|
|
|
|
// x-axis rotation for up vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = jointList[j].placement.up[1] * cx - jointList[j].placement.up[2] * sx;
|
|
|
|
z2 = jointList[j].placement.up[1] * sx + jointList[j].placement.up[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.up[1] = y2;
|
|
|
|
jointList[j].placement.up[2] = z2;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( curCorrespondingJoint[j + 1] != -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// translate origin
|
2012-03-17 20:01:54 +00:00
|
|
|
jointList[j].placement.origin[0] += curTranslation[i - 1][0];
|
|
|
|
jointList[j].placement.origin[1] += curTranslation[i - 1][1];
|
|
|
|
jointList[j].placement.origin[2] += curTranslation[i - 1][2];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// translate back to local coord
|
2012-03-17 20:01:54 +00:00
|
|
|
jointList[j].placement.direction[0] += curTranslation[i - 1][0];
|
|
|
|
jointList[j].placement.direction[1] += curTranslation[i - 1][1];
|
|
|
|
jointList[j].placement.direction[2] += curTranslation[i - 1][2];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// translate back to local coord
|
2012-03-17 20:01:54 +00:00
|
|
|
jointList[j].placement.up[0] += curTranslation[i - 1][0];
|
|
|
|
jointList[j].placement.up[1] += curTranslation[i - 1][1];
|
|
|
|
jointList[j].placement.up[2] += curTranslation[i - 1][2];
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void LoadGlobals( char *fileName ){
|
2007-11-04 03:34:51 +00:00
|
|
|
FILE *file1;
|
2012-03-17 20:01:54 +00:00
|
|
|
int dot = '.';
|
2007-11-04 03:34:51 +00:00
|
|
|
char *dotstart;
|
2012-03-17 20:01:54 +00:00
|
|
|
char InputFileName[256];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dotstart = strrchr( fileName,dot ); // Does it already have an extension on the file name?
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !dotstart ) {
|
|
|
|
strcpy( InputFileName, fileName );
|
|
|
|
strcat( InputFileName, ".hrc" );
|
|
|
|
if ( ( file1 = fopen( InputFileName, "rb" ) ) != NULL ) {
|
|
|
|
fclose( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadHRCGlobals( InputFileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( " - assuming .HRC\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "\n Could not open file '%s':\n"
|
|
|
|
"No HRC match.\n", fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( file1 = fopen( fileName, "rb" ) ) != NULL ) {
|
|
|
|
printf( "\n" );
|
|
|
|
fclose( file1 );
|
|
|
|
if ( strcmp( dotstart,".hrc" ) == 0 || strcmp( dotstart,".HRC" ) == 0 ) {
|
|
|
|
LoadHRCGlobals( fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "Could not open file '%s':\n",fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void LoadClusters( char *fileName, int **clusterList, int *num_verts, int skelType ){
|
2007-11-04 03:34:51 +00:00
|
|
|
FILE *file1;
|
2012-03-17 20:01:54 +00:00
|
|
|
int dot = '.';
|
2007-11-04 03:34:51 +00:00
|
|
|
char *dotstart;
|
2012-03-17 20:01:54 +00:00
|
|
|
char InputFileName[256];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dotstart = strrchr( fileName,dot ); // Does it already have an extension on the file name?
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !dotstart ) {
|
|
|
|
strcpy( InputFileName, fileName );
|
|
|
|
strcat( InputFileName, ".hrc" );
|
|
|
|
if ( ( file1 = fopen( InputFileName, "rb" ) ) != NULL ) {
|
|
|
|
fclose( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadHRCClustered( InputFileName, clusterList, num_verts, skelType );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( " - assuming .HRC\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "\n Could not open file '%s':\n"
|
|
|
|
"No HRC match.\n", fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( file1 = fopen( fileName, "rb" ) ) != NULL ) {
|
|
|
|
printf( "\n" );
|
|
|
|
fclose( file1 );
|
|
|
|
if ( strcmp( dotstart,".hrc" ) == 0 || strcmp( dotstart,".HRC" ) == 0 ) {
|
|
|
|
LoadHRCClustered( fileName, clusterList, num_verts, skelType );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "Could not open file '%s':\n",fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void LoadJointList( char *fileName, QDataJoint_t *jointList, int skelType ){
|
2007-11-04 03:34:51 +00:00
|
|
|
FILE *file1;
|
2012-03-17 20:01:54 +00:00
|
|
|
int dot = '.';
|
2007-11-04 03:34:51 +00:00
|
|
|
char *dotstart;
|
2012-03-17 20:01:54 +00:00
|
|
|
char InputFileName[256];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dotstart = strrchr( fileName,dot ); // Does it already have an extension on the file name?
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !dotstart ) {
|
|
|
|
strcpy( InputFileName, fileName );
|
|
|
|
strcat( InputFileName, ".hrc" );
|
|
|
|
if ( ( file1 = fopen( InputFileName, "rb" ) ) != NULL ) {
|
|
|
|
fclose( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadHRCJointList( InputFileName, jointList, skelType );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( " - assuming .HRC\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "\n Could not open file '%s':\n"
|
|
|
|
"No HRC.\n", fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( file1 = fopen( fileName, "rb" ) ) != NULL ) {
|
|
|
|
printf( "\n" );
|
|
|
|
fclose( file1 );
|
|
|
|
if ( strcmp( dotstart,".hrc" ) == 0 || strcmp( dotstart,".HRC" ) == 0 ) {
|
|
|
|
LoadHRCJointList( fileName, jointList, skelType );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "Could not open file '%s':\n",fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|