Fix some more stuff

This commit is contained in:
Miloslav Ciz 2024-09-11 02:12:04 +02:00
parent ffbe827f22
commit 4b9b6ad8ae
3 changed files with 33 additions and 66 deletions

View file

@ -27,7 +27,7 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_CAR_TURN_FRICTION (4 * TPE_F / 4) #define LCR_CAR_TURN_FRICTION (4 * TPE_F / 4)
#define LCR_CAR_ELASTICITY (TPE_F / 100) #define LCR_CAR_ELASTICITY (TPE_F / 100)
#define LCR_CAR_ACCELERATION (LCR_PHYSICS_UNIT / 15) #define LCR_CAR_ACCELERATION (LCR_PHYSICS_UNIT / 15)
#define LCR_CAR_TURN_SPEED (LCR_GAME_UNIT / 16) #define LCR_CAR_TURN_SPEED (LCR_GAME_UNIT / 20)
#define LCR_CAR_TURN_MAX (LCR_GAME_UNIT / 4) #define LCR_CAR_TURN_MAX (LCR_GAME_UNIT / 4)
/* /*
@ -149,7 +149,6 @@ void LCR_racingInit(void)
void LCR_racingGetCarTransform(LCR_GameUnit position[3], void LCR_racingGetCarTransform(LCR_GameUnit position[3],
LCR_GameUnit rotation[3], LCR_GameUnit interpolationParam) LCR_GameUnit rotation[3], LCR_GameUnit interpolationParam)
{ {
#if LCR_SETTING_SMOOTH_ANIMATIONS #if LCR_SETTING_SMOOTH_ANIMATIONS
TPE_Vec3 v = TPE_vec3Plus( TPE_Vec3 v = TPE_vec3Plus(
LCR_racing.carPositions[1], LCR_racing.carPositions[1],
@ -175,7 +174,6 @@ void LCR_racingGetCarTransform(LCR_GameUnit position[3],
rotation[0] = (v.x * LCR_GAME_UNIT) / TPE_F; rotation[0] = (v.x * LCR_GAME_UNIT) / TPE_F;
rotation[1] = (v.y * LCR_GAME_UNIT) / TPE_F; rotation[1] = (v.y * LCR_GAME_UNIT) / TPE_F;
rotation[2] = (v.z * LCR_GAME_UNIT) / TPE_F; rotation[2] = (v.z * LCR_GAME_UNIT) / TPE_F;
// TODO: also smooth out rotation?
} }
void _LCR_drawPhysicsDebugPixel(uint16_t x, uint16_t y, uint8_t color) void _LCR_drawPhysicsDebugPixel(uint16_t x, uint16_t y, uint8_t color)
@ -360,9 +358,9 @@ LCR_racing.carPositions[0] =
LCR_racing.carPositions[1], LCR_racing.carPositions[1],
LCR_racing.carPositions[0], LCR_racing.carPositions[0],
TPE_vec3( TPE_vec3(
LCR_PHYSICS_UNIT / 64, // TODO: 64 LCR_PHYSICS_UNIT / 50, // TODO: constant
LCR_PHYSICS_UNIT / 64, LCR_PHYSICS_UNIT / 50,
LCR_PHYSICS_UNIT / 64 LCR_PHYSICS_UNIT / 50
) )
); );

View file

@ -101,20 +101,22 @@ void LCR_rendererSetCarTransform(LCR_GameUnit position[3],
// TODO: make a separate function that does the smoothing (updateCarTransform) // TODO: make a separate function that does the smoothing (updateCarTransform)
LCR_renderer.carModel->transform.rotation.x = LCR_renderer.carModel->transform.rotation.x =
_LCR_smoothRotation(LCR_renderer.carModel->transform.rotation.x, _LCR_smoothRotation(LCR_renderer.carModel->transform.rotation.x,
S3L_wrap((rotation[0] * S3L_F) / LCR_GAME_UNIT,S3L_F),1); S3L_wrap((rotation[0] * S3L_F) / LCR_GAME_UNIT,S3L_F),3);
/*
LCR_renderer.carModel->transform.rotation.y = S3L_wrap((rotation[1] * LCR_renderer.carModel->transform.rotation.y = S3L_wrap((rotation[1] *
S3L_F) / LCR_GAME_UNIT,S3L_F); // don't smooth for faster reaction? S3L_F) / LCR_GAME_UNIT,S3L_F); // don't smooth for faster reaction?
/* */
LCR_renderer.carModel->transform.rotation.y = LCR_renderer.carModel->transform.rotation.y =
_LCR_smoothRotation(LCR_renderer.carModel->transform.rotation.y, _LCR_smoothRotation(LCR_renderer.carModel->transform.rotation.y,
S3L_wrap((rotation[1] * S3L_F) / LCR_GAME_UNIT,S3L_F),1); S3L_wrap((rotation[1] * S3L_F) / LCR_GAME_UNIT,S3L_F),1);
*/
LCR_renderer.carModel->transform.rotation.z = LCR_renderer.carModel->transform.rotation.z =
_LCR_smoothRotation(LCR_renderer.carModel->transform.rotation.z, _LCR_smoothRotation(LCR_renderer.carModel->transform.rotation.z,
S3L_wrap((rotation[2] * S3L_F) / LCR_GAME_UNIT,S3L_F),1); S3L_wrap((rotation[2] * S3L_F) / LCR_GAME_UNIT,S3L_F),3);
/* /*
LCR_renderer.carModel->transform.rotation.x = S3L_wrap((rotation[0] * LCR_renderer.carModel->transform.rotation.x = S3L_wrap((rotation[0] *
@ -898,26 +900,12 @@ void LCR_rendererMoveCamera(LCR_GameUnit forwRightUpOffset[3],
((f.z * forwRightUpOffset[0] + r.z * forwRightUpOffset[1] + ((f.z * forwRightUpOffset[0] + r.z * forwRightUpOffset[1] +
u.z * forwRightUpOffset[2]) * S3L_F) / LCR_GAME_UNIT; u.z * forwRightUpOffset[2]) * S3L_F) / LCR_GAME_UNIT;
LCR_renderer.scene.camera.transform.rotation.y += LCR_renderer.scene.camera.transform.rotation.y +=
(yawPitchOffset[0] * S3L_F) / LCR_GAME_UNIT; (yawPitchOffset[0] * S3L_F) / LCR_GAME_UNIT;
LCR_renderer.scene.camera.transform.rotation.x += LCR_renderer.scene.camera.transform.rotation.x +=
(yawPitchOffset[1] * S3L_F) / LCR_GAME_UNIT; (yawPitchOffset[1] * S3L_F) / LCR_GAME_UNIT;
/*
LCR_renderer.scene.camera.transform.rotation.y = S3L_wrap(
LCR_renderer.scene.camera.transform.rotation.y +
(yawPitchOffset[0] * S3L_F) / LCR_GAME_UNIT,
S3L_F);
LCR_renderer.scene.camera.transform.rotation.x = S3L_clamp(
LCR_renderer.scene.camera.transform.rotation.x +
(yawPitchOffset[1] * S3L_F) / LCR_GAME_UNIT,
-1 * S3L_F / 4,S3L_F / 4);
*/
#define chk(o,c,l) \ #define chk(o,c,l) \
if (LCR_renderer.scene.camera.transform.translation.c o l) \ if (LCR_renderer.scene.camera.transform.translation.c o l) \
LCR_renderer.scene.camera.transform.translation.c = l; LCR_renderer.scene.camera.transform.translation.c = l;
@ -1199,10 +1187,10 @@ void _LCR_rendererLoadMapChunk(uint8_t chunk, int8_t x, int8_t y, int8_t z)
S3L_Unit _LCR_smoothRotation(S3L_Unit angleOld, S3L_Unit angleNew, S3L_Unit _LCR_smoothRotation(S3L_Unit angleOld, S3L_Unit angleNew,
unsigned int amount) unsigned int amount)
{ {
// angleOld = S3L_wrap(angleOld,S3L_F); /* We have to do the following angle correction -- even if keep angles in
// angleNew = S3L_wrap(angleNew,S3L_F); correct range at the start of frame, subsequent steps may alter the rotations
and here we could end up with bad ranges again. */
S3L_Unit angleDiff = angleNew - angleOld; S3L_Unit angleDiff = S3L_wrap(angleNew,S3L_F) - S3L_wrap(angleOld,S3L_F);
if (angleDiff == 0) if (angleDiff == 0)
return angleNew; return angleNew;
@ -1215,16 +1203,10 @@ S3L_Unit _LCR_smoothRotation(S3L_Unit angleOld, S3L_Unit angleNew,
angleDiff = (angleDiff > 0) ? -1 * angleDiffAbs : angleDiffAbs; angleDiff = (angleDiff > 0) ? -1 * angleDiffAbs : angleDiffAbs;
} }
// if (angleDiffAbs > (3 * S3L_F) / 8) // angle too big, rotate immediately if (angleDiffAbs > (3 * S3L_F) / 8) // angle too big, rotate immediately
// return angleNew; return angleNew;
/* return angleOld + (angleDiff / S3L_nonZero(amount));
printf("%d %d %d\n",angleOld,angleNew,
angleOld + (angleDiff >> amount)
);
*/
return angleOld + (angleDiff >> amount); // smoothly interpolate
} }
/** /**
@ -1344,8 +1326,8 @@ void _LCR_rendererAnimateCar(void)
{ {
if (LCR_carVertexTypes[i] > 0) if (LCR_carVertexTypes[i] > 0)
{ {
S3L_Unit s = S3L_sin(LCR_renderer.wheelRotation), S3L_Unit s = S3L_sin(-1 * LCR_renderer.wheelRotation),
c = S3L_cos(LCR_renderer.wheelRotation); c = S3L_cos(-1 * LCR_renderer.wheelRotation);
S3L_Unit v[2], tmp; S3L_Unit v[2], tmp;
@ -1388,8 +1370,7 @@ void _LCR_rendererAnimateCar(void)
void LCR_rendererCameraFollow(void) void LCR_rendererCameraFollow(void)
{ {
S3L_Transform3D transPrev = S3L_Transform3D transPrev = LCR_renderer.scene.camera.transform;
LCR_renderer.scene.camera.transform;
LCR_renderer.scene.camera.transform.translation.y = LCR_renderer.scene.camera.transform.translation.y =
S3L_clamp( S3L_clamp(
@ -1401,14 +1382,11 @@ void LCR_rendererCameraFollow(void)
(LCR_SETTING_CAMERA_HEIGHT + LCR_SETTING_CAMERA_HEIGHT_BAND) * (LCR_SETTING_CAMERA_HEIGHT + LCR_SETTING_CAMERA_HEIGHT_BAND) *
LCR_RENDERER_UNIT / 8); LCR_RENDERER_UNIT / 8);
S3L_Vec4 toCam = S3L_Vec4 toCam = LCR_renderer.scene.camera.transform.translation;
LCR_renderer.scene.camera.transform.translation;
S3L_vec3Sub(&toCam, S3L_vec3Sub(&toCam,LCR_renderer.carModel->transform.translation);
LCR_renderer.carModel->transform.translation);
S3L_Unit horizontalDist = S3L_Unit horizontalDist = S3L_sqrt(toCam.x * toCam.x + toCam.z * toCam.z);
S3L_sqrt(toCam.x * toCam.x + toCam.z * toCam.z);
if (horizontalDist == 0) if (horizontalDist == 0)
{ {
@ -1449,21 +1427,12 @@ void LCR_rendererCameraFollow(void)
LCR_renderer.scene.camera.transform.translation.x /= 2; LCR_renderer.scene.camera.transform.translation.x /= 2;
LCR_renderer.scene.camera.transform.translation.y /= 2; LCR_renderer.scene.camera.transform.translation.y /= 2;
LCR_renderer.scene.camera.transform.translation.z /= 2; LCR_renderer.scene.camera.transform.translation.z /= 2;
LCR_renderer.scene.camera.transform.rotation.x = _LCR_smoothRotation( LCR_renderer.scene.camera.transform.rotation.x = _LCR_smoothRotation(
transPrev.rotation.x,LCR_renderer.scene.camera.transform.rotation.x,2); transPrev.rotation.x,LCR_renderer.scene.camera.transform.rotation.x,8);
/*
printf("aaa %d %d %d\n",
transPrev.rotation.y,
LCR_renderer.scene.camera.transform.rotation.y,
_LCR_smoothRotation(
transPrev.rotation.y,LCR_renderer.scene.camera.transform.rotation.y,3)
);
*/
LCR_renderer.scene.camera.transform.rotation.y = _LCR_smoothRotation( LCR_renderer.scene.camera.transform.rotation.y = _LCR_smoothRotation(
transPrev.rotation.y,LCR_renderer.scene.camera.transform.rotation.y,3); transPrev.rotation.y,LCR_renderer.scene.camera.transform.rotation.y,6);
#endif #endif
} }

View file

@ -102,7 +102,7 @@
#ifndef LCR_SETTING_CAMERA_HEIGHT #ifndef LCR_SETTING_CAMERA_HEIGHT
/** Base height of the car follow camera, in 4ths of map block height. */ /** Base height of the car follow camera, in 4ths of map block height. */
#define LCR_SETTING_CAMERA_HEIGHT 5 #define LCR_SETTING_CAMERA_HEIGHT 4
#endif #endif
#ifndef LCR_SETTING_CAMERA_HEIGHT_BAND #ifndef LCR_SETTING_CAMERA_HEIGHT_BAND
@ -113,12 +113,12 @@
#ifndef LCR_SETTING_CAMERA_DISTANCE #ifndef LCR_SETTING_CAMERA_DISTANCE
/** Base horizontal distance of the car follow camera, in 4ths of map block /** Base horizontal distance of the car follow camera, in 4ths of map block
width. */ width. */
#define LCR_SETTING_CAMERA_DISTANCE 4 #define LCR_SETTING_CAMERA_DISTANCE 3
#endif #endif
#ifndef LCR_SETTING_CAMERA_DISTANCE_BAND #ifndef LCR_SETTING_CAMERA_DISTANCE_BAND
/** Band for distance of the car follow camera, in same units as base dist. */ /** Band for distance of the car follow camera, in same units as base dist. */
#define LCR_SETTING_CAMERA_DISTANCE_BAND 3 #define LCR_SETTING_CAMERA_DISTANCE_BAND 2
#endif #endif
#ifndef LCR_SETTING_GHOST_COLOR #ifndef LCR_SETTING_GHOST_COLOR