diff options
author | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-06-10 16:31:35 +0000 |
---|---|---|
committer | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-06-10 16:31:35 +0000 |
commit | 429c794b4fce1e1b389f5e3fe7f790ee5db9b2be (patch) | |
tree | 5ea391988c3f5e9e13581edd519bdb74f0d3488d /src/physics.c | |
parent | 95a32eefcf4cace4e67b47d83fa3632edee0d675 (diff) |
Do collision detection maths with double-precision maths
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@88 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src/physics.c')
-rw-r--r-- | src/physics.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/physics.c b/src/physics.c index 9656572..6d3ed49 100644 --- a/src/physics.c +++ b/src/physics.c @@ -39,11 +39,11 @@ /* Conversion factor between friction and 'yawthrust' */ #define TORQUE 3 -int physics_point_is_inside_hull(GLfloat cx, GLfloat cy, GLfloat cz, GLfloat *fvert, int nfvert, GLfloat nx, GLfloat ny, GLfloat nz) { +int physics_point_is_inside_hull(double cx, double cy, double cz, double *fvert, int nfvert, double nx, double ny, double nz) { int i; - GLfloat p1x, p1y, p1z; - GLfloat p2x, p2y, p2z; + double p1x, p1y, p1z; + double p2x, p2y, p2z; p1x = fvert[3*0 + 0]; p1y = fvert[3*0 + 1]; @@ -56,9 +56,9 @@ int physics_point_is_inside_hull(GLfloat cx, GLfloat cy, GLfloat cz, GLfloat *fv for ( i=1; i<=nfvert; i++ ) { - GLfloat lx, ly, lz; - GLfloat qx, qy, qz; - GLfloat px, py, pz; + double lx, ly, lz; + double qx, qy, qz; + double px, py, pz; if ( i < nfvert ) { p2x = fvert[3*i + 0]; @@ -86,14 +86,14 @@ 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, GLfloat *ttc) { +int physics_will_collide_face(double sx, double sy, double sz, double vx, double vy, double vz, + double nx, double ny, double nz, double *fvert, int nfvert, Uint32 dt, + ModelInstance *obj, double *ttc) { - GLfloat px, py, pz; - GLfloat pdotn, sdotn, vdotn; - GLfloat cx, cy, cz; - GLfloat t; + double px, py, pz; + double pdotn, sdotn, vdotn; + double cx, cy, cz; + double t; /* Range test */ px = fvert[3*0 + 0]; @@ -139,11 +139,11 @@ int physics_will_collide_face(GLfloat sx, GLfloat sy, GLfloat sz, GLfloat vx, GL } static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *other, Uint32 dt, int a, - GLfloat sx, GLfloat sy, GLfloat sz, GLfloat vx, GLfloat vy, GLfloat vz) { + double sx, double sy, double sz, double vx, double vy, double vz) { - const GLfloat nx = other->model->primitives[a]->normals[0]; - const GLfloat ny = other->model->primitives[a]->normals[1]; - const GLfloat nz = other->model->primitives[a]->normals[2]; + const double nx = other->model->primitives[a]->normals[0]; + const double ny = other->model->primitives[a]->normals[1]; + const double nz = other->model->primitives[a]->normals[2]; switch ( other->model->primitives[a]->type ) { @@ -154,9 +154,9 @@ static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *ot for ( f=0; f<other->model->primitives[a]->num_vertices/4; f++ ) { - GLfloat face[3*4]; + double face[3*4]; int q; - GLfloat ttc; + double ttc; for ( q=0; q<4; q++ ) { face[3*q + 0] = other->x + other->model->primitives[a]->vertices[3*((4*f)+q) + 0]; @@ -200,9 +200,9 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, Uint3 int i; - const GLfloat vx = obj->vx; - const GLfloat vy = obj->vy; - const GLfloat vz = obj->vz; + const double vx = obj->vx; + const double vy = obj->vy; + const double vz = obj->vz; /* Consider all the primitives in 'obj' */ for ( i=0; i<obj->model->num_primitives; i++ ) { @@ -213,9 +213,9 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, Uint3 for ( j=0; j<obj->model->primitives[i]->num_vertices; j++ ) { int a; - const GLfloat sx = obj->x + obj->model->primitives[i]->vertices[3*j+0]; - const GLfloat sy = obj->y + obj->model->primitives[i]->vertices[3*j+1]; - const GLfloat sz = obj->z + obj->model->primitives[i]->vertices[3*j+2]; + const double sx = obj->x + obj->model->primitives[i]->vertices[3*j+0]; + const double sy = obj->y + obj->model->primitives[i]->vertices[3*j+1]; + const double sz = obj->z + obj->model->primitives[i]->vertices[3*j+2]; /* Consider all the primitives in 'other' */ for ( a=0; a<other->model->num_primitives; a++ ) { |