Tinker with physics again
This commit is contained in:
parent
b4aa9cd867
commit
0e694589eb
4 changed files with 52 additions and 23 deletions
46
racing.h
46
racing.h
|
@ -57,8 +57,8 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
|
|||
|
||||
#define LCR_PHYSICS_UNIT 4096 ///< len. of square for phys. engine
|
||||
|
||||
#define TPE_RESHAPE_TENSION_LIMIT 3
|
||||
#define TPE_RESHAPE_ITERATIONS 7 /**< Empirically tested, seems to have a
|
||||
#define TPE_RESHAPE_TENSION_LIMIT 8
|
||||
#define TPE_RESHAPE_ITERATIONS 16 /**< Empirically tested, seems to have a
|
||||
big impact on bugs that happen when
|
||||
driving onto a curved ramp under
|
||||
various angles. */
|
||||
|
@ -1128,17 +1128,23 @@ void _LCR_racingWheelAccelerate(unsigned int wheel, TPE_Vec3 dir,
|
|||
|
||||
int _LCR_racingCarShapeOK(void)
|
||||
{
|
||||
int r = 1;
|
||||
TPE_Unit bodyTension = 0;
|
||||
TPE_Connection *c = LCR_racing.carConnections;
|
||||
|
||||
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; // 16: magic con.
|
||||
for (int i = 0; i < LCR_CAR_CONNECTIONS; ++i) // joint tension
|
||||
{
|
||||
bodyTension += TPE_abs(
|
||||
TPE_connectionTension(
|
||||
TPE_LENGTH(
|
||||
TPE_vec3Minus(
|
||||
LCR_racing.carJoints[c->joint1].position,
|
||||
LCR_racing.carJoints[c->joint2].position)),
|
||||
c->length));
|
||||
|
||||
return r;
|
||||
c++;
|
||||
}
|
||||
|
||||
return (bodyTension / LCR_CAR_CONNECTIONS) <= TPE_RESHAPE_TENSION_LIMIT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1444,12 +1450,10 @@ uint32_t LCR_racingStep(unsigned int input)
|
|||
|
||||
TPE_Joint joints[LCR_CAR_JOINTS];
|
||||
|
||||
if (_LCR_racingCarShapeOK()) // in rare cases this may not hold
|
||||
LCR_racing.carBody.flags |= TPE_BODY_FLAG_NONROTATING;
|
||||
else
|
||||
{
|
||||
LCR_LOG1("car not OK in non-rotating step");
|
||||
}
|
||||
if (!_LCR_racingCarShapeOK())
|
||||
printf("NOT OOOOOOOOOOOK\n");
|
||||
|
||||
LCR_racing.carBody.flags |= TPE_BODY_FLAG_NONROTATING;
|
||||
|
||||
for (int i = 0; i < LCR_CAR_JOINTS; ++i)
|
||||
joints[i] = LCR_racing.carBody.joints[i];
|
||||
|
@ -1479,7 +1483,15 @@ uint32_t LCR_racingStep(unsigned int input)
|
|||
|
||||
if ((LCR_racing.carBody.flags & TPE_BODY_FLAG_UNRESOLVED) ||
|
||||
!_LCR_racingCarShapeOK())
|
||||
{
|
||||
printf("SASASASSASASASASASASSAS\n");
|
||||
TPE_bodyStop(&LCR_racing.carBody);
|
||||
|
||||
for (int k = 0; k < 2 * TPE_RESHAPE_ITERATIONS; ++k)
|
||||
TPE_bodyReshape(&LCR_racing.carBody,_LCR_racingEnvironmentFunction);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue