Move camera

This commit is contained in:
Miloslav Ciz 2023-09-16 22:52:03 +02:00
parent edcde03fa3
commit ee15824329
3 changed files with 60 additions and 3 deletions

22
game.h
View file

@ -1,6 +1,6 @@
/** /**
Licar game: this file implements the backend of a complete, actually playable game: this file implements the backend of a complete, actually playable
licar game, and is meant to be included and used by specific frontends (which game, and is meant to be included and used by specific frontends (which
will handle each platform's hardware details and I/O). will handle each platform's hardware details and I/O).
*/ */
@ -78,7 +78,7 @@ void LCR_drawPixelUnsafe(unsigned int x, unsigned int y,
static inline void LCR_drawPixelSafe(unsigned int x, unsigned int y, static inline void LCR_drawPixelSafe(unsigned int x, unsigned int y,
uint_fast16_t color); uint_fast16_t color);
#include "map.h" #include "racing.h"
#include "assets.h" #include "assets.h"
#include "renderer.h" #include "renderer.h"
@ -133,6 +133,22 @@ for (int i = 0; i < LCR_EFFECTIVE_RESOLUTION_X; ++i)
for (int i = 0; i < LCR_KEYS_TOTAL; ++i) for (int i = 0; i < LCR_KEYS_TOTAL; ++i)
_LCR_keyStates[i] = LCR_keyPressed(i); _LCR_keyStates[i] = LCR_keyPressed(i);
LCR_SpaceUnit camPos[3];
LCR_getCameraPos(camPos);
#define N 10
if (_LCR_keyStates[LCR_KEY_UP]) camPos[2] += N;
else if (_LCR_keyStates[LCR_KEY_DOWN]) camPos[2] -= N;
if (_LCR_keyStates[LCR_KEY_LEFT]) camPos[0] -= N;
else if (_LCR_keyStates[LCR_KEY_RIGHT]) camPos[0] += N;
if (_LCR_keyStates[LCR_KEY_A]) camPos[1] -= N;
else if (_LCR_keyStates[LCR_KEY_B]) camPos[1] += N;
LCR_setCameraPos(camPos);
LCR_drawBackground(200 + aaa / 10); LCR_drawBackground(200 + aaa / 10);

15
racing.h Normal file
View file

@ -0,0 +1,15 @@
/**
racing module: implements the racing physics and logic.
*/
#ifndef _LCR_RACING_H
#define _LCR_RACING_H
typedef int32_t LCR_SpaceUnit; ///< game spatial units
#define LCR_SQUARE_SIDE_LEN 1024 ///< length of map square in LCR_SpaceUnits
#include "map.h"
#include "tinyphysicsengine.h"
#endif // guard

View file

@ -1,3 +1,7 @@
/**
3D renderer: implements 3D rendering.
*/
#ifndef _LCR_RENDERER_H #ifndef _LCR_RENDERER_H
#define _LCR_RENDERER_H #define _LCR_RENDERER_H
@ -10,6 +14,8 @@
struct LCR_Renderer struct LCR_Renderer
{ {
// TODO // TODO
}; };
S3L_Scene LCR_scene3D; S3L_Scene LCR_scene3D;
@ -59,6 +65,26 @@ uint8_t LCR_rendererInit(void)
return 1; return 1;
} }
void LCR_getCameraPos(LCR_SpaceUnit pos[3])
{
pos[0] = (LCR_scene3D.camera.transform.translation.x *
LCR_SQUARE_SIDE_LEN) / S3L_FRACTIONS_PER_UNIT;
pos[1] = (LCR_scene3D.camera.transform.translation.y *
LCR_SQUARE_SIDE_LEN) / S3L_FRACTIONS_PER_UNIT;
pos[2] = (LCR_scene3D.camera.transform.translation.z *
LCR_SQUARE_SIDE_LEN) / S3L_FRACTIONS_PER_UNIT;
}
void LCR_setCameraPos(LCR_SpaceUnit pos[3])
{
LCR_scene3D.camera.transform.translation.x =
(pos[0] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
LCR_scene3D.camera.transform.translation.y =
(pos[1] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
LCR_scene3D.camera.transform.translation.z =
(pos[2] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
}
void LCR_render(void) void LCR_render(void)
{ {
S3L_newFrame(); S3L_newFrame();