Interpolate rotations
This commit is contained in:
parent
f83e7f519d
commit
09031d209d
3 changed files with 36 additions and 17 deletions
36
racing.h
36
racing.h
|
@ -945,18 +945,27 @@ uint8_t _LCR_racingCollisionHandler(uint16_t b1, uint16_t j1, uint16_t b2,
|
|||
return 1;
|
||||
}
|
||||
|
||||
LCR_GameUnit _LCR_racingSmoothRot(LCR_GameUnit angleNew, LCR_GameUnit angleOld)
|
||||
LCR_GameUnit _LCR_racingInterpolateRot(LCR_GameUnit angleNew,
|
||||
LCR_GameUnit angleOld, LCR_GameUnit interpolationParam)
|
||||
{
|
||||
/* We'll smooth small rotations by averaging the last two angles; bigger
|
||||
rotations won't be smoothed -- firstly this removes lag for fast rotations
|
||||
and also deals with the issue of averaging e.g. 1 and 359 degrees. */
|
||||
angleNew %= LCR_GAME_UNIT;
|
||||
|
||||
if (angleNew < 0)
|
||||
angleNew += LCR_GAME_UNIT;
|
||||
|
||||
angleOld %= LCR_GAME_UNIT;
|
||||
|
||||
if (angleOld < 0)
|
||||
angleOld += LCR_GAME_UNIT;
|
||||
|
||||
LCR_GameUnit diff = angleNew - angleOld;
|
||||
|
||||
if (diff > LCR_GAME_UNIT / 8 || diff < -1 * LCR_GAME_UNIT / 8)
|
||||
return angleNew;
|
||||
LCR_GameUnit diff2 = (diff > 0) ?
|
||||
-1 * (LCR_GAME_UNIT - diff) :
|
||||
(LCR_GAME_UNIT + diff);
|
||||
|
||||
return angleOld + diff / 2;
|
||||
return angleOld + ((TPE_abs(diff) < TPE_abs(diff2) ?
|
||||
diff : diff2) * interpolationParam) / LCR_GAME_UNIT;
|
||||
}
|
||||
|
||||
TPE_Vec3 _LCR_racingGetWheelCenterPoint(void)
|
||||
|
@ -1121,12 +1130,13 @@ void LCR_racingGetCarTransform(LCR_GameUnit position[3],
|
|||
position[1] = v.y;
|
||||
position[2] = v.z;
|
||||
|
||||
rotation[0] = _LCR_racingSmoothRot(LCR_racing.carRotations[0].x,
|
||||
LCR_racing.carRotations[1].x);
|
||||
rotation[1] = _LCR_racingSmoothRot(LCR_racing.carRotations[0].y,
|
||||
LCR_racing.carRotations[1].y);
|
||||
rotation[2] = _LCR_racingSmoothRot(LCR_racing.carRotations[0].z,
|
||||
LCR_racing.carRotations[1].z);
|
||||
rotation[0] = _LCR_racingInterpolateRot(LCR_racing.carRotations[0].x,
|
||||
LCR_racing.carRotations[1].x,interpolationParam);
|
||||
rotation[1] = _LCR_racingInterpolateRot(LCR_racing.carRotations[0].y,
|
||||
LCR_racing.carRotations[1].y,interpolationParam);
|
||||
rotation[2] = _LCR_racingInterpolateRot(LCR_racing.carRotations[0].z,
|
||||
LCR_racing.carRotations[1].z,interpolationParam);
|
||||
|
||||
#else
|
||||
position[0] = LCR_racing.carPositions[0].x;
|
||||
position[1] = LCR_racing.carPositions[0].y;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue