Continue smoothing

This commit is contained in:
Miloslav Ciz 2024-09-09 21:25:22 +02:00
parent 03b703d454
commit 08fb45b652
2 changed files with 203 additions and 171 deletions

View file

@ -14,7 +14,7 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_RACING_INPUT_BACK 0x04
#define LCR_RACING_INPUT_LEFT 0x08
#define LCR_PHYSICS_UNIT 512 ///< length of map square for physics engine
#define LCR_PHYSICS_UNIT 1024 ///< length of map square for physics engine
#include "map.h"
#include "tinyphysicsengine.h"
@ -22,7 +22,8 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_CAR_JOINTS 5
#define LCR_CAR_CONNECTIONS 10
#define LCR_CAR_FORWARD_FRICTION (TPE_F / 14)
#define LCR_GRAVITY 5
#define LCR_CAR_FORWARD_FRICTION TPE_F / 14
#define LCR_CAR_TURN_FRICTION (3 * TPE_F / 4)
#define LCR_CAR_ELASTICITY (TPE_F / 100)
@ -103,14 +104,14 @@ void LCR_racingInit(void)
LCR_racing.carConnections,LCR_CAR_CONNECTIONS,
TPE_F);
LCR_racing.carBody.friction = LCR_CAR_FORWARD_FRICTION;
LCR_racing.carBody.elasticity = LCR_CAR_ELASTICITY;
TPE_worldInit(&(LCR_racing.physicsWorld),
&(LCR_racing.carBody),1,_LCR_racingEnvironmentFunction);
LCR_racing.physicsWorld.collisionCallback = _LCR_racingCollisionHandler;
LCR_racing.carBody.friction = LCR_CAR_FORWARD_FRICTION;
LCR_racing.carBody.elasticity = LCR_CAR_ELASTICITY;
LCR_racingRestart();
}
@ -188,9 +189,7 @@ void LCR_racingStep(unsigned int input)
TPE_bodyAccelerate(&(LCR_racing.carBody),vel);
}
TPE_bodyApplyGravity(&(LCR_racing.carBody),
TPE_F / 32
);
TPE_bodyApplyGravity(&(LCR_racing.carBody),LCR_GRAVITY);
LCR_racing.wheelCollisions <<= 4;
TPE_worldStep(&(LCR_racing.physicsWorld));
@ -221,20 +220,26 @@ void LCR_racingStep(unsigned int input)
LCR_GAME_UNIT / 4),LCR_racing.carBody.joints[4].position);
}
LCR_racing.carPositions[1] = LCR_racing.carPositions[0];
TPE_Vec3 tmpVec = LCR_racing.carPositions[0];
#define AVERAGE(c) \
(((((LCR_racing.carBody.joints[0].position.c + \
LCR_racing.carBody.joints[1].position.c + \
LCR_racing.carBody.joints[2].position.c + \
LCR_racing.carBody.joints[3].position.c) / 4) + \
LCR_racing.carBody.joints[4].position.c) / 2) * \
LCR_GAME_UNIT) / LCR_PHYSICS_UNIT
LCR_racing.carPositions[0] =
_LCR_TPE_vec3DividePlain(
TPE_vec3TimesPlain(
LCR_racing.carBody.joints[4].position,LCR_GAME_UNIT),
LCR_PHYSICS_UNIT);
LCR_racing.carPositions[0].x = AVERAGE(x);
LCR_racing.carPositions[0].y = AVERAGE(y);
LCR_racing.carPositions[0].z = AVERAGE(z);
#undef AVERAGE
LCR_racing.carPositions[0] =
TPE_vec3KeepWithinBox(
LCR_racing.carPositions[1],
LCR_racing.carPositions[0],
TPE_vec3(
LCR_PHYSICS_UNIT / 64, // TODO: 64
LCR_PHYSICS_UNIT / 64,
LCR_PHYSICS_UNIT / 64
)
);
LCR_racing.carPositions[1] = tmpVec;
}
void LCR_physicsDebugDraw(LCR_GameUnit camPos[3], LCR_GameUnit camRot[2],