void compute_arbitrary_spin(float frame_rate_hz, double timestamp, union quat *orientation, union quat *rotational_velocity) { /* reduce to axis and angle */ float x, y, z, a; quat_to_axis(rotational_velocity, &x, &y, &z, &a); /* current rotation is universe timestamp * rotation per timestamp rotational_velocity is frame_rate_hz and universe is 1/10 sec */ a = a * frame_rate_hz / (10.0 * frame_rate_hz / 30) * timestamp; quat_init_axis(orientation, x, y, z, a); }
/** * @brief RE_LerpTagET * @param[in,out] tag * @param[in] refent * @param[in] tagNameIn * @param[in] startIndex * @return */ int RE_LerpTagET(orientation_t *tag, const refEntity_t *refent, const char *tagNameIn, int startIndex) { mdvTag_t *start, *end; int i; float frontLerp, backLerp; model_t *model; char tagName[MAX_QPATH]; //, *ch; int retval = 0; qhandle_t handle; int startFrame, endFrame; float frac; handle = refent->hModel; startFrame = refent->oldframe; endFrame = refent->frame; frac = 1.0f - refent->backlerp; Q_strncpyz(tagName, tagNameIn, MAX_QPATH); /* // if the tagName has a space in it, then it is passing through the starting tag number if (ch = strrchr(tagName, ' ')) { *ch = 0; ch++; startIndex = atoi(ch); } */ model = R_GetModelByHandle(handle); /* if(!model->mdv[0]) //if(!model->model.md3[0] && !model->model.mdc[0] && !model->model.mds) { AxisClear(tag->axis); VectorClear(tag->origin); return -1; } */ frontLerp = frac; backLerp = 1.0f - frac; start = end = NULL; if (model->type == MOD_MESH) { // old MD3 style // FIXME: retval is reassigned before used, does it was intended ? retval = R_GetTag(model->mdv[0], startFrame, tagName, startIndex, &start); retval = R_GetTag(model->mdv[0], endFrame, tagName, startIndex, &end); } /* else if(model->type == MOD_MDS) { // use bone lerping retval = R_GetBoneTag(tag, model->model.mds, startIndex, refent, tagNameIn); if(retval >= 0) { return retval; } // failed return -1; } */ else if (model->type == MOD_MDM) { // use bone lerping retval = R_MDM_GetBoneTag(tag, model->mdm, startIndex, refent, tagNameIn); if (retval >= 0) { return retval; } // failed return -1; } #if defined(USE_REFENTITY_ANIMATIONSYSTEM) else if (model->type == MOD_MD5) { // Dushan: VS need this first vec3_t tmp; retval = RE_BoneIndex(handle, tagName); if (retval <= 0) { return -1; } VectorCopy(refent->skeleton.bones[retval].origin, tag->origin); quat_to_axis(refent->skeleton.bones[retval].rotation, tag->axis); VectorCopy(tag->axis[2], tmp); VectorCopy(tag->axis[1], tag->axis[2]); VectorCopy(tag->axis[0], tag->axis[1]); VectorCopy(tmp, tag->axis[0]); return retval; } #endif /* else { // psuedo-compressed MDC tags mdcTag_t *cstart, *cend; retval = R_GetMDCTag((byte *) model->model.mdc[0], startFrame, tagName, startIndex, &cstart); retval = R_GetMDCTag((byte *) model->model.mdc[0], endFrame, tagName, startIndex, &cend); // uncompress the MDC tags into MD3 style tags if(cstart && cend) { for(i = 0; i < 3; i++) { ustart.origin[i] = (float)cstart->xyz[i] * MD3_XYZ_SCALE; uend.origin[i] = (float)cend->xyz[i] * MD3_XYZ_SCALE; sangles[i] = (float)cstart->angles[i] * MDC_TAG_ANGLE_SCALE; eangles[i] = (float)cend->angles[i] * MDC_TAG_ANGLE_SCALE; } AnglesToAxis(sangles, ustart.axis); AnglesToAxis(eangles, uend.axis); start = &ustart; end = &uend; } else { start = NULL; end = NULL; } } */ if (!start || !end) { AxisClear(tag->axis); VectorClear(tag->origin); return -1; } for (i = 0; i < 3; i++) { tag->origin[i] = start->origin[i] * backLerp + end->origin[i] * frontLerp; tag->axis[0][i] = start->axis[0][i] * backLerp + end->axis[0][i] * frontLerp; tag->axis[1][i] = start->axis[1][i] * backLerp + end->axis[1][i] * frontLerp; tag->axis[2][i] = start->axis[2][i] * backLerp + end->axis[2][i] * frontLerp; } VectorNormalize(tag->axis[0]); VectorNormalize(tag->axis[1]); VectorNormalize(tag->axis[2]); return retval; }
void quat_to_axis_v(const union quat *q, union vec3 *v, float *a) { quat_to_axis(q, &v->v.x, &v->v.y, &v->v.z, a); }