aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-07-28 13:23:32 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-07-28 13:23:32 +0000
commit6560468c97c76178dd2316f294ff378b2024fef1 (patch)
treeb6743027dea55006c2d8c472b1671b44da1ed5a7
parent9dea7d83cc1bddf77682deb6581a0f4a6cb24113 (diff)
Tidying up physics.c
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@191 84d2e878-0bd5-11dd-ad15-13eda11d74c5
-rw-r--r--src/physics.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/physics.c b/src/physics.c
index 3c7f2e0..1e64bda 100644
--- a/src/physics.c
+++ b/src/physics.c
@@ -40,7 +40,8 @@
/* Conversion factor between friction and 'yawthrust' */
#define TORQUE 1.5
-int physics_point_is_inside_hull(double cx, double cy, double cz, double *fvert, int nfvert, double nx, double ny, double nz) {
+static int physics_point_is_inside_hull(double cx, double cy, double cz, double *fvert, int nfvert,
+ double nx, double ny, double nz) {
int i;
double p1x, p1y, p1z;
@@ -87,7 +88,7 @@ int physics_point_is_inside_hull(double cx, double cy, double cz, double *fvert,
}
-int physics_will_collide_face(double sx, double sy, double sz, double vx, double vy, double vz,
+static 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, double dt,
double *ttc) {
@@ -125,7 +126,8 @@ int physics_will_collide_face(double sx, double sy, double sz, double vx, double
/* Check for collision with all faces in a primitive */
static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *other, double dt, int a,
- double sx, double sy, double sz, CollisionSpec *coll, Room *room, Game *game) {
+ double sx, double sy, double sz,
+ CollisionSpec *coll, Room *room, Game *game) {
int found = 0;
@@ -150,15 +152,19 @@ static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *ot
if ( nx*obj->vx + ny*obj->vy + nz*obj->vz > 0.0 ) continue;
for ( q=0; q<4; q++ ) {
- 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];
+ const double ox = other->x;
+ const double oy = other->y;
+ const double oz = other->z;
+ face[3*q + 0] = ox + other->model->primitives[a]->vertices[3*((4*f)+q) + 0];
+ face[3*q + 1] = oy + other->model->primitives[a]->vertices[3*((4*f)+q) + 1];
+ face[3*q + 2] = oz + other->model->primitives[a]->vertices[3*((4*f)+q) + 2];
face[3*q + 0] += 10.0*(room->rx - game->cur_room_x);
face[3*q + 1] += 10.0*(room->ry - game->cur_room_y);
face[3*q + 2] += 10.0*(room->rz - game->cur_room_z);
}
- if ( physics_will_collide_face(obj->x+sx, obj->y+sy, obj->z+sz, obj->vx, obj->vy, obj->vz,
+ if ( physics_will_collide_face(obj->x+sx, obj->y+sy, obj->z+sz,
+ obj->vx, obj->vy, obj->vz,
nx, ny, nz, face, 4, dt, &ttc) != 0 ) {
/* Update 'coll' if this collision happens sooner than the current best */
@@ -187,7 +193,8 @@ static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *ot
}
/* Return non-zero if 'obj' will collide with 'other' within 'dt' milliseconds */
-static int physics_check_collide(ModelInstance *obj, ModelInstance *other, double dt, CollisionSpec *coll, Room *room, Game *game) {
+static int physics_check_collide(ModelInstance *obj, ModelInstance *other, double dt, CollisionSpec *coll,
+ Room *room, Game *game) {
int i;
int found = 0;
@@ -206,7 +213,8 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, doubl
/* ...against all primitives in the static object */
for ( a=0; a<other->model->num_primitives; a++ ) {
- if ( physics_check_collide_all_faces(obj, other, dt, a, sx, sy, sz, coll, room, game) ) {
+ if ( physics_check_collide_all_faces(obj, other, dt, a, sx, sy, sz,
+ coll, room, game) ) {
found = 1;
}
}
@@ -243,7 +251,7 @@ static int physics_find_earliest_collision(ModelInstance *obj, Game *game, doubl
}
}
-
+
return found;
}