From 09031d209d5fa10c4ea27de734b7ec3e544f0817 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Fri, 20 Jun 2025 03:09:06 +0200 Subject: [PATCH] Interpolate rotations --- TODO.txt | 9 +++++---- game.h | 8 ++++++++ racing.h | 36 +++++++++++++++++++++++------------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/TODO.txt b/TODO.txt index bed7bba..67b0e7a 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,10 +2,7 @@ fuck issue trackers :D =========== GENERAL ============== -- stop playing engine sound when replay finishes - LCR_SETTING_TEXTURE_SUBSAMPLE = 0 should turn off texturing completely -- maybe address the jerky rotations? or not? -- add (digital) controller support to SDL and CSFML? - frontends: - auto test frontend, with no I/O, that will just internally run a series of inputs and check if the output is as expected @@ -17,7 +14,7 @@ fuck issue trackers :D - linux framebuffer? - make some kinda repo for world record runs? how will they submit it? - final tests: - - check every single setting individually + - check every single setting individually DID 1x - very long replay DID 1x - absence of music file - different resolutions KINDA DID 1x @@ -86,6 +83,10 @@ fuck issue trackers :D theory they should (enough block space to load): try to set the exact same settings on PC and see if the maps load or what. IT'S BCS BUILDING THE MAP TEMPORARILY REQUIRES MORE BLOCKS +- maybe address the jerky rotations? or not? +- stop playing engine sound when replay finishes +- add (digital) controller support to SDL and CSFML? NOT NOW, doesn't wanna + detect it or something (or either PC) - on arduinos for some reason straight triangles (floor, walls, ...) on map don't fucking display, they seem to not be added at all, but maybe it's something with the "instability" due to low memory... HOWEVER on ringo (enough diff --git a/game.h b/game.h index ffc9d8c..83d862f 100644 --- a/game.h +++ b/game.h @@ -1865,6 +1865,14 @@ uint8_t LCR_gameStep(uint32_t time) int engineIntensity = LCR_carSpeedKMH() * 2; + if (LCR_game.state == LCR_GAME_STATE_RUN_FINISHED) + { + engineIntensity -= LCR_game.time - LCR_game.stateStartTime; + + if (engineIntensity < 0) + engineIntensity = 0; + } + LCR_audioSetEngineIntensity(paused ? 0 : (engineIntensity < 256 ? engineIntensity : 255)); diff --git a/racing.h b/racing.h index 1f9615c..ff529a9 100644 --- a/racing.h +++ b/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;