diff options
-rw-r--r-- | src/physics.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/physics.c b/src/physics.c index 75113c1..8352e84 100644 --- a/src/physics.c +++ b/src/physics.c @@ -125,7 +125,7 @@ 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) { + double sx, double sy, double sz, CollisionSpec *coll, Room *room, Game *game) { int found = 0; @@ -153,6 +153,9 @@ static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *ot 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]; + 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, @@ -184,7 +187,7 @@ 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) { +static int physics_check_collide(ModelInstance *obj, ModelInstance *other, double dt, CollisionSpec *coll, Room *room, Game *game) { int i; int found = 0; @@ -203,7 +206,7 @@ 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) ) { + if ( physics_check_collide_all_faces(obj, other, dt, a, sx, sy, sz, coll, room, game) ) { found = 1; } } @@ -218,21 +221,27 @@ 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) { - Room *room; int found = 0; + int i; /* Consider only the current room, for now */ - room = game_find_room(game, game->cur_room_x, game->cur_room_y, game->cur_room_z); - if ( room != NULL ) { + for ( i=0; i<game->num_rooms; i++ ) { - /* 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) ) { - found = 1; + 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; + } } - } + } } return found; |