|
|
@@ -10,8 +10,8 @@
|
|
|
|
|
|
TPE_Vec3 environmentDistance(TPE_Vec3 p, TPE_Unit maxD)
|
|
|
{
|
|
|
-TPE_ENV_START( TPE_envSphereInside(p,TPE_vec3(0,0,0),SPHERE_R),p )
|
|
|
-TPE_ENV_END
|
|
|
+ TPE_ENV_START( TPE_envSphereInside(p,TPE_vec3(0,0,0),SPHERE_R),p )
|
|
|
+ TPE_ENV_END
|
|
|
}
|
|
|
|
|
|
uint8_t debugDrawOn = 1;
|
|
|
@@ -26,7 +26,6 @@ int main(void)
|
|
|
|
|
|
s3l_scene.camera.transform.translation.z = -1 * SPHERE_R - 1000;
|
|
|
|
|
|
-
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
{
|
|
|
switch (i)
|
|
|
@@ -38,24 +37,23 @@ int main(void)
|
|
|
default: break;
|
|
|
}
|
|
|
|
|
|
-TPE_Body *b = &tpe_world.bodies[tpe_world.bodyCount - 1];
|
|
|
-
|
|
|
- TPE_bodyMove(b,TPE_vec3((i - 2) * 1200,0,0));
|
|
|
-
|
|
|
+ TPE_Body *b = &tpe_world.bodies[tpe_world.bodyCount - 1];
|
|
|
|
|
|
-b->friction = 0;
|
|
|
-b->elasticity = TPE_FRACTIONS_PER_UNIT;
|
|
|
+ TPE_bodyMove(b,TPE_vec3((i - 2) * 1200,0,0));
|
|
|
|
|
|
-TPE_bodyAccelerate(b,
|
|
|
+ /* We don't want any energy losses due to friction and non-elastic collision,
|
|
|
+ so we'll turn them off. This alone won't be enough though as numeric errors
|
|
|
+ will still change the total energy. */
|
|
|
|
|
|
-TPE_vec3Plus(
|
|
|
-TPE_vec3Times(TPE_bodyGetCenterOfMass(b),50),
|
|
|
-TPE_vec3(0,10,0))
|
|
|
+ b->friction = 0;
|
|
|
+ b->elasticity = TPE_FRACTIONS_PER_UNIT;
|
|
|
|
|
|
-);
|
|
|
- }
|
|
|
+ TPE_bodyAccelerate(b, // give some initial velocity
|
|
|
+ TPE_vec3Plus(TPE_vec3Times(TPE_bodyGetCenterOfMass(b),55),TPE_vec3(0,8,0)));
|
|
|
+ }
|
|
|
|
|
|
-TPE_Unit sTotal = TPE_worldGetNetSpeed(&tpe_world);
|
|
|
+ TPE_Unit sTotal = TPE_worldGetNetSpeed(&tpe_world);
|
|
|
+ // ^ keep the record of total speed
|
|
|
|
|
|
while (helper_running)
|
|
|
{
|
|
|
@@ -63,45 +61,23 @@ TPE_Unit sTotal = TPE_worldGetNetSpeed(&tpe_world);
|
|
|
|
|
|
helper_cameraFreeMovement();
|
|
|
|
|
|
- if (helper_frame % 16 == 0)
|
|
|
- {
|
|
|
- //helper_printCPU();
|
|
|
- //helper_printCamera();
|
|
|
-
|
|
|
- if (sdl_keyboard[SDL_SCANCODE_L])
|
|
|
- for (int i = 0; i < tpe_world.bodyCount; ++i)
|
|
|
- {
|
|
|
- TPE_bodyActivate(&tpe_world.bodies[i]);
|
|
|
- TPE_bodyAccelerate(&tpe_world.bodies[i],
|
|
|
- TPE_vec3(0,(500 * 30) / FPS,0));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- timeMeasure = 0;
|
|
|
- }
|
|
|
-
|
|
|
-unsigned long t1 = helper_getMicroSecs();
|
|
|
-
|
|
|
TPE_worldStep(&tpe_world);
|
|
|
|
|
|
-timeMeasure += helper_getMicroSecs() - t1;
|
|
|
-
|
|
|
- helper_set3dColor(180,10,10);
|
|
|
-
|
|
|
-TPE_Unit s = TPE_worldGetNetSpeed(&tpe_world);
|
|
|
-
|
|
|
-TPE_Unit ratio = (sTotal * TPE_FRACTIONS_PER_UNIT) / TPE_nonZero(s);
|
|
|
+ TPE_Unit s = TPE_worldGetNetSpeed(&tpe_world);
|
|
|
+ TPE_Unit ratio = (sTotal * TPE_FRACTIONS_PER_UNIT) / TPE_nonZero(s);
|
|
|
|
|
|
-if (ratio < (4 * TPE_FRACTIONS_PER_UNIT) / 5 ||
|
|
|
- ratio > (6 * TPE_FRACTIONS_PER_UNIT) / 5)
|
|
|
-{
|
|
|
+ if (ratio < (4 * TPE_FRACTIONS_PER_UNIT) / 5 ||
|
|
|
+ ratio > (6 * TPE_FRACTIONS_PER_UNIT) / 5)
|
|
|
+ {
|
|
|
+ // if total speed changed by more than 1/5, we adjust it
|
|
|
|
|
|
-printf("net speed is now %d but needs to be %d, correcting!\n",s,sTotal);
|
|
|
+ printf("net speed is now %d but needs to be %d, correcting!\n",s,sTotal);
|
|
|
|
|
|
-for (int i = 0; i < tpe_world.bodyCount; ++i)
|
|
|
- TPE_bodyMultiplyNetSpeed(&tpe_world.bodies[i],ratio);
|
|
|
+ for (int i = 0; i < tpe_world.bodyCount; ++i)
|
|
|
+ TPE_bodyMultiplyNetSpeed(&tpe_world.bodies[i],ratio);
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
+ helper_set3dColor(200,10,10);
|
|
|
|
|
|
for (int i = 0; i < tpe_world.bodyCount; ++i)
|
|
|
{
|
|
|
@@ -110,10 +86,10 @@ for (int i = 0; i < tpe_world.bodyCount; ++i)
|
|
|
TPE_Vec3 right = TPE_vec3(512,0,0);
|
|
|
TPE_Vec3 forw = TPE_vec3(0,0,512);
|
|
|
|
|
|
-TPE_bodyActivate(&tpe_world.bodies[i]);
|
|
|
+ TPE_bodyActivate(&tpe_world.bodies[i]); // don't let bodies deactivate
|
|
|
|
|
|
- if (i != 1)
|
|
|
- {
|
|
|
+ if (i != 1) // ugly code to get the correct orientation :)
|
|
|
+ {
|
|
|
if (i != 3)
|
|
|
{
|
|
|
forw = TPE_vec3Minus(joints[2].position,joints[0].position);
|
|
|
@@ -125,7 +101,7 @@ TPE_bodyActivate(&tpe_world.bodies[i]);
|
|
|
|
|
|
TPE_Vec3 orient = TPE_rotationFromVecs(forw,right);
|
|
|
|
|
|
- switch (i % 5)
|
|
|
+ switch (i % 5) // and draw the correct shape
|
|
|
{
|
|
|
case 0: helper_draw3dBox(pos,TPE_vec3(1200,1200,1200),orient); break;
|
|
|
case 1: helper_draw3dSphere(pos,TPE_vec3(500,500,500),orient); break;
|
|
|
@@ -137,8 +113,8 @@ TPE_bodyActivate(&tpe_world.bodies[i]);
|
|
|
|
|
|
helper_set3dColor(200,200,200);
|
|
|
|
|
|
-helper_draw3dSphereInside(TPE_vec3(0,0,0),TPE_vec3(SPHERE_R,SPHERE_R,SPHERE_R),
|
|
|
- TPE_vec3(0,0,0) );
|
|
|
+ helper_draw3dSphereInside(TPE_vec3(0,0,0),
|
|
|
+ TPE_vec3(SPHERE_R,SPHERE_R,SPHERE_R),TPE_vec3(0,0,0));
|
|
|
|
|
|
if (helper_debugDrawOn)
|
|
|
helper_debugDraw(1);
|