diff options
author | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-06-08 13:50:15 +0000 |
---|---|---|
committer | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-06-08 13:50:15 +0000 |
commit | 1464a566770c24fa0d275c11b7d8e7547314a240 (patch) | |
tree | 954ba271b20f6f744e0c5d2e4d3ed69a737ac3fc /src | |
parent | 901c64df46251c1610a7d765b41b8343b994540a (diff) |
Fix collision detection 'sticking'
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@86 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src')
-rw-r--r-- | src/physics.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/physics.c b/src/physics.c index d163b01..466281d 100644 --- a/src/physics.c +++ b/src/physics.c @@ -88,7 +88,7 @@ int physics_point_is_inside_hull(GLfloat cx, GLfloat cy, GLfloat cz, GLfloat *fv int physics_will_collide_face(GLfloat sx, GLfloat sy, GLfloat sz, GLfloat vx, GLfloat vy, GLfloat vz, GLfloat nx, GLfloat ny, GLfloat nz, GLfloat *fvert, int nfvert, Uint32 dt, - ModelInstance *obj, Uint32 *ttc) { + ModelInstance *obj, GLfloat *ttc) { GLfloat px, py, pz; GLfloat pdotn, sdotn, vdotn; @@ -106,10 +106,7 @@ int physics_will_collide_face(GLfloat sx, GLfloat sy, GLfloat sz, GLfloat vx, GL if ( vdotn == 0.0 ) return 0; /* Collision happens infinitely far in the future */ t = (pdotn - sdotn) / vdotn; - /* If the vertex is exactly on the plane, then moving away from the plane is OK */ - if ( (t == 0.0) && (vdotn > 0.0) ) return 0; - - if ( t < 0.0 ) return 0; /* Collided in the past */ + if ( t <= 0.0 ) return 0; /* Collided in the past */ if ( t > dt ) return 0; /* Not going to collide this step */ /* Boundary test */ @@ -159,7 +156,7 @@ static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *ot GLfloat face[3*4]; int q; - Uint32 ttc; + GLfloat ttc; for ( q=0; q<4; q++ ) { face[3*q + 0] = other->x + other->model->primitives[a]->vertices[3*((4*f)+q) + 0]; @@ -169,7 +166,7 @@ static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *ot if ( physics_will_collide_face(sx, sy, sz, vx, vy, vz, nx, ny, nz, face, 4, dt, other, &ttc) != 0 ) { - printf("collides with %s/%p\n", other->model->name, other); + printf("collides with %s/%p in %5.2f ms\n", other->model->name, other, ttc); if ( (nx == 0.0) && (ny == 0.0) && ( nz == 1.0) ) { obj->x += obj->vx * ttc; |