Start antiglitch
This commit is contained in:
parent
3310008a0d
commit
10366c2a09
4 changed files with 71 additions and 65 deletions
42
racing.h
42
racing.h
|
@ -454,6 +454,21 @@ void _LCR_racingWheelAccelerate(unsigned int wheel, TPE_Vec3 dir)
|
|||
(dir.z * LCR_CAR_ACCELERATION) / TPE_F;
|
||||
}
|
||||
|
||||
int _LCR_racingCarShapeOK(void)
|
||||
{
|
||||
int r = 1;
|
||||
|
||||
for (int i = 0; i < LCR_racing.carBody.jointCount; ++i)
|
||||
r &= TPE_connectionTension(TPE_dist(
|
||||
LCR_racing.carBody.joints[
|
||||
LCR_racing.carBody.connections[i].joint1].position,
|
||||
LCR_racing.carBody.joints[
|
||||
LCR_racing.carBody.connections[i].joint2].position),
|
||||
LCR_racing.carBody.connections[i].length) < TPE_F / 16; // TODO: const
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
Updates the racing physics world, call every LCR_RACING_TICK_MS milliseconds.
|
||||
*/
|
||||
|
@ -645,33 +660,8 @@ LCR_racing.carPositions[0] =
|
|||
}
|
||||
}
|
||||
|
||||
// now try to decide if car shape is OK
|
||||
TPE_Unit v1, v2;
|
||||
|
||||
v1 = TPE_vec3Dot(
|
||||
TPE_vec3Minus(
|
||||
LCR_racing.carBody.joints[1].position,
|
||||
LCR_racing.carBody.joints[0].position),
|
||||
TPE_vec3Minus(
|
||||
LCR_racing.carBody.joints[3].position,
|
||||
LCR_racing.carBody.joints[0].position));
|
||||
|
||||
v2 = TPE_vec3Dot(
|
||||
TPE_vec3Minus(
|
||||
LCR_racing.carBody.joints[1].position,
|
||||
LCR_racing.carBody.joints[2].position),
|
||||
TPE_vec3Minus(
|
||||
LCR_racing.carBody.joints[3].position,
|
||||
LCR_racing.carBody.joints[2].position));
|
||||
|
||||
v1 = v1 > v2 ? ((v1 * LCR_GAME_UNIT) / TPE_nonZero(v2)) :
|
||||
((v2 * LCR_GAME_UNIT) / TPE_nonZero(v1));
|
||||
|
||||
#define _TOLERANCE (LCR_GAME_UNIT / 8)
|
||||
|
||||
if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) ||
|
||||
v1 < (LCR_GAME_UNIT - _TOLERANCE) ||
|
||||
v1 > (LCR_GAME_UNIT + _TOLERANCE))
|
||||
!_LCR_racingCarShapeOK())
|
||||
{
|
||||
// car not OK
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue