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

@ -101,20 +101,22 @@ void LCR_rendererSetCarTransform(LCR_GameUnit position[3],
// TODO: make a separate function that does the smoothing (updateCarTransform)
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] *
S3L_F) / LCR_GAME_UNIT,S3L_F); // don't smooth for faster reaction?
/*
*/
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);
*/
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] *
@ -898,26 +900,12 @@ void LCR_rendererMoveCamera(LCR_GameUnit forwRightUpOffset[3],
((f.z * forwRightUpOffset[0] + r.z * forwRightUpOffset[1] +
u.z * forwRightUpOffset[2]) * S3L_F) / LCR_GAME_UNIT;
LCR_renderer.scene.camera.transform.rotation.y +=
(yawPitchOffset[0] * S3L_F) / LCR_GAME_UNIT;
LCR_renderer.scene.camera.transform.rotation.y +=
(yawPitchOffset[0] * S3L_F) / LCR_GAME_UNIT;
LCR_renderer.scene.camera.transform.rotation.x +=
(yawPitchOffset[1] * S3L_F) / LCR_GAME_UNIT;
LCR_renderer.scene.camera.transform.rotation.x +=
(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) \
if (LCR_renderer.scene.camera.transform.translation.c o 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,
unsigned int amount)
{
// angleOld = S3L_wrap(angleOld,S3L_F);
// angleNew = S3L_wrap(angleNew,S3L_F);
S3L_Unit angleDiff = angleNew - angleOld;
/* We have to do the following angle correction -- even if keep angles in
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 = S3L_wrap(angleNew,S3L_F) - S3L_wrap(angleOld,S3L_F);
if (angleDiff == 0)
return angleNew;
@ -1215,16 +1203,10 @@ S3L_Unit _LCR_smoothRotation(S3L_Unit angleOld, S3L_Unit angleNew,
angleDiff = (angleDiff > 0) ? -1 * angleDiffAbs : angleDiffAbs;
}
// if (angleDiffAbs > (3 * S3L_F) / 8) // angle too big, rotate immediately
// return angleNew;
if (angleDiffAbs > (3 * S3L_F) / 8) // angle too big, rotate immediately
return angleNew;
/*
printf("%d %d %d\n",angleOld,angleNew,
angleOld + (angleDiff >> amount)
);
*/
return angleOld + (angleDiff >> amount); // smoothly interpolate
return angleOld + (angleDiff / S3L_nonZero(amount));
}
/**
@ -1344,8 +1326,8 @@ void _LCR_rendererAnimateCar(void)
{
if (LCR_carVertexTypes[i] > 0)
{
S3L_Unit s = S3L_sin(LCR_renderer.wheelRotation),
c = S3L_cos(LCR_renderer.wheelRotation);
S3L_Unit s = S3L_sin(-1 * LCR_renderer.wheelRotation),
c = S3L_cos(-1 * LCR_renderer.wheelRotation);
S3L_Unit v[2], tmp;
@ -1388,8 +1370,7 @@ void _LCR_rendererAnimateCar(void)
void LCR_rendererCameraFollow(void)
{
S3L_Transform3D transPrev =
LCR_renderer.scene.camera.transform;
S3L_Transform3D transPrev = LCR_renderer.scene.camera.transform;
LCR_renderer.scene.camera.transform.translation.y =
S3L_clamp(
@ -1401,14 +1382,11 @@ void LCR_rendererCameraFollow(void)
(LCR_SETTING_CAMERA_HEIGHT + LCR_SETTING_CAMERA_HEIGHT_BAND) *
LCR_RENDERER_UNIT / 8);
S3L_Vec4 toCam =
LCR_renderer.scene.camera.transform.translation;
S3L_Vec4 toCam = LCR_renderer.scene.camera.transform.translation;
S3L_vec3Sub(&toCam,
LCR_renderer.carModel->transform.translation);
S3L_vec3Sub(&toCam,LCR_renderer.carModel->transform.translation);
S3L_Unit horizontalDist =
S3L_sqrt(toCam.x * toCam.x + toCam.z * toCam.z);
S3L_Unit horizontalDist = S3L_sqrt(toCam.x * toCam.x + toCam.z * toCam.z);
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.y /= 2;
LCR_renderer.scene.camera.transform.translation.z /= 2;
LCR_renderer.scene.camera.transform.rotation.x = _LCR_smoothRotation(
transPrev.rotation.x,LCR_renderer.scene.camera.transform.rotation.x,2);
/*
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)
);
*/
transPrev.rotation.x,LCR_renderer.scene.camera.transform.rotation.x,8);
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
}