From 532432ff8b611874bd8e9c86ff1c3f412263289b Mon Sep 17 00:00:00 2001 From: Alexander Shishkin Date: Sun, 6 Oct 2024 23:55:14 +0300 Subject: [PATCH] character: Fix motion vector calculation The motion vector calculation is broken in 2 places: first, the new coordinate system's unit vectors are scaled by the motion vector components twice, which resulted in an unintentionally convoluted unit vector calculation and as a byproduct resulted in slower diagonal motion. Fix this and make the end result actually make sense. Signed-off-by: Alexander Shishkin --- core/character.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/core/character.c b/core/character.c index 4938c4a..3e455ae 100644 --- a/core/character.c +++ b/core/character.c @@ -217,15 +217,9 @@ void character_move(struct character *ch, struct scene *s) err("no normal vector: is there collision?\n"); return; } - if (ch->angle[2] < 0) - dCalcVectorCross3(newz, newy, oldx); - else - dCalcVectorCross3(newz, oldx, newy); - if ((ch->angle[0] < 0) != (ch->angle[2] < 0)) - dCalcVectorCross3(newx, newz, newy); - else - dCalcVectorCross3(newx, newy, newz); + dCalcVectorCross3(newz, oldx, newy); + dCalcVectorCross3(newx, newy, newz); dSafeNormalize3(newx); dSafeNormalize3(newy); @@ -236,8 +230,6 @@ void character_move(struct character *ch, struct scene *s) vec3_scale(ch->angle, ch->angle, (float)gl_refresh_rate() / (float)s->fps.fps_fine); /* watch out for Y and Z swapping places */ - dScaleVector3(newx, ch->angle[0]); - dScaleVector3(newz, ch->angle[2]); dAddScaledVectors3(res, newx, newz, ch->angle[0], ch->angle[2]); // if (scene_camera_follows(s, ch)) {