diff options
author | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-07-30 21:40:52 +0000 |
---|---|---|
committer | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-07-30 21:40:52 +0000 |
commit | 9770acf2e071f07d2b58ac1527d7e5e00626df41 (patch) | |
tree | 550bc1c92a5a046d5f01bf26aad39847e266152e /src | |
parent | 62fc6aad00fcfb09b85cce87a50b30e6422afe21 (diff) |
Only check for collisions in adjacent rooms when lander is close to edges
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@197 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src')
-rw-r--r-- | src/physics.c | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/src/physics.c b/src/physics.c index 00879e7..3472cc5 100644 --- a/src/physics.c +++ b/src/physics.c @@ -226,29 +226,19 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, doubl } -/* Find the earliest collision for 'obj'. Fill out 'coll' and return 1 if any */ -static int physics_find_earliest_collision(ModelInstance *obj, Game *game, double dt, CollisionSpec *coll) { +static int physics_collision_room(ModelInstance *obj, Game *game, double dt, CollisionSpec *coll, + int rx, int ry, int rz) { + Room *room; int found = 0; - int i; - /* Consider only the current room, for now */ - for ( i=0; i<game->num_rooms; i++ ) { - - Room *room; - - room = game->rooms[i]; - - if ( room != NULL ) { - - /* Check for collision of this object with all other objects in the room */ - int j; - for ( j=0; j<room->num_objects; j++ ) { - if ( physics_check_collide(obj, room->objects[j], dt, coll, room, game) ) { - found = 1; - } + room = game_find_room(game, rx, ry, rz); + if ( room != NULL ) { + int j; + for ( j=0; j<room->num_objects; j++ ) { + if ( physics_check_collide(obj, room->objects[j], dt, coll, room, game) ) { + found = 1; } - } } @@ -256,6 +246,40 @@ static int physics_find_earliest_collision(ModelInstance *obj, Game *game, doubl } +/* Find the earliest collision for 'obj'. Fill out 'coll' and return 1 if any */ +static int physics_find_earliest_collision(ModelInstance *obj, Game *game, double dt, CollisionSpec *coll) { + + int found = 0; + int rx, ry, rz; + + rx = game->cur_room_x; + ry = game->cur_room_y; + rz = game->cur_room_z; + if ( physics_collision_room(obj, game, dt, coll, rx, ry, rz) ) found = 1; + + if ( game->lander->x > 4.0 ) { + if ( physics_collision_room(obj, game, dt, coll, rx+1, ry, rz) ) found = 1; + } + if ( game->lander->x < -4.0 ) { + if ( physics_collision_room(obj, game, dt, coll, rx-1, ry, rz) ) found = 1; + } + if ( game->lander->y > 4.0 ) { + if ( physics_collision_room(obj, game, dt, coll, rx, ry+1, rz) ) found = 1; + } + if ( game->lander->y < -4.0 ) { + if ( physics_collision_room(obj, game, dt, coll, rx, ry-1, rz) ) found = 1; + } + if ( game->lander->z > 4.0 ) { + if ( physics_collision_room(obj, game, dt, coll, rx, ry, rz-1) ) found = 1; + } + if ( game->lander->z < -4.0 ) { + if ( physics_collision_room(obj, game, dt, coll, rx, ry, rz-1) ) found = 1; + } + + return found; + +} + /* Called once for each object which isn't just "scenery" */ static void physics_process(ModelInstance *obj, Uint32 dt, Game *game) { |