Simplify materials
This commit is contained in:
parent
beee13d2b3
commit
93b622a0a4
3 changed files with 38 additions and 48 deletions
6
assets.h
6
assets.h
|
@ -22,7 +22,7 @@ static const char *LCR_maps[] =
|
||||||
|
|
||||||
"#=s0s0 #fd190" // big concrete
|
"#=s0s0 #fd190" // big concrete
|
||||||
"#=s0B0 #fd910" // concrete wall
|
"#=s0B0 #fd910" // concrete wall
|
||||||
"#^s1A0 #f7110" // ramps before wall
|
"#^s1A0 #fk110" // ramps before wall
|
||||||
|
|
||||||
"#;p0w0L #f5130" // bugs
|
"#;p0w0L #f5130" // bugs
|
||||||
|
|
||||||
|
@ -37,15 +37,13 @@ static const char *LCR_maps[] =
|
||||||
|
|
||||||
"#(s0r0" // hill
|
"#(s0r0" // hill
|
||||||
"#~t1t2 #~u1t2 #~t1u2" // bumps
|
"#~t1t2 #~u1t2 #~t1u2" // bumps
|
||||||
"#^t0r0 #f7110 " // ramps
|
"#^t0r0 #fq110 " // ramps
|
||||||
|
|
||||||
"#}n0l0J #|n1l0J #|n3l0J- #]n4l0J- #=o0l0 #f1510" // loop
|
"#}n0l0J #|n1l0J #|n3l0J- #]n4l0J- #=o0l0 #f1510" // loop
|
||||||
"#]n0m0J #|n1m0J #|n3m0J- #]n4m0J- #=o0m0 #f1510" // loop
|
"#]n0m0J #|n1m0J #|n3m0J- #]n4m0J- #=o0m0 #f1510" // loop
|
||||||
"#}l0k0L #|l1k0L #|l3k0L- #]l4k0L- #=k0k0 #f1510"
|
"#}l0k0L #|l1k0L #|l3k0L- #]l4k0L- #=k0k0 #f1510"
|
||||||
"#]l0j0L #|l1j0L #|l3j0L- #]l4j0L- #=k0j0 #f1510"
|
"#]l0j0L #|l1j0L #|l3j0L- #]l4j0L- #=k0j0 #f1510"
|
||||||
"#-k5k0 #f5120"
|
"#-k5k0 #f5120"
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LCR_IMAGE_SIZE 64 ///< one-dimension resolution of bitmap image
|
#define LCR_IMAGE_SIZE 64 ///< one-dimension resolution of bitmap image
|
||||||
|
|
77
racing.h
77
racing.h
|
@ -31,26 +31,20 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
|
||||||
|
|
||||||
#define LCR_GRAVITY (LCR_PHYSICS_UNIT / 160)
|
#define LCR_GRAVITY (LCR_PHYSICS_UNIT / 160)
|
||||||
#define LCR_CAR_FORWARD_FRICTION (TPE_F / 180)
|
#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_AIR_FRICTION 32
|
||||||
|
|
||||||
#define LCR_CAR_STAND_FRICTION_MULTIPLIER 32
|
#define LCR_CAR_STAND_FRICTION_MULTIPLIER 32
|
||||||
#define LCR_CAR_STEER_FRICTION (TPE_F)
|
#define LCR_CAR_STEER_FRICTION (TPE_F)
|
||||||
#define LCR_CAR_ELASTICITY (TPE_F / 150)
|
#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_ACCELERATION (LCR_PHYSICS_UNIT / 20)
|
||||||
|
|
||||||
#define LCR_CAR_STEER_SPEED (LCR_GAME_UNIT / 16)
|
#define LCR_CAR_STEER_SPEED (LCR_GAME_UNIT / 16)
|
||||||
#define LCR_CAR_STEER_MAX ((7 * LCR_GAME_UNIT) / 24)
|
#define LCR_CAR_STEER_MAX ((7 * LCR_GAME_UNIT) / 24)
|
||||||
|
|
||||||
// TODO
|
// multipliers (in 8ths) of friction and acceleration on concrete:
|
||||||
#define LCR_CAR_FORWARD_FRICTION_ICE (TPE_F / 200)
|
#define LCR_CAR_GRASS_FACTOR 5
|
||||||
#define LCR_CAR_STEER_FRICTION_ICE (TPE_F / 20)
|
#define LCR_CAR_DIRT_FACTOR 3
|
||||||
#define LCR_CAR_ACCELERATION_ICE (LCR_PHYSICS_UNIT / 100)
|
#define LCR_CAR_ICE_FACTOR 1
|
||||||
#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)
|
|
||||||
|
|
||||||
#define LCR_CAR_JOINTS 5
|
#define LCR_CAR_JOINTS 5
|
||||||
#define LCR_CAR_CONNECTIONS 10
|
#define LCR_CAR_CONNECTIONS 10
|
||||||
|
@ -582,29 +576,35 @@ LCR_GameUnit LCR_racingGetWheelSteer(void)
|
||||||
return LCR_racing.wheelSteer;
|
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,
|
void _LCR_racingWheelAccelerate(unsigned int wheel, TPE_Vec3 dir,
|
||||||
uint8_t material)
|
uint8_t material)
|
||||||
{
|
{
|
||||||
TPE_Unit acc =
|
TPE_Unit acc =
|
||||||
material == LCR_BLOCK_MATERIAL_ICE ?
|
_LCR_applyMaterialFactor(LCR_CAR_ACCELERATION,material);
|
||||||
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;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
acc = acc / (1 + (LCR_racingGetCarSpeedUnsigned() / LCR_CAR_AIR_FRICTION));
|
||||||
|
|
||||||
LCR_racing.carBody.joints[wheel].velocity[0] +=
|
LCR_racing.carBody.joints[wheel].velocity[0] +=
|
||||||
(dir.x * acc) / TPE_F;
|
(dir.x * acc) / TPE_F;
|
||||||
|
@ -696,11 +696,7 @@ uint32_t LCR_racingStep(unsigned int input)
|
||||||
}
|
}
|
||||||
|
|
||||||
LCR_racing.carBody.friction =
|
LCR_racing.carBody.friction =
|
||||||
groundMat == LCR_BLOCK_MATERIAL_ICE ?
|
_LCR_applyMaterialFactor(LCR_CAR_FORWARD_FRICTION,groundMat);
|
||||||
LCR_CAR_FORWARD_FRICTION_ICE :
|
|
||||||
(groundMat == LCR_BLOCK_MATERIAL_DIRT ?
|
|
||||||
LCR_CAR_FORWARD_FRICTION_DIRT :
|
|
||||||
LCR_CAR_FORWARD_FRICTION);
|
|
||||||
|
|
||||||
if(!(input & (LCR_RACING_INPUT_FORW | LCR_RACING_INPUT_BACK)))
|
if(!(input & (LCR_RACING_INPUT_FORW | LCR_RACING_INPUT_BACK)))
|
||||||
LCR_racing.carBody.friction *= LCR_CAR_STAND_FRICTION_MULTIPLIER;
|
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 */
|
determined by the dot product (angle) of the axis and velocity */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TPE_Vec3 fric = TPE_vec3Times(ja,(TPE_vec3Dot(ja,jv) *
|
TPE_Vec3 fric = TPE_vec3Times(ja,(TPE_vec3Dot(ja,jv) *
|
||||||
(/*groundMat == LCR_BLOCK_MATERIAL_CONCRETE*/ 1 ?
|
_LCR_applyMaterialFactor(LCR_CAR_STEER_FRICTION,groundMat)) / TPE_F);
|
||||||
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);
|
|
||||||
|
|
||||||
jv = TPE_vec3Minus(jv,fric); // subtract the friction
|
jv = TPE_vec3Minus(jv,fric); // subtract the friction
|
||||||
|
|
||||||
|
@ -926,13 +915,13 @@ if (TPE_vec3Dot(carVel,carForw) < 0)
|
||||||
{
|
{
|
||||||
// car not OK
|
// car not OK
|
||||||
|
|
||||||
if (LCR_racing.carNotOKCount > 5) // TODO: constant
|
if (LCR_racing.carNotOKCount > 10) // TODO: constant
|
||||||
{
|
{
|
||||||
LCR_LOG1("car not OK (short), fixing");
|
LCR_LOG1("car not OK (short), fixing");
|
||||||
|
|
||||||
for (int i = 0; i < LCR_CAR_JOINTS; ++i)
|
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
|
// for a while try to smoothly iterate towards previous OK position
|
||||||
LCR_racing.carBody.joints[i].position =
|
LCR_racing.carBody.joints[i].position =
|
||||||
|
|
|
@ -1510,6 +1510,9 @@ void LCR_rendererCameraFollow(void)
|
||||||
S3L_lookAt(LCR_renderer.carModel->transform.translation,
|
S3L_lookAt(LCR_renderer.carModel->transform.translation,
|
||||||
&(LCR_renderer.scene.camera.transform));
|
&(LCR_renderer.scene.camera.transform));
|
||||||
|
|
||||||
|
// look a bit up to see further ahead:
|
||||||
|
LCR_renderer.scene.camera.transform.rotation.x += S3L_F / 32;
|
||||||
|
|
||||||
#if LCR_SETTING_SMOOTH_ANIMATIONS
|
#if LCR_SETTING_SMOOTH_ANIMATIONS
|
||||||
// now average with previous transform to smooth the animation out:
|
// now average with previous transform to smooth the animation out:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue