Browse Source

Fix a bug

Miloslav Ciz 3 years ago
parent
commit
eaa84e01c0
3 changed files with 22 additions and 14 deletions
  1. 2 1
      programs/2d.c
  2. 1 1
      programs/make.sh
  3. 19 12
      tinyphysicsengine.h

+ 2 - 1
programs/2d.c

@@ -41,7 +41,8 @@ else
 
 
 
 
     tpe_world.bodies[i].friction = 400;
     tpe_world.bodies[i].friction = 400;
-    
+   
+ 
 tpe_world.bodies[i].elasticity = 100;
 tpe_world.bodies[i].elasticity = 100;
 
 
     TPE_bodyMove(&tpe_world.bodies[i],TPE_vec3(-1000 + i * 800,ROOM_H / 4,0));
     TPE_bodyMove(&tpe_world.bodies[i],TPE_vec3(-1000 + i * 800,ROOM_H / 4,0));

+ 1 - 1
programs/make.sh

@@ -1,5 +1,5 @@
 #!/bin/bash
 #!/bin/bash
 
 
-PROGRAM=player # change this to name of a program you want to compile :)
+PROGRAM=car # change this to name of a program you want to compile :)
 
 
 clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -O3 -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wno-unused-parameter -Wno-missing-field-initializers -o $PROGRAM $PROGRAM.c -lm -lSDL2 && ./$PROGRAM
 clear; clear; g++ -x c -g -fmax-errors=5 -pedantic -O3 -Wall -Wextra -Wstrict-prototypes -Wold-style-definition -Wno-unused-parameter -Wno-missing-field-initializers -o $PROGRAM $PROGRAM.c -lm -lSDL2 && ./$PROGRAM

+ 19 - 12
tinyphysicsengine.h

@@ -896,21 +896,28 @@ void TPE_worldStep(TPE_World *world)
         connection++;
         connection++;
       }
       }
 
 
-      if (body->connectionCount > 0 && !(body->flags & TPE_BODY_FLAG_SOFT))
+      if (body->connectionCount > 0)
       {
       {
-        TPE_bodyReshape(body,world->environmentFunction);
-
-        bodyTension /= body->connectionCount;
-      
-        if (bodyTension > TPE_RESHAPE_TENSION_LIMIT)
+        if (body->flags & TPE_BODY_FLAG_SOFT)
         {
         {
-          for (uint8_t k = 0; k < TPE_RESHAPE_ITERATIONS; ++k)
-            TPE_bodyReshape(body,world->environmentFunction);
+          TPE_bodyCancelOutVelocities(body);
         }
         }
-#if TPE_CANCEL_OUT_VELOCITIES
         else
         else
-          TPE_bodyCancelOutVelocities(body);
-#endif
+        {
+          TPE_bodyReshape(body,world->environmentFunction);
+
+          bodyTension /= body->connectionCount;
+        
+          if (bodyTension > TPE_RESHAPE_TENSION_LIMIT)
+          {
+            for (uint8_t k = 0; k < TPE_RESHAPE_ITERATIONS; ++k)
+              TPE_bodyReshape(body,world->environmentFunction);
+          }
+      #if TPE_CANCEL_OUT_VELOCITIES
+          else
+            TPE_bodyCancelOutVelocities(body);
+      #endif
+        }
       }
       }
     }
     }
 
 
@@ -1030,7 +1037,7 @@ void TPE_bodyCancelOutVelocities(TPE_Body *body)
 
 
     TPE_Unit tension = TPE_connectionTension(TPE_LENGTH(dir),c->length);
     TPE_Unit tension = TPE_connectionTension(TPE_LENGTH(dir),c->length);
 
 
-    if (tension <= TPE_TENSION_ACCELERATION_THRESHOLD ||
+    if (tension <= TPE_TENSION_ACCELERATION_THRESHOLD &&
       tension >= -1 * TPE_TENSION_ACCELERATION_THRESHOLD)
       tension >= -1 * TPE_TENSION_ACCELERATION_THRESHOLD)
     {
     {
       TPE_Vec3
       TPE_Vec3