Work on stabilizing the physics a bit

This commit is contained in:
James Lambert 2022-06-02 07:44:53 -06:00
parent ef17c51a8b
commit e9384716a3
4 changed files with 12 additions and 5 deletions

View file

@ -3,6 +3,7 @@
#include "gjk.h"
#include "contact_insertion.h"
#include "collision_scene.h"
#include "../math/mathf.h"
void collisionObjectInit(struct CollisionObject* object, struct ColliderTypeData *collider, struct RigidBody* body, float mass) {
object->collider = collider;
@ -50,6 +51,10 @@ void collisionObjectCollideWithQuad(struct CollisionObject* object, struct Colli
contact->friction = 0.5f;
contact->restitution = 0.5f;
if (isnan(result.penetration) || isnan(result.contactA.x) || isnan(result.contactB.x) || isnan(result.normal.x)) {
return;
}
contactInsert(contact, &result);
}

View file

@ -8,7 +8,7 @@
#include <string.h>
#define Q3_BAUMGARTE 0.3f
#define Q3_BAUMGARTE 0.1f
#define Q3_PENETRATION_SLOP 0.001f
@ -18,6 +18,8 @@
#define ENABLE_FRICTION 1
#define SOLVER_ITERATIONS 8
struct ContactSolver gContactSolver;
void contactSolverCleanupManifold(struct ContactManifold* manifold) {
@ -381,9 +383,9 @@ void contactSolverIterate(struct ContactSolver* contactSolver) {
void contactSolverSolve(struct ContactSolver* solver) {
contactSolverPreSolve(solver);
contactSolverIterate(solver);
contactSolverIterate(solver);
contactSolverIterate(solver);
for (int i = 0; i < SOLVER_ITERATIONS; ++i) {
contactSolverIterate(solver);
}
}
struct ContactManifold* contactSolverGetContactManifold(struct ContactSolver* solver, struct CollisionObject* shapeA, struct CollisionObject* shapeB) {

View file

@ -6,7 +6,7 @@
extern float gTimePassed;
extern OSTime gLastTime;
#define FRAME_SKIP 2
#define FRAME_SKIP 1
#define FIXED_DELTA_TIME ((1.0f + FRAME_SKIP) / 60.0f)
void timeUpdateDelta();