From 709d152a5f0f9d5669dac70e0fc9c7f0e9507daa Mon Sep 17 00:00:00 2001 From: divverent Date: Thu, 22 Oct 2009 07:19:57 +0000 Subject: [PATCH] change cl_lerping interpolation model from euler angles interpolation to forward/up vector interpolation to prevent problems near the singularity of euler angles git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9375 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cl_main.c b/cl_main.c index bf4d1d80..ef74fd14 100644 --- a/cl_main.c +++ b/cl_main.c @@ -864,7 +864,7 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat const matrix4x4_t *matrix; matrix4x4_t blendmatrix, tempmatrix, matrix2; int j, k, l, frame; - float origin[3], angles[3], delta[3], lerp, d; + float origin[3], angles[3], lerp, d; entity_t *t; dp_model_t *model; //entity_persistent_t *p = &e->persistent; @@ -960,11 +960,23 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat // interpolate the origin and angles lerp = max(0, lerp); VectorLerp(e->persistent.oldorigin, lerp, e->persistent.neworigin, origin); +#if 0 + // this fails at the singularity of euler angles VectorSubtract(e->persistent.newangles, e->persistent.oldangles, delta); if (delta[0] < -180) delta[0] += 360;else if (delta[0] >= 180) delta[0] -= 360; if (delta[1] < -180) delta[1] += 360;else if (delta[1] >= 180) delta[1] -= 360; if (delta[2] < -180) delta[2] += 360;else if (delta[2] >= 180) delta[2] -= 360; VectorMA(e->persistent.oldangles, lerp, delta, angles); +#else + { + vec3_t f0, u0, f1, u1; + AngleVectors(e->persistent.oldangles, f0, NULL, u0); + AngleVectors(e->persistent.newangles, f1, NULL, u1); + VectorMAM(1-lerp, f0, lerp, f1, f0); + VectorMAM(1-lerp, u0, lerp, u1, u0); + AnglesFromVectors(angles, f0, u0, false); + } +#endif } else { -- 2.39.2