Fix some stuff

This commit is contained in:
Miloslav Ciz 2024-09-10 15:30:07 +02:00
parent 08fb45b652
commit 74ea3dcd41
4 changed files with 615 additions and 405 deletions

View file

@ -74,7 +74,7 @@ struct
#if LCR_ANIMATE_CAR
S3L_Unit wheelRotation;
S3L_Unit wheelTurn;
S3L_Unit wheelSteer;
S3L_Unit wheelRotationCenters[4];
S3L_Unit animatedCarVerts[LCR_CAR_VERTEX_COUNT * 3];
#endif
@ -828,7 +828,7 @@ LCR_renderer.ghostModel->transform.translation.x -= LCR_GAME_UNIT / 4;
LCR_renderer.wheelRotationCenters[3] /= count[1];
LCR_renderer.wheelRotation = 0;
LCR_renderer.wheelTurn = 0;
LCR_renderer.wheelSteer = 0;
#endif
S3L_sceneInit(
@ -1280,8 +1280,8 @@ void _LCR_rendererAnimateCar(void)
{
if (LCR_carVertexTypes[i] > 0)
{
S3L_Unit s = S3L_sin(-1 * LCR_renderer.wheelRotation),
c = S3L_cos(-1 * LCR_renderer.wheelRotation);
S3L_Unit s = S3L_sin(LCR_renderer.wheelRotation),
c = S3L_cos(LCR_renderer.wheelRotation);
S3L_Unit v[2], tmp;
@ -1302,19 +1302,19 @@ void _LCR_rendererAnimateCar(void)
LCR_renderer.animatedCarVerts[index + 1] =
v[1] + LCR_renderer.wheelRotationCenters[offset + 1];
if (LCR_carVertexTypes[i] > 1)
if (LCR_carVertexTypes[i] == 1)
{
/* Turn front wheels; this is not real turning but just a fake by
skewing in Z and X directions. */
LCR_renderer.animatedCarVerts[index] = LCR_carVertices[index];
LCR_renderer.animatedCarVerts[index + 2] -=
(LCR_renderer.animatedCarVerts[index] * LCR_renderer.wheelTurn)
(LCR_renderer.animatedCarVerts[index] * LCR_renderer.wheelSteer)
/ (8 * S3L_F);
LCR_renderer.animatedCarVerts[index] +=
((LCR_renderer.animatedCarVerts[index + 2] -
LCR_renderer.wheelRotationCenters[0]) * LCR_renderer.wheelTurn)
LCR_renderer.wheelRotationCenters[2]) * LCR_renderer.wheelSteer)
/ (2 * S3L_F);
}
}
@ -1353,8 +1353,19 @@ void LCR_rendererCameraFollow(void)
LCR_renderer.carModel->transform.translation.z +
LCR_SETTING_CAMERA_MAX_DISTANCE * LCR_RENDERER_UNIT / 4);
S3L_lookAt(LCR_renderer.carModel->transform.translation,
&(LCR_renderer.scene.camera.transform));
/* Hotfix for a Gimbal lock kinda issue, don't do lookAt when completely
above the car, rather shift the camera a bit (needs some tuning). */
if (S3L_abs(LCR_renderer.scene.camera.transform.translation.x -
LCR_renderer.carModel->transform.translation.x) > 8 &&
S3L_abs(LCR_renderer.scene.camera.transform.translation.z -
LCR_renderer.carModel->transform.translation.z) > 8)
S3L_lookAt(LCR_renderer.carModel->transform.translation,
&(LCR_renderer.scene.camera.transform));
else
{
LCR_renderer.scene.camera.transform.translation.x += 4;
LCR_renderer.scene.camera.transform.translation.z -= 8;
}
#if LCR_SETTING_SMOOTH_ANIMATIONS
// now average with previous transform to smooth the animation out:
@ -1368,10 +1379,18 @@ void LCR_rendererCameraFollow(void)
transPrev.rotation.x -= LCR_renderer.scene.camera.transform.rotation.x;
transPrev.rotation.y -= LCR_renderer.scene.camera.transform.rotation.y;
if (S3L_abs(transPrev.rotation.x) < S3L_F / 4)
LCR_renderer.scene.camera.transform.rotation.x += transPrev.rotation.x / 2;
if (S3L_abs(transPrev.rotation.y) < S3L_F / 5)
LCR_renderer.scene.camera.transform.rotation.y += transPrev.rotation.y / 2;
LCR_renderer.scene.camera.transform.rotation.y += transPrev.rotation.y / 2;
LCR_renderer.scene.camera.transform.rotation.x += transPrev.rotation.x / 2;
#endif
}
void LCR_rendererSetWheelState(LCR_GameUnit rotation, LCR_GameUnit steer)
{
#if LCR_ANIMATE_CAR
LCR_renderer.wheelRotation = rotation;
LCR_renderer.wheelSteer = steer;
#endif
}
@ -1379,19 +1398,16 @@ void LCR_rendererDraw(void)
{
LCR_renderer.previousTriID = -1;
S3L_newFrame();
#if LCR_ANIMATE_CAR
_LCR_rendererAnimateCar();
#endif
_LCR_rendererLoadMapChunks(); // TODO: call only once in a while?
LCR_rendererDrawSky(1,
LCR_renderer.scene.camera.transform.rotation.y,
-4 * LCR_renderer.scene.camera.transform.rotation.x);
#if LCR_ANIMATE_CAR
LCR_renderer.wheelRotation += 5;
LCR_renderer.wheelTurn = S3L_sin(LCR_renderer.frame * 4);
_LCR_rendererAnimateCar();
#endif
LCR_drawLevelFloor();
LCR_rendererDrawLOD();