added rotate keyword

backported zmodel rootbone manipulations so that scale/origin/rotate work more consistently (should fix problems with animations after the reference frame not being affected properly by scale)


git-svn-id: svn://svn.icculus.org/twilight/trunk/dpmodel@5569 d7cf8633-e32d-0410-b094-e92efae38249
This commit is contained in:
havoc 2005-08-11 07:58:33 +00:00
parent 5555f5a977
commit 3e53b6fc51

View file

@ -43,7 +43,7 @@ char scene_name_uppercase[MAX_FILEPATH];
FILE *headerfile = NULL;
double modelorigin[3], modelscale;
double modelorigin[3] = {0, 0, 0}, modelrotate = 0, modelscale = 1;
// this makes it keep all bones, not removing unused ones (as they might be used for attachments)
int keepallbones = 1;
@ -526,13 +526,6 @@ int parseskeleton(void)
printf("error: bone %i not defined\n", num);
return 0;
}
// root bones need to be offset
if (bones[num].parent < 0)
{
x = (x - modelorigin[0]) * modelscale;
y = (y - modelorigin[1]) * modelscale;
z = (z - modelorigin[2]) * modelscale;
}
// LordHavoc: compute matrix
frames[frame].bones[num] = computebonematrix(x, y, z, a, b, c);
}
@ -685,10 +678,6 @@ int parsetriangles(void)
printf("bone %i in triangle data is not defined\n", vbonenum);
return 0;
}
// apply model scaling and offset
org[0] = (org[0] - modelorigin[0]) * modelscale;
org[1] = (org[1] - modelorigin[1]) * modelscale;
org[2] = (org[2] - modelorigin[2]) * modelscale;
// untransform the origin and normal
inversetransform(org, bonematrix[vbonenum], vorigin);
inverserotate(normal, bonematrix[vbonenum], vnormal);
@ -966,6 +955,36 @@ int cleanupshadernames(void)
return 1;
}
void fixrootbones(void)
{
int i, j;
float cy, sy;
bonepose_t rootpose, temp;
cy = cos(modelrotate * M_PI / 180.0);
sy = sin(modelrotate * M_PI / 180.0);
rootpose.m[0][0] = cy * modelscale;
rootpose.m[1][0] = sy * modelscale;
rootpose.m[2][0] = 0;
rootpose.m[0][1] = -sy * modelscale;
rootpose.m[1][1] = cy * modelscale;
rootpose.m[2][1] = 0;
rootpose.m[0][2] = 0;
rootpose.m[1][2] = 0;
rootpose.m[2][2] = modelscale;
rootpose.m[0][3] = -modelorigin[0] * rootpose.m[0][0] + -modelorigin[1] * rootpose.m[1][0] + -modelorigin[2] * rootpose.m[2][0];
rootpose.m[1][3] = -modelorigin[0] * rootpose.m[0][1] + -modelorigin[1] * rootpose.m[1][1] + -modelorigin[2] * rootpose.m[2][1];
rootpose.m[2][3] = -modelorigin[0] * rootpose.m[0][2] + -modelorigin[1] * rootpose.m[1][2] + -modelorigin[2] * rootpose.m[2][2];
for (j = 0;j < numbones;j++)
{
if (bones[j].parent < 0)
{
// a root bone
for (i = 0;i < numframes;i++)
frames[i].bones[j] = concattransform(rootpose, frames[i].bones[j]);
}
}
}
char *token;
void inittokens(char *script)
@ -1188,6 +1207,17 @@ int sc_origin(void)
return 1;
}
int sc_rotate(void)
{
char *c = gettoken();
if (!c)
return 0;
if (!isdouble(c))
return 0;
modelrotate = atof(c);
return 1;
}
int sc_scale(void)
{
char *c = gettoken();
@ -1253,6 +1283,7 @@ sccommand sc_commands[] =
{"model", sc_model},
// {"texturedir", sc_texturedir},
{"origin", sc_origin},
{"rotate", sc_rotate},
{"scale", sc_scale},
{"scene", sc_scene},
{"#", sc_comment},
@ -1320,6 +1351,7 @@ void processscript(void)
freeframes();
return;
}
fixrootbones();
if (!convertmodel())
{
freeframes();