Add follow camera
This commit is contained in:
parent
46c8a4eade
commit
e3d0b3219f
4 changed files with 164 additions and 27 deletions
105
renderer.h
105
renderer.h
|
@ -31,6 +31,8 @@
|
|||
|
||||
#define LCR_RENDERER_MODEL_COUNT 9
|
||||
|
||||
#define LCR_RENDERER_CAR_SCALE (LCR_RENDERER_UNIT / 4)
|
||||
|
||||
struct
|
||||
{
|
||||
S3L_Scene scene;
|
||||
|
@ -91,6 +93,13 @@ void LCR_rendererSetCarTransform(LCR_GameUnit position[3],
|
|||
(position[1] * LCR_RENDERER_UNIT) / LCR_GAME_UNIT;
|
||||
LCR_renderer.carModel->transform.translation.z =
|
||||
(position[2] * LCR_RENDERER_UNIT) / LCR_GAME_UNIT;
|
||||
|
||||
LCR_renderer.carModel->transform.rotation.x = S3L_wrap((rotation[0] *
|
||||
S3L_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT,S3L_FRACTIONS_PER_UNIT);
|
||||
LCR_renderer.carModel->transform.rotation.y = S3L_wrap((rotation[1] *
|
||||
S3L_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT,S3L_FRACTIONS_PER_UNIT);
|
||||
LCR_renderer.carModel->transform.rotation.z = S3L_wrap((rotation[2] *
|
||||
S3L_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT,S3L_FRACTIONS_PER_UNIT);
|
||||
}
|
||||
|
||||
void _LCR_pixelFuncc3D(S3L_PixelInfo *pixel)
|
||||
|
@ -790,15 +799,9 @@ uint8_t LCR_rendererInit(void)
|
|||
LCR_renderer.wheelTurn = 0;
|
||||
#endif
|
||||
|
||||
LCR_renderer.carModel->transform.translation.x -= 2 * LCR_RENDERER_UNIT;
|
||||
LCR_renderer.carModel->transform.scale.x = LCR_RENDERER_UNIT / 3;
|
||||
|
||||
LCR_renderer.carModel->transform.scale.y =
|
||||
LCR_renderer.carModel->transform.scale.x;
|
||||
|
||||
LCR_renderer.carModel->transform.scale.z =
|
||||
LCR_renderer.carModel->transform.scale.x;
|
||||
|
||||
LCR_renderer.carModel->transform.scale.x = LCR_RENDERER_CAR_SCALE;
|
||||
LCR_renderer.carModel->transform.scale.y = LCR_RENDERER_CAR_SCALE;
|
||||
LCR_renderer.carModel->transform.scale.z = LCR_RENDERER_CAR_SCALE;
|
||||
|
||||
S3L_sceneInit(
|
||||
LCR_renderer.models,LCR_RENDERER_MODEL_COUNT,&LCR_renderer.scene);
|
||||
|
@ -1291,6 +1294,88 @@ void _LCR_rendererAnimateCar(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
void LCR_rendererCameraFollow(void)
|
||||
{
|
||||
|
||||
|
||||
/*
|
||||
LCR_renderer.scene.camera.transform.translation.y =
|
||||
LCR_renderer.carModel->transform.translation.y + LCR_RENDERER_UNIT;
|
||||
*/
|
||||
|
||||
/*
|
||||
TPE_Vec3 cPos = TPE_vec3KeepWithinDistanceBand(
|
||||
TPE_vec3(
|
||||
s3l_scene.camera.transform.translation.x,
|
||||
s3l_scene.camera.transform.translation.y,
|
||||
s3l_scene.camera.transform.translation.z
|
||||
),carBody->joints[4].position,4 * TPE_F,6 * TPE_F);
|
||||
|
||||
s3l_scene.camera.transform.translation.x = cPos.x;
|
||||
s3l_scene.camera.transform.translation.y = cPos.y;
|
||||
s3l_scene.camera.transform.translation.z = cPos.z;
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
S3L_Unit tmp =
|
||||
LCR_renderer.scene.camera.transform.translation.y -
|
||||
LCR_renderer.carModel->transform.translation.y;
|
||||
|
||||
tmp -= S3L_clamp(tmp,
|
||||
(LCR_SETTING_CAMERA_HEIGHT -
|
||||
LCR_SETTING_CAMERA_HEIGHT_BAND) * LCR_GAME_UNIT / 8,
|
||||
(LCR_SETTING_CAMERA_HEIGHT +
|
||||
LCR_SETTING_CAMERA_HEIGHT_BAND) * LCR_GAME_UNIT / 8);
|
||||
|
||||
LCR_renderer.scene.camera.transform.translation.y -= tmp;
|
||||
*/
|
||||
|
||||
LCR_renderer.scene.camera.transform.translation.y =
|
||||
S3L_clamp(
|
||||
LCR_renderer.scene.camera.transform.translation.y,
|
||||
LCR_renderer.carModel->transform.translation.y +
|
||||
(LCR_SETTING_CAMERA_HEIGHT - LCR_SETTING_CAMERA_HEIGHT_BAND) *
|
||||
LCR_GAME_UNIT / 8,
|
||||
LCR_renderer.carModel->transform.translation.y +
|
||||
(LCR_SETTING_CAMERA_HEIGHT + LCR_SETTING_CAMERA_HEIGHT_BAND) *
|
||||
LCR_GAME_UNIT / 8);
|
||||
|
||||
LCR_renderer.scene.camera.transform.translation.x =
|
||||
S3L_clamp(
|
||||
LCR_renderer.scene.camera.transform.translation.x,
|
||||
LCR_renderer.carModel->transform.translation.x -
|
||||
LCR_SETTING_CAMERA_MAX_DISTANCE * LCR_GAME_UNIT / 4,
|
||||
LCR_renderer.carModel->transform.translation.x +
|
||||
LCR_SETTING_CAMERA_MAX_DISTANCE * LCR_GAME_UNIT / 4);
|
||||
|
||||
LCR_renderer.scene.camera.transform.translation.z =
|
||||
S3L_clamp(
|
||||
LCR_renderer.scene.camera.transform.translation.z,
|
||||
LCR_renderer.carModel->transform.translation.z -
|
||||
LCR_SETTING_CAMERA_MAX_DISTANCE * LCR_GAME_UNIT / 4,
|
||||
LCR_renderer.carModel->transform.translation.z +
|
||||
LCR_SETTING_CAMERA_MAX_DISTANCE * LCR_GAME_UNIT / 4);
|
||||
|
||||
|
||||
|
||||
|
||||
S3L_lookAt(LCR_renderer.carModel->transform.translation,
|
||||
&(LCR_renderer.scene.camera.transform));
|
||||
|
||||
|
||||
/*
|
||||
TPE_Unit angleDiff = s3l_scene.camera.transform.rotation.y -
|
||||
(TPE_vec2Angle(toCar.x,toCar.z) - 128);
|
||||
|
||||
s3l_scene.camera.transform.rotation.y -=
|
||||
(angleDiff < 100 && angleDiff > -100) ? angleDiff / 2 : angleDiff;
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LCR_rendererDraw(void)
|
||||
{
|
||||
LCR_renderer.previousTriID = -1;
|
||||
|
@ -1309,6 +1394,8 @@ LCR_renderer.wheelTurn = S3L_sin(LCR_renderer.frame * 4);
|
|||
_LCR_rendererAnimateCar();
|
||||
#endif
|
||||
|
||||
LCR_rendererCameraFollow();
|
||||
|
||||
LCR_drawLevelFloor();
|
||||
LCR_rendererDrawLOD();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue