From 58173ca471c97bc099080975c021fc720aa50140 Mon Sep 17 00:00:00 2001 From: taw27 Date: Tue, 27 May 2008 23:00:51 +0000 Subject: Mostly fix collision detection (collision response now needs work...) git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@46 84d2e878-0bd5-11dd-ad15-13eda11d74c5 --- src/physics.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/physics.c b/src/physics.c index 33a0417..b289b06 100644 --- a/src/physics.c +++ b/src/physics.c @@ -49,16 +49,27 @@ int physics_point_is_inside_hull(GLfloat cx, GLfloat cy, GLfloat cz, GLfloat *fv p1y = fvert[3*0 + 1]; p1z = fvert[3*0 + 2]; - for ( i=1; ip2 */ qx = p2x-p1x; qy = p2y-p1y; qz = p2z-p1z; lx = ny*qz - nz*qy; @@ -115,16 +126,14 @@ int physics_will_collide_face(GLfloat sx, GLfloat sy, GLfloat sz, GLfloat vx, GL name = obj->model->name; } - printf("Testing vertex %8f %8f %8f, velocity %8f %8f %8f against face %8f %8f %8f (%s/%p)\n", - sx, sy, sz, vx, vy, vz, px, py, pz, name, obj); - printf("(%f - %f) / %f\n", pdotn, sdotn, vdotn); - printf("Collision happens at t + %f\n", t); - exit(0); + // printf("Testing vertex %8f %8f %8f, velocity %8f %8f %8f against face %8f %8f %8f (%s/%p)\n", + // sx, sy, sz, vx, vy, vz, px, py, pz, name, obj); + // printf("(%f - %f) / %f\n", pdotn, sdotn, vdotn); + // printf("Collision happens at t + %f\n", t); + // exit(0); return 1; - } else { - printf("!"); } return 0; @@ -164,18 +173,18 @@ static int physics_will_collide(ModelInstance *obj, ModelInstance *other, Uint32 case PRIMITIVE_QUADS : { + /* Faces are quads */ int f; - /* Faces are quads */ for ( f=0; fmodel->primitives[a]->num_vertices/4; f++ ) { GLfloat face[3*4]; int q; for ( q=0; q<4; q++ ) { - face[3*q + 0] = other->x + other->model->primitives[a]->vertices[4*(f+q) + 0]; - face[3*q + 1] = other->y + other->model->primitives[a]->vertices[4*(f+q) + 1]; - face[3*q + 2] = other->z + other->model->primitives[a]->vertices[4*(f+q) + 2]; + face[3*q + 0] = other->x + other->model->primitives[a]->vertices[3*((4*f)+q) + 0]; + face[3*q + 1] = other->y + other->model->primitives[a]->vertices[3*((4*f)+q) + 1]; + face[3*q + 2] = other->z + other->model->primitives[a]->vertices[3*((4*f)+q) + 2]; } if ( physics_will_collide_face(sx, sy, sz, vx, vy, vz, nx, ny, nz, @@ -185,6 +194,7 @@ static int physics_will_collide(ModelInstance *obj, ModelInstance *other, Uint32 } } break; + } } -- cgit v1.2.3