Start debug draw
This commit is contained in:
parent
56904cabab
commit
1c6666b377
3 changed files with 119 additions and 22 deletions
17
game.h
17
game.h
|
@ -119,10 +119,8 @@ void LCR_gameInit(void)
|
||||||
LCR_keyStates[i] = 0;
|
LCR_keyStates[i] = 0;
|
||||||
|
|
||||||
LCR_mapLoad(map1);
|
LCR_mapLoad(map1);
|
||||||
|
|
||||||
LCR_rendererInit();
|
LCR_rendererInit();
|
||||||
|
LCR_racingInit();
|
||||||
LCR_loadImage(0); // ???
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCR_gameEnd(void)
|
void LCR_gameEnd(void)
|
||||||
|
@ -138,11 +136,22 @@ uint8_t LCR_gameStep(uint32_t time)
|
||||||
|
|
||||||
if (time >= LCR_nextRenderFrameTime)
|
if (time >= LCR_nextRenderFrameTime)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LCR_rendererDraw();
|
LCR_rendererDraw();
|
||||||
|
|
||||||
|
|
||||||
|
LCR_GameUnit sss[7];
|
||||||
|
LCR_rendererGetCameraTransform(sss,sss + 3,sss + 6);
|
||||||
|
LCR_physicsDebugDraw(sss,sss + 3,sss[6]);
|
||||||
|
|
||||||
|
|
||||||
LCR_nextRenderFrameTime += 1000 / LCR_SETTING_FPS;
|
LCR_nextRenderFrameTime += 1000 / LCR_SETTING_FPS;
|
||||||
|
|
||||||
LCR_SpaceUnit offsets[5];
|
LCR_GameUnit offsets[5];
|
||||||
|
|
||||||
for (int i = 0; i < 5; ++i)
|
for (int i = 0; i < 5; ++i)
|
||||||
offsets[i] = 0;
|
offsets[i] = 0;
|
||||||
|
|
71
racing.h
71
racing.h
|
@ -5,11 +5,78 @@
|
||||||
#ifndef _LCR_RACING_H
|
#ifndef _LCR_RACING_H
|
||||||
#define _LCR_RACING_H
|
#define _LCR_RACING_H
|
||||||
|
|
||||||
typedef int32_t LCR_SpaceUnit; ///< game spatial units
|
typedef int32_t LCR_GameUnit; ///< game spatial units
|
||||||
|
|
||||||
#define LCR_SQUARE_SIDE_LEN 1024 ///< length of map square in LCR_SpaceUnits
|
#define LCR_GAME_UNIT 1024 ///< length of map square in game units
|
||||||
|
|
||||||
|
#define LCR_PHYSICS_UNIT 512 ///< length of map square for physics engine
|
||||||
|
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "tinyphysicsengine.h"
|
#include "tinyphysicsengine.h"
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
TPE_World physicsWorld;
|
||||||
|
TPE_Body carBody;
|
||||||
|
} LCR_racing;
|
||||||
|
|
||||||
|
TPE_Vec3 LCR_racingEnvironmentFunction(TPE_Vec3 point, TPE_Unit maxDist)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
return
|
||||||
|
TPE_envHalfPlane(point,
|
||||||
|
TPE_vec3(0,0,0),
|
||||||
|
TPE_vec3(0,TPE_FRACTIONS_PER_UNIT,0));
|
||||||
|
*/
|
||||||
|
|
||||||
|
return TPE_envAABoxInside(point,TPE_vec3(0,0,0),TPE_vec3(
|
||||||
|
LCR_PHYSICS_UNIT * LCR_MAP_SIZE_BLOCKS,
|
||||||
|
(LCR_PHYSICS_UNIT * LCR_MAP_SIZE_BLOCKS) / 2,
|
||||||
|
LCR_PHYSICS_UNIT * LCR_MAP_SIZE_BLOCKS));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void LCR_racingInit(void)
|
||||||
|
{
|
||||||
|
LCR_log("initializing racing engine");
|
||||||
|
|
||||||
|
TPE_worldInit(&(LCR_racing.physicsWorld),
|
||||||
|
&(LCR_racing.carBody),1,LCR_racingEnvironmentFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _LCR_drawPhysicsDebugPixel(uint16_t x, uint16_t y, uint8_t color)
|
||||||
|
{
|
||||||
|
if (x > 1 && x < LCR_EFFECTIVE_RESOLUTION_X - 1 &&
|
||||||
|
y > 1 && y < LCR_EFFECTIVE_RESOLUTION_Y - 1)
|
||||||
|
{
|
||||||
|
uint16_t color = color;
|
||||||
|
color = (color << 3) | 0xf800;
|
||||||
|
|
||||||
|
for (int j = -1; j < 2; ++j)
|
||||||
|
for (int i = -1; i < 2; ++i)
|
||||||
|
LCR_drawPixelXYUnsafe(x + i,y + j,color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LCR_physicsDebugDraw(LCR_GameUnit camPos[3], LCR_GameUnit camRot[2],
|
||||||
|
LCR_GameUnit camFov)
|
||||||
|
{
|
||||||
|
TPE_Vec3 cPos, cRot, cView;
|
||||||
|
|
||||||
|
cPos.x = (camPos[0] * LCR_PHYSICS_UNIT) / LCR_GAME_UNIT;
|
||||||
|
cPos.y = (camPos[1] * LCR_PHYSICS_UNIT) / LCR_GAME_UNIT;
|
||||||
|
cPos.z = (camPos[2] * LCR_PHYSICS_UNIT) / LCR_GAME_UNIT;
|
||||||
|
|
||||||
|
cRot.x = (camRot[0] * TPE_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT;
|
||||||
|
cRot.y = (camRot[1] * TPE_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT;
|
||||||
|
cRot.z = 0;
|
||||||
|
|
||||||
|
cView.x = LCR_EFFECTIVE_RESOLUTION_X;
|
||||||
|
cView.y = LCR_EFFECTIVE_RESOLUTION_Y;
|
||||||
|
cView.z = (camFov * TPE_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT;
|
||||||
|
|
||||||
|
TPE_worldDebugDraw(&(LCR_racing.physicsWorld),_LCR_drawPhysicsDebugPixel,
|
||||||
|
cPos,cRot,cView,16,2 * LCR_PHYSICS_UNIT);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|
53
renderer.h
53
renderer.h
|
@ -37,6 +37,8 @@ struct
|
||||||
S3L_Model3D mapModel; ///< whole map model
|
S3L_Model3D mapModel; ///< whole map model
|
||||||
S3L_Model3D *carModel;
|
S3L_Model3D *carModel;
|
||||||
|
|
||||||
|
// TODO: ghostModel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The scene model array.
|
The scene model array.
|
||||||
0, 1, 2, 3, 4, 5, 6, 7: nearest map chunk models
|
0, 1, 2, 3, 4, 5, 6, 7: nearest map chunk models
|
||||||
|
@ -67,7 +69,7 @@ struct
|
||||||
uint8_t gridOfLODs[LCR_RENDERER_LOD_BLOCKS];
|
uint8_t gridOfLODs[LCR_RENDERER_LOD_BLOCKS];
|
||||||
|
|
||||||
// pixel function precomputed values:
|
// pixel function precomputed values:
|
||||||
int previousTriID;
|
uint32_t previousTriID;
|
||||||
int triUVs[6];
|
int triUVs[6];
|
||||||
uint8_t texSubsampleCount;
|
uint8_t texSubsampleCount;
|
||||||
|
|
||||||
|
@ -793,8 +795,29 @@ LCR_renderer.carModel->transform.scale.z =
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCR_rendererMoveCamera(LCR_SpaceUnit forwRightUpOffset[3],
|
void LCR_rendererGetCameraTransform(LCR_GameUnit position[3],
|
||||||
LCR_SpaceUnit yawPitchOffset[2])
|
LCR_GameUnit rotation[3], LCR_GameUnit *fov)
|
||||||
|
{
|
||||||
|
position[0] = (LCR_renderer.scene.camera.transform.translation.x *
|
||||||
|
LCR_GAME_UNIT) / LCR_RENDERER_UNIT;
|
||||||
|
position[1] = (LCR_renderer.scene.camera.transform.translation.y *
|
||||||
|
LCR_GAME_UNIT) / LCR_RENDERER_UNIT;
|
||||||
|
position[2] = (LCR_renderer.scene.camera.transform.translation.z *
|
||||||
|
LCR_GAME_UNIT) / LCR_RENDERER_UNIT;
|
||||||
|
|
||||||
|
rotation[0] = (LCR_renderer.scene.camera.transform.rotation.x *
|
||||||
|
LCR_GAME_UNIT) / S3L_FRACTIONS_PER_UNIT;
|
||||||
|
rotation[1] = (LCR_renderer.scene.camera.transform.rotation.y *
|
||||||
|
LCR_GAME_UNIT) / S3L_FRACTIONS_PER_UNIT;
|
||||||
|
rotation[2] = (LCR_renderer.scene.camera.transform.rotation.z *
|
||||||
|
LCR_GAME_UNIT) / S3L_FRACTIONS_PER_UNIT;
|
||||||
|
|
||||||
|
*fov = (LCR_renderer.scene.camera.focalLength * LCR_GAME_UNIT)
|
||||||
|
/ S3L_FRACTIONS_PER_UNIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LCR_rendererMoveCamera(LCR_GameUnit forwRightUpOffset[3],
|
||||||
|
LCR_GameUnit yawPitchOffset[2])
|
||||||
{
|
{
|
||||||
S3L_Vec4 f, r, u;
|
S3L_Vec4 f, r, u;
|
||||||
|
|
||||||
|
@ -803,27 +826,25 @@ void LCR_rendererMoveCamera(LCR_SpaceUnit forwRightUpOffset[3],
|
||||||
|
|
||||||
LCR_renderer.scene.camera.transform.translation.x +=
|
LCR_renderer.scene.camera.transform.translation.x +=
|
||||||
((f.x * forwRightUpOffset[0] + r.x * forwRightUpOffset[1] +
|
((f.x * forwRightUpOffset[0] + r.x * forwRightUpOffset[1] +
|
||||||
u.x * forwRightUpOffset[2]) * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
|
u.x * forwRightUpOffset[2]) * S3L_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT;
|
||||||
|
|
||||||
LCR_renderer.scene.camera.transform.translation.y +=
|
LCR_renderer.scene.camera.transform.translation.y +=
|
||||||
((f.y * forwRightUpOffset[0] + r.y * forwRightUpOffset[1] +
|
((f.y * forwRightUpOffset[0] + r.y * forwRightUpOffset[1] +
|
||||||
u.y * forwRightUpOffset[2]) * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
|
u.y * forwRightUpOffset[2]) * S3L_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT;
|
||||||
|
|
||||||
LCR_renderer.scene.camera.transform.translation.z +=
|
LCR_renderer.scene.camera.transform.translation.z +=
|
||||||
((f.z * forwRightUpOffset[0] + r.z * forwRightUpOffset[1] +
|
((f.z * forwRightUpOffset[0] + r.z * forwRightUpOffset[1] +
|
||||||
u.z * forwRightUpOffset[2]) * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
|
u.z * forwRightUpOffset[2]) * S3L_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT;
|
||||||
|
|
||||||
LCR_renderer.scene.camera.transform.rotation.y +=
|
LCR_renderer.scene.camera.transform.rotation.y = S3L_wrap(
|
||||||
(yawPitchOffset[0] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
|
LCR_renderer.scene.camera.transform.rotation.y +
|
||||||
|
(yawPitchOffset[0] * S3L_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT,
|
||||||
|
S3L_FRACTIONS_PER_UNIT);
|
||||||
|
|
||||||
LCR_renderer.scene.camera.transform.rotation.x +=
|
LCR_renderer.scene.camera.transform.rotation.x = S3L_clamp(
|
||||||
(yawPitchOffset[1] * S3L_FRACTIONS_PER_UNIT) / LCR_SQUARE_SIDE_LEN;
|
LCR_renderer.scene.camera.transform.rotation.x +
|
||||||
|
(yawPitchOffset[1] * S3L_FRACTIONS_PER_UNIT) / LCR_GAME_UNIT,
|
||||||
if (LCR_renderer.scene.camera.transform.rotation.x > S3L_FRACTIONS_PER_UNIT / 4)
|
-1 * S3L_FRACTIONS_PER_UNIT / 4,S3L_FRACTIONS_PER_UNIT / 4);
|
||||||
LCR_renderer.scene.camera.transform.rotation.x = S3L_FRACTIONS_PER_UNIT / 4;
|
|
||||||
|
|
||||||
if (LCR_renderer.scene.camera.transform.rotation.x < -1 * S3L_FRACTIONS_PER_UNIT / 4)
|
|
||||||
LCR_renderer.scene.camera.transform.rotation.x = -1 * S3L_FRACTIONS_PER_UNIT / 4;
|
|
||||||
|
|
||||||
#define chk(o,c,l) \
|
#define chk(o,c,l) \
|
||||||
if (LCR_renderer.scene.camera.transform.translation.c o l) \
|
if (LCR_renderer.scene.camera.transform.translation.c o l) \
|
||||||
|
|
Loading…
Reference in a new issue