Skip to content

Commit

Permalink
character: Fix motion vector calculation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
virtuoso committed Oct 6, 2024
1 parent 540bb36 commit 532432f
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions core/character.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down

0 comments on commit 532432f

Please sign in to comment.