Simplify materials

This commit is contained in:
Miloslav Ciz 2024-12-05 00:37:50 +01:00
parent beee13d2b3
commit 93b622a0a4
3 changed files with 38 additions and 48 deletions

View file

@ -31,26 +31,20 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_GRAVITY (LCR_PHYSICS_UNIT / 160)
#define LCR_CAR_FORWARD_FRICTION (TPE_F / 180)
//#define LCR_CAR_AIR_FRICTION ((LCR_GAME_UNIT * 3) / 4)
#define LCR_CAR_AIR_FRICTION 32
#define LCR_CAR_STAND_FRICTION_MULTIPLIER 32
#define LCR_CAR_STEER_FRICTION (TPE_F)
#define LCR_CAR_ELASTICITY (TPE_F / 150)
//#define LCR_CAR_ACCELERATION (LCR_PHYSICS_UNIT / 90)
#define LCR_CAR_ACCELERATION (LCR_PHYSICS_UNIT / 20)
#define LCR_CAR_STEER_SPEED (LCR_GAME_UNIT / 16)
#define LCR_CAR_STEER_MAX ((7 * LCR_GAME_UNIT) / 24)
// TODO
#define LCR_CAR_FORWARD_FRICTION_ICE (TPE_F / 200)
#define LCR_CAR_STEER_FRICTION_ICE (TPE_F / 20)
#define LCR_CAR_ACCELERATION_ICE (LCR_PHYSICS_UNIT / 100)
#define LCR_CAR_FORWARD_FRICTION_DIRT (TPE_F / 7)
#define LCR_CAR_STEER_FRICTION_DIRT (TPE_F / 2)
#define LCR_CAR_STEER_FRICTION_GRASS (4 * (TPE_F / 5))
#define LCR_CAR_ACCELERATION_GRASS (LCR_PHYSICS_UNIT / 20)
// multipliers (in 8ths) of friction and acceleration on concrete:
#define LCR_CAR_GRASS_FACTOR 5
#define LCR_CAR_DIRT_FACTOR 3
#define LCR_CAR_ICE_FACTOR 1
#define LCR_CAR_JOINTS 5
#define LCR_CAR_CONNECTIONS 10
@ -582,29 +576,35 @@ LCR_GameUnit LCR_racingGetWheelSteer(void)
return LCR_racing.wheelSteer;
}
TPE_Unit _LCR_applyMaterialFactor(TPE_Unit value, uint8_t mat)
{
switch (mat)
{
case LCR_BLOCK_MATERIAL_GRASS:
value *= LCR_CAR_GRASS_FACTOR;
break;
case LCR_BLOCK_MATERIAL_DIRT:
value *= LCR_CAR_DIRT_FACTOR;
break;
case LCR_BLOCK_MATERIAL_ICE:
value *= LCR_CAR_ICE_FACTOR;
break;
default: value *= 8; break;
}
return value / 8;
}
void _LCR_racingWheelAccelerate(unsigned int wheel, TPE_Vec3 dir,
uint8_t material)
{
TPE_Unit acc =
material == LCR_BLOCK_MATERIAL_ICE ?
LCR_CAR_ACCELERATION_ICE :
(material == LCR_BLOCK_MATERIAL_GRASS ?
LCR_CAR_ACCELERATION_GRASS :
LCR_CAR_ACCELERATION);
/*
acc -=
(acc * LCR_racing.carSpeed) / LCR_CAR_AIR_FRICTION;
*/
acc =
acc / (1 + (LCR_racingGetCarSpeedUnsigned() / LCR_CAR_AIR_FRICTION));
/*
if (acc < 0)
acc = 0;
*/
_LCR_applyMaterialFactor(LCR_CAR_ACCELERATION,material);
acc = acc / (1 + (LCR_racingGetCarSpeedUnsigned() / LCR_CAR_AIR_FRICTION));
LCR_racing.carBody.joints[wheel].velocity[0] +=
(dir.x * acc) / TPE_F;
@ -696,11 +696,7 @@ uint32_t LCR_racingStep(unsigned int input)
}
LCR_racing.carBody.friction =
groundMat == LCR_BLOCK_MATERIAL_ICE ?
LCR_CAR_FORWARD_FRICTION_ICE :
(groundMat == LCR_BLOCK_MATERIAL_DIRT ?
LCR_CAR_FORWARD_FRICTION_DIRT :
LCR_CAR_FORWARD_FRICTION);
_LCR_applyMaterialFactor(LCR_CAR_FORWARD_FRICTION,groundMat);
if(!(input & (LCR_RACING_INPUT_FORW | LCR_RACING_INPUT_BACK)))
LCR_racing.carBody.friction *= LCR_CAR_STAND_FRICTION_MULTIPLIER;
@ -798,16 +794,9 @@ uint32_t LCR_racingStep(unsigned int input)
determined by the dot product (angle) of the axis and velocity */
TPE_Vec3 fric = TPE_vec3Times(ja,(TPE_vec3Dot(ja,jv) *
(/*groundMat == LCR_BLOCK_MATERIAL_CONCRETE*/ 1 ?
LCR_CAR_STEER_FRICTION :
(groundMat == LCR_BLOCK_MATERIAL_DIRT ?
LCR_CAR_STEER_FRICTION_DIRT :
(
groundMat == LCR_BLOCK_MATERIAL_GRASS ?
LCR_CAR_STEER_FRICTION_GRASS :
LCR_CAR_STEER_FRICTION_ICE)))
) / TPE_F);
_LCR_applyMaterialFactor(LCR_CAR_STEER_FRICTION,groundMat)) / TPE_F);
jv = TPE_vec3Minus(jv,fric); // subtract the friction
@ -926,13 +915,13 @@ if (TPE_vec3Dot(carVel,carForw) < 0)
{
// car not OK
if (LCR_racing.carNotOKCount > 5) // TODO: constant
if (LCR_racing.carNotOKCount > 10) // TODO: constant
{
LCR_LOG1("car not OK (short), fixing");
for (int i = 0; i < LCR_CAR_JOINTS; ++i)
{
if (LCR_racing.carNotOKCount < 50) // TODO: const
if (LCR_racing.carNotOKCount < 20) // TODO: const
{
// for a while try to smoothly iterate towards previous OK position
LCR_racing.carBody.joints[i].position =