diff options
author | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-06-18 13:36:41 +0000 |
---|---|---|
committer | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-06-18 13:36:41 +0000 |
commit | e51050b7c9b7c573d3b1b2079b978c9876024941 (patch) | |
tree | 183c2e96b9028dd48099c8dd0fa441d7cf464058 /src/physics.c | |
parent | f144fc6fbc30ef8c4a22f57a2e456d0ae58ecbae (diff) |
Stuff
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@96 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src/physics.c')
-rw-r--r-- | src/physics.c | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/src/physics.c b/src/physics.c index cfbdf7e..ec4334f 100644 --- a/src/physics.c +++ b/src/physics.c @@ -200,7 +200,7 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, Uint3 const double vy = obj->vy; const double vz = obj->vz; - double ttc_lowest = 100000.0; + double ttc_lowest = +INFINITY; double nxc = 0.0; double nyc = 0.0; double nzc = 0.0; @@ -226,7 +226,12 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, Uint3 } } - if ( ttc_lowest < dt ) return 0; + if ( ttc_lowest == +INFINITY ) return 0; + + if ( ttc_lowest > dt ) { + printf("will collide with %s/%8p, but too far in the future at %5.2f ms\n", other->model->name, other, ttc_lowest); + return 0; + } if ( (nxc == 0.0) && (nyc == 0.0) && (nzc == 1.0) ) { obj->x += obj->vx * ttc_lowest; @@ -234,34 +239,42 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, Uint3 obj->z += obj->vz * ttc_lowest; obj->vz = 0.0; obj->landed = 1; + printf("Landed!\n"); } else { obj->vx = -obj->vx; obj->vy = -obj->vy; obj->vz = -obj->vz; obj->yawspeed = 0.0; + printf("Bounce!\n"); } - - return 0; + return 1; } /* Called once for each object which isn't just "scenery" */ static void physics_process(ModelInstance *obj, Uint32 dt, Game *game) { - Room *room; + int collided = 0; + do { - /* Consider only the current room */ - room = game_find_room(game, game->cur_room_x, game->cur_room_y, game->cur_room_z); - if ( room != NULL ) { - /* Consider all the objects in this room */ - int j; - for ( j=0; j<room->num_objects; j++ ) { - if ( physics_check_collide(obj, room->objects[j], dt) ) { - return; + Room *room; + + collided = 0; + + /* Consider only the current room */ + room = game_find_room(game, game->cur_room_x, game->cur_room_y, game->cur_room_z); + if ( room != NULL ) { + /* Consider all the objects in this room */ + int j; + for ( j=0; j<room->num_objects; j++ ) { + if ( physics_check_collide(obj, room->objects[j], dt) ) { /* Should be dt - ttc */ + collided = 1; + } } } - } + + } while ( collided ); /* Air friction */ if ( obj->vx > 0.0 ) { @@ -297,7 +310,10 @@ static void physics_process(ModelInstance *obj, Uint32 dt, Game *game) { } /* Gravity */ - if ( (obj->attribs & OBJ_GRAVITY) && (!obj->landed) ) obj->vz -= GRAVITY * dt; + if ( (obj->attribs & OBJ_GRAVITY) && (!obj->landed) ) { + printf("Gravity\n"); + obj->vz -= GRAVITY * dt; + } /* Take a step */ obj->x += obj->vx * dt; |