Clean a bit and stuff

This commit is contained in:
Miloslav Ciz 2024-12-18 20:45:35 +01:00
parent e42212d7c1
commit b79b83e56a
6 changed files with 99 additions and 88 deletions

View file

@ -9,17 +9,17 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_GAME_UNIT 1024 ///< length of map square in LCR_GameUnits
#define LCR_RACING_INPUT_FORW 0x01
#define LCR_RACING_INPUT_RIGHT 0x02
#define LCR_RACING_INPUT_BACK 0x04
#define LCR_RACING_INPUT_LEFT 0x08
#define LCR_RACING_INPUT_FORW 0x01
#define LCR_RACING_INPUT_RIGHT 0x02
#define LCR_RACING_INPUT_BACK 0x04
#define LCR_RACING_INPUT_LEFT 0x08
#define LCR_RACING_EVENT_CP_TAKEN 0x0001
#define LCR_RACING_EVENT_FINISHED 0x0002
#define LCR_RACING_EVENT_CRASH_SMALL 0x0004
#define LCR_RACING_EVENT_CRASH_BIG 0x0008
#define LCR_PHYSICS_UNIT 4096 ///< length of map square for physics engine
#define LCR_PHYSICS_UNIT 4096 ///< len. of square for phys. engine
#define TPE_RESHAPE_TENSION_LIMIT 3
#define TPE_RESHAPE_ITERATIONS 8
@ -66,14 +66,14 @@ struct
Lower bits record current collisions, higher
bits the previous state (for averaging). */
TPE_Vec3 carPositions[2]; ///* Current and previous position in game units.
TPE_Vec3 carRotations[2]; ///* Current and previous rotation in game units.
uint8_t carDrifting; ///* Whether or not the car is currently in drift.
TPE_Vec3 carPositions[2]; ///< Current and previous position in game units.
TPE_Vec3 carRotations[2]; ///< Current and previous rotation in game units.
uint8_t carDrifting; ///< Whether or not the car is currently in drift.
TPE_Vec3 carOKPositions[LCR_CAR_JOINTS];
uint8_t carNotOKCount;
TPE_Unit fanForce; ///* Upwards acceleration caused by a fan.
TPE_Unit fanForce; ///< Upwards acceleration caused by a fan.
LCR_GameUnit wheelRotation;
LCR_GameUnit wheelSteer;
@ -489,8 +489,6 @@ LCR_GameUnit LCR_racingGetCarSpeedSigned(void)
return LCR_racing.carSpeed;
}
uint8_t _LCR_racingCollisionHandler(uint16_t b1, uint16_t j1, uint16_t b2,
uint16_t j2, TPE_Vec3 p)
{
@ -516,12 +514,9 @@ LCR_GameUnit _LCR_racingSmoothRot(LCR_GameUnit angleNew, LCR_GameUnit angleOld)
return angleOld + diff / 2;
}
void _LCR_racingUpdateCarPosRot(void)
TPE_Vec3 _LCR_racingGetWheelCenterPoint(void)
{
TPE_Vec3 tmpVec = LCR_racing.carPositions[0];
TPE_Vec3 wheelAverage = _LCR_TPE_vec3DividePlain(
return _LCR_TPE_vec3DividePlain(
TPE_vec3Plus(
TPE_vec3Plus(
LCR_racing.carBody.joints[0].position,
@ -529,9 +524,15 @@ void _LCR_racingUpdateCarPosRot(void)
TPE_vec3Plus(
LCR_racing.carBody.joints[2].position,
LCR_racing.carBody.joints[3].position)),4);
}
void _LCR_racingUpdateCarPosRot(void)
{
TPE_Vec3 tmpVec = LCR_racing.carPositions[0];
LCR_racing.carPositions[0] = _LCR_TPE_vec3DividePlain(
TPE_vec3TimesPlain(wheelAverage,LCR_GAME_UNIT),LCR_PHYSICS_UNIT);
TPE_vec3TimesPlain(_LCR_racingGetWheelCenterPoint(),LCR_GAME_UNIT),
LCR_PHYSICS_UNIT);
LCR_racing.carPositions[0] = // smooth the position
TPE_vec3KeepWithinBox(LCR_racing.carPositions[1],LCR_racing.carPositions[0],
@ -637,7 +638,6 @@ void LCR_racingInit(void)
&(LCR_racing.carBody),1,_LCR_racingEnvironmentFunction);
LCR_racing.physicsWorld.collisionCallback = _LCR_racingCollisionHandler;
}
/**
@ -742,12 +742,9 @@ void _LCR_racingWheelAccelerate(unsigned int wheel, TPE_Vec3 dir,
if (accelerator)
acc *= 2; // TODO: constant?
LCR_racing.carBody.joints[wheel].velocity[0] +=
(dir.x * acc) / TPE_F;
LCR_racing.carBody.joints[wheel].velocity[1] +=
(dir.y * acc) / TPE_F;
LCR_racing.carBody.joints[wheel].velocity[2] +=
(dir.z * acc) / TPE_F;
LCR_racing.carBody.joints[wheel].velocity[0] += (dir.x * acc) / TPE_F;
LCR_racing.carBody.joints[wheel].velocity[1] += (dir.y * acc) / TPE_F;
LCR_racing.carBody.joints[wheel].velocity[2] += (dir.z * acc) / TPE_F;
}
int _LCR_racingCarShapeOK(void)
@ -1035,16 +1032,7 @@ uint32_t LCR_racingStep(unsigned int input)
if (angle <= 0)
{
LCR_LOG1("roof flipped over, fixing")
LCR_racing.carBody.joints[4].position =
_LCR_TPE_vec3DividePlain(
TPE_vec3Plus(
TPE_vec3Plus(
LCR_racing.carBody.joints[0].position,
LCR_racing.carBody.joints[1].position),
TPE_vec3Plus(
LCR_racing.carBody.joints[2].position,
LCR_racing.carBody.joints[3].position)),4);
LCR_racing.carBody.joints[4].position = _LCR_racingGetWheelCenterPoint();
angle = 0;
}