Add camera modes
This commit is contained in:
parent
a9f0a6885a
commit
7fb04804e7
3 changed files with 98 additions and 50 deletions
48
renderer.h
48
renderer.h
|
@ -120,6 +120,11 @@ void LCR_rendererSetCarTransform(LCR_GameUnit position[3],
|
|||
S3L_F) / LCR_GAME_UNIT,S3L_F);
|
||||
}
|
||||
|
||||
void LCR_rendererSetCarVisibility(uint8_t visible)
|
||||
{
|
||||
LCR_renderer.carModel->config.visible = visible;
|
||||
}
|
||||
|
||||
void _LCR_rendererDrawFontPixel(int x, int y, uint16_t color)
|
||||
{
|
||||
#if LCR_FONT_PIXEL_SIZE == 1
|
||||
|
@ -1604,20 +1609,47 @@ void _LCR_rendererAnimateCar(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
void LCR_rendererCameraFollow(void)
|
||||
/**
|
||||
Call every rendering frame to make the camera follow the car model. The
|
||||
distance parameter can be either 0 (inside of car, car should be made
|
||||
invisible for this), 1 (normal distance) or 2 (double distance).
|
||||
*/
|
||||
void LCR_rendererCameraFollow(unsigned char distance)
|
||||
{
|
||||
LCR_LOG2("following camera");
|
||||
|
||||
if (distance == 0)
|
||||
{
|
||||
LCR_renderer.scene.camera.transform.translation =
|
||||
LCR_renderer.carModel->transform.translation;
|
||||
|
||||
LCR_renderer.scene.camera.transform.translation.y += LCR_RENDERER_UNIT / 3;
|
||||
|
||||
LCR_renderer.scene.camera.transform.rotation =
|
||||
LCR_renderer.carModel->transform.rotation;
|
||||
|
||||
LCR_renderer.scene.camera.transform.rotation.x = -1 *
|
||||
((LCR_renderer.scene.camera.transform.rotation.x + S3L_FRACTIONS_PER_UNIT / 4) %
|
||||
(S3L_FRACTIONS_PER_UNIT / 2) - S3L_FRACTIONS_PER_UNIT / 4);
|
||||
|
||||
LCR_renderer.scene.camera.transform.rotation.y += S3L_FRACTIONS_PER_UNIT / 2;
|
||||
LCR_renderer.scene.camera.transform.rotation.z *= -1;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int shift = distance != 1;
|
||||
|
||||
S3L_Transform3D transPrev = LCR_renderer.scene.camera.transform;
|
||||
|
||||
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_SETTING_CAMERA_HEIGHT << shift) - LCR_SETTING_CAMERA_HEIGHT_BAND) *
|
||||
LCR_RENDERER_UNIT / 8,
|
||||
LCR_renderer.carModel->transform.translation.y +
|
||||
(LCR_SETTING_CAMERA_HEIGHT + LCR_SETTING_CAMERA_HEIGHT_BAND) *
|
||||
((LCR_SETTING_CAMERA_HEIGHT << shift) + LCR_SETTING_CAMERA_HEIGHT_BAND) *
|
||||
LCR_RENDERER_UNIT / 8);
|
||||
|
||||
S3L_Vec4 toCam = LCR_renderer.scene.camera.transform.translation;
|
||||
|
@ -1634,9 +1666,9 @@ void LCR_rendererCameraFollow(void)
|
|||
|
||||
S3L_Unit horizontalDistNew =
|
||||
S3L_clamp(horizontalDist,
|
||||
(LCR_SETTING_CAMERA_DISTANCE - LCR_SETTING_CAMERA_DISTANCE_BAND)
|
||||
((LCR_SETTING_CAMERA_DISTANCE << shift) - LCR_SETTING_CAMERA_DISTANCE_BAND)
|
||||
* (LCR_RENDERER_UNIT / 4),
|
||||
(LCR_SETTING_CAMERA_DISTANCE + LCR_SETTING_CAMERA_DISTANCE_BAND)
|
||||
((LCR_SETTING_CAMERA_DISTANCE << shift) + LCR_SETTING_CAMERA_DISTANCE_BAND)
|
||||
* (LCR_RENDERER_UNIT / 4));
|
||||
|
||||
if (horizontalDistNew != horizontalDist)
|
||||
|
@ -1776,6 +1808,7 @@ void LCR_rendererDrawMenu(const char *tabName,const char **items,
|
|||
#endif
|
||||
}
|
||||
|
||||
// TODO: what is this function even doing?
|
||||
void LCR_rendererCameraReset(void)
|
||||
{
|
||||
LCR_renderer.scene.camera.transform.translation =
|
||||
|
@ -1787,7 +1820,10 @@ void LCR_rendererCameraReset(void)
|
|||
LCR_renderer.scene.camera.transform.translation.z +=
|
||||
S3L_cos(LCR_renderer.carModel->transform.rotation.y);
|
||||
|
||||
LCR_rendererCameraFollow();
|
||||
LCR_renderer.scene.camera.transform.rotation.x = 0;
|
||||
LCR_renderer.scene.camera.transform.rotation.z = 0;
|
||||
|
||||
LCR_rendererCameraFollow(1);
|
||||
}
|
||||
|
||||
void LCR_rendererSetWheelState(LCR_GameUnit rotation, LCR_GameUnit steer)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue