83 lines
2.1 KiB
C
83 lines
2.1 KiB
C
/**
|
|
racing module: implements the racing physics and logic.
|
|
*/
|
|
|
|
#ifndef _LCR_RACING_H
|
|
#define _LCR_RACING_H
|
|
|
|
typedef int32_t LCR_GameUnit; ///< game spatial units
|
|
|
|
#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 "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
|