aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-28 22:41:17 +0000
committertaw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5>2008-05-28 22:41:17 +0000
commite80ac8222e7ab6c32f8deda483d6cfc661b5b751 (patch)
tree6d44fef6b8d986f1fe9233e17885c041019c6868 /src
parent0013c4e06b805e07359188cb0bd06ffb9e33dd8f (diff)
Collision response - make it possible to land
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@52 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src')
-rw-r--r--src/model.c1
-rw-r--r--src/physics.c21
-rw-r--r--src/types.h2
3 files changed, 16 insertions, 8 deletions
diff --git a/src/model.c b/src/model.c
index 30bc289..d182f32 100644
--- a/src/model.c
+++ b/src/model.c
@@ -478,6 +478,7 @@ ModelInstance *model_instance_new(ModelContext *ctx, const char *name, RenderCon
instance->vz = 0.0;
instance->yaw = 0.0;
instance->yawspeed = 0.0;
+ instance->landed = 0.0;
return instance;
diff --git a/src/physics.c b/src/physics.c
index 1277f62..120caff 100644
--- a/src/physics.c
+++ b/src/physics.c
@@ -141,7 +141,7 @@ int physics_will_collide_face(GLfloat sx, GLfloat sy, GLfloat sz, GLfloat vx, GL
}
/* Return non-zero if 'obj' will collide with 'other' with 'dt' milliseconds */
-static int physics_will_collide(ModelInstance *obj, ModelInstance *other, Uint32 dt) {
+static int physics_check_collide(ModelInstance *obj, ModelInstance *other, Uint32 dt) {
int i;
@@ -190,6 +190,15 @@ static int physics_will_collide(ModelInstance *obj, ModelInstance *other, Uint32
if ( physics_will_collide_face(sx, sy, sz, vx, vy, vz, nx, ny, nz,
face, 4, dt, other) != 0 ) {
//printf("collides with %s/%p\n", other->model->name, other);
+ if ( (nx == 0.0) && (ny == 0.0) && ( nz == 1.0) ) {
+ obj->vz = 0.0;
+ obj->landed = 1;
+ } else {
+ obj->vx = -obj->vx;
+ obj->vy = -obj->vy;
+ obj->vz = -obj->vz;
+ obj->yawspeed = 0.0;
+ }
return 1; /* Don't waste time looking anywhere else */
}
}
@@ -219,12 +228,7 @@ static void physics_process(ModelInstance *obj, Uint32 dt, Game *game) {
/* Consider all the objects in this room */
int j;
for ( j=0; j<room->num_objects; j++ ) {
- if ( physics_will_collide(obj, room->objects[j], dt) ) {
- /* Stop the object in its tracks and return */
- obj->vx = -obj->vx;
- obj->vy = -obj->vy;
- obj->vz = -obj->vz;
- obj->yawspeed = 0.0;
+ if ( physics_check_collide(obj, room->objects[j], dt) ) {
return;
}
}
@@ -264,7 +268,7 @@ static void physics_process(ModelInstance *obj, Uint32 dt, Game *game) {
}
/* Gravity */
- if ( obj->attribs & OBJ_GRAVITY ) obj->vz -= GRAVITY * dt;
+ if ( (obj->attribs & OBJ_GRAVITY) && (!obj->landed) ) obj->vz -= GRAVITY * dt;
/* Take a step */
obj->x += obj->vx * dt;
@@ -288,6 +292,7 @@ void physics_step(Game *game, Uint32 t) {
if ( game->fuel > 0.0 ) {
game->lander->vz += THRUST * dt;
game->fuel -= 0.0002;
+ game->lander->landed = 0;
}
}
if ( game->forward ) {
diff --git a/src/types.h b/src/types.h
index c70c9bb..71e8de7 100644
--- a/src/types.h
+++ b/src/types.h
@@ -101,6 +101,8 @@ typedef struct {
float yaw;
float yawspeed;
+ int landed;
+
} ModelInstance;
typedef struct {