2012-05-11 12:22:10 +00:00
|
|
|
/*
|
|
|
|
r_iqm.c
|
|
|
|
|
|
|
|
Shared IQM rendering support
|
|
|
|
|
|
|
|
Copyright (C) 2012 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2012/5/11
|
|
|
|
|
|
|
|
This program 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.
|
|
|
|
|
|
|
|
This program 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 this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/skin.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "r_internal.h"
|
|
|
|
|
|
|
|
float
|
|
|
|
R_IQMGetLerpedFrames (entity_t *ent, iqm_t *iqm)
|
|
|
|
{
|
2021-07-22 06:39:28 +00:00
|
|
|
animation_t *animation = &ent->animation;
|
2021-03-09 14:52:40 +00:00
|
|
|
int frame = ent->animation.frame;
|
2012-05-11 12:22:10 +00:00
|
|
|
float time, fullinterval;
|
|
|
|
iqmanim *anim;
|
|
|
|
|
2012-05-19 12:26:11 +00:00
|
|
|
if (!iqm->num_anims)
|
2021-07-22 06:39:28 +00:00
|
|
|
return R_EntityBlend (animation, 0, 1.0 / 25.0);
|
2012-05-11 12:22:10 +00:00
|
|
|
if (frame >= iqm->num_anims || frame < 0) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_dev, "R_IQMGetLerpedFrames: no such frame %d\n",
|
2012-05-11 12:22:10 +00:00
|
|
|
frame);
|
|
|
|
frame = 0;
|
|
|
|
}
|
|
|
|
anim = &iqm->anims[frame];
|
|
|
|
fullinterval = anim->num_frames / anim->framerate;
|
2021-07-22 06:39:28 +00:00
|
|
|
time = vr_data.realtime + ent->animation.syncbase;
|
2012-05-11 12:22:10 +00:00
|
|
|
time -= ((int) (time / fullinterval)) * fullinterval;
|
|
|
|
frame = (int) (time * anim->framerate) + anim->first_frame;
|
2021-07-22 06:39:28 +00:00
|
|
|
return R_EntityBlend (animation, frame, 1.0 / anim->framerate);
|
2012-05-11 12:22:10 +00:00
|
|
|
}
|
2012-05-16 08:44:18 +00:00
|
|
|
|
|
|
|
iqmframe_t *
|
2012-05-17 06:57:07 +00:00
|
|
|
R_IQMBlendFrames (const iqm_t *iqm, int frame1, int frame2, float blend,
|
|
|
|
int extra)
|
2012-05-16 08:44:18 +00:00
|
|
|
{
|
|
|
|
iqmframe_t *frame;
|
|
|
|
int i;
|
|
|
|
|
2021-07-28 06:01:45 +00:00
|
|
|
frame = Hunk_TempAlloc (0, iqm->num_joints * sizeof (iqmframe_t) + extra);
|
2012-05-19 12:26:11 +00:00
|
|
|
if (iqm->num_frames) {
|
2012-05-16 08:44:18 +00:00
|
|
|
#if 0
|
2012-05-19 12:26:11 +00:00
|
|
|
for (i = 0; i < iqm->num_joints; i++) {
|
|
|
|
iqmframe_t *f1 = &iqm->frames[frame1][i];
|
|
|
|
iqmframe_t *f2 = &iqm->frames[frame2][i];
|
|
|
|
DualQuatBlend (f1->rt, f2->rt, blend, frame[i].rt);
|
|
|
|
QuatBlend (f1->shear, f2->shear, blend, frame[i].shear);
|
|
|
|
QuatBlend (f1->scale, f2->scale, blend, frame[i].scale);
|
|
|
|
}
|
2012-05-16 08:44:18 +00:00
|
|
|
#else
|
2012-05-19 12:26:11 +00:00
|
|
|
for (i = 0; i < iqm->num_joints; i++) {
|
|
|
|
iqmframe_t *f1 = &iqm->frames[frame1][i];
|
|
|
|
iqmframe_t *f2 = &iqm->frames[frame2][i];
|
|
|
|
iqmjoint *j = &iqm->joints[i];
|
|
|
|
Mat4Blend ((float *) f1, (float *) f2, blend, (float*)&frame[i]);
|
|
|
|
if (j->parent >= 0)
|
|
|
|
Mat4Mult ((float*)&frame[j->parent],
|
|
|
|
(float*)&frame[i], (float*)&frame[i]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
#if 0
|
|
|
|
for (i = 0; i < iqm->num_joints; i++) {
|
2018-10-12 05:33:55 +00:00
|
|
|
QuatSet (0, 0, 0, 1, frame[i].rt.q0.q);
|
2012-05-19 12:26:11 +00:00
|
|
|
QuatSet (0, 0, 0, 0, frame[i].rt.qe.q);
|
|
|
|
QuatSet (0, 0, 0, 0, frame[i].shear);
|
|
|
|
QuatSet (1, 1, 1, 0, frame[i].scale);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
for (i = 0; i < iqm->num_joints; i++) {
|
|
|
|
Mat4Identity ((float*)&frame[i]);
|
|
|
|
}
|
2012-05-16 08:44:18 +00:00
|
|
|
#endif
|
2012-05-19 12:26:11 +00:00
|
|
|
}
|
2012-05-16 08:44:18 +00:00
|
|
|
return frame;
|
|
|
|
}
|
2012-05-18 15:34:15 +00:00
|
|
|
|
|
|
|
iqmframe_t *
|
|
|
|
R_IQMBlendPalette (const iqm_t *iqm, int frame1, int frame2, float blend,
|
|
|
|
int extra, iqmblend_t *blend_palette, int palette_size)
|
|
|
|
{
|
|
|
|
iqmframe_t *frame;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
extra += (palette_size - iqm->num_joints) * sizeof (iqmframe_t);
|
|
|
|
frame = R_IQMBlendFrames (iqm, frame1, frame2, blend, extra);
|
|
|
|
for (i = iqm->num_joints; i < palette_size; i++) {
|
|
|
|
vec_t *mat = (vec_t *) &frame[i];
|
|
|
|
iqmblend_t *blend = &blend_palette[i];
|
|
|
|
vec_t *f;
|
|
|
|
|
|
|
|
f = (vec_t *) &frame[blend->indices[0]];
|
|
|
|
Mat4Scale (f, blend->weights[0] / 255.0, mat);
|
|
|
|
for (j = 1; j < 4; j++) {
|
|
|
|
if (!blend->weights[j])
|
|
|
|
break;
|
|
|
|
f = (vec_t *) &frame[blend->indices[j]];
|
|
|
|
Mat4MultAdd (mat, blend->weights[j] / 255.0, f, mat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|