From cb49aacee1dd0d9d4f09a59b10542b73769b9715 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 13 Aug 2008 12:09:23 +0100 Subject: Attempt to load model file again as collision model, but don't subdivide --- src/model.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/model.c b/src/model.c index 8abbc42..5c12f0e 100644 --- a/src/model.c +++ b/src/model.c @@ -233,7 +233,18 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render } fh = fopen(tmp, "r"); if ( fh == NULL ) { - return -1; + if ( coll ) { + /* Couldn't open a collision model with name -coll. + * Try again using the original model */ + snprintf(tmp, 63, "%s/models/%s", DATADIR, name); + fh = fopen(tmp, "r"); + if ( fh == NULL ) { + return 1; + } + subdiv = 0; + } else { + return 1; + } } if ( coll ) { model->num_coll_primitives = 0; @@ -324,7 +335,7 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render } /* Subdivide the previous face if requested */ - if ( !coll && subdiv && (sscanf(line, "subdivide %f %f", &x, &y) == 2) ) { + if ( subdiv && (sscanf(line, "subdivide %f %f", &x, &y) == 2) ) { if ( type == PRIMITIVE_QUADS ) { if ( (num_vertices > 0) && ((num_vertices % 4)==0) ) { GLfloat u, v; -- cgit v1.2.3 From db4e00bd8e3568eee1edfcfb2b90426275c11aac Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 14 Aug 2008 17:12:23 +0100 Subject: Add (commented) mugwatch --- src/physics.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/physics.c b/src/physics.c index 7867fd1..38f41b6 100644 --- a/src/physics.c +++ b/src/physics.c @@ -201,6 +201,10 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, doubl int i; int found = 0; + if ( strcmp("pipe", other->model->name) == 0 ) { + // printf("pipe prim 0 has %i vertices\n", other->model->primitives[0]->num_vertices); + // printf("pipe cprim 0 has %i vertices\n", other->model->coll_primitives[0]->num_vertices); + } /* Check all the vertices in the moving object... */ for ( i=0; imodel->num_coll_primitives; i++ ) { int j; -- cgit v1.2.3 From 927f39b74d86d329bde1ded5eeaa9b235b3d9c86 Mon Sep 17 00:00:00 2001 From: Tom White Date: Thu, 14 Aug 2008 22:56:58 +0100 Subject: Interpolate normals when subdividing --- src/model.c | 61 +++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/src/model.c b/src/model.c index 5c12f0e..3dc6d46 100644 --- a/src/model.c +++ b/src/model.c @@ -343,14 +343,26 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render GLfloat v2x, v2y, v2z; GLfloat v3x, v3y, v3z; GLfloat v4x, v4y, v4z; - GLfloat nx, ny, nz; + GLfloat n1x, n1y, n1z; + GLfloat n2x, n2y, n2z; + GLfloat n3x, n3y, n3z; + GLfloat n4x, n4y, n4z; GLfloat t1x, t1y; GLfloat t2x, t2y; GLfloat t3x, t3y; GLfloat t4x, t4y; - nx = normals[3*(num_vertices-1) + 0]; - ny = normals[3*(num_vertices-1) + 1]; - nz = normals[3*(num_vertices-1) + 2]; + n4x = normals[3*(num_vertices-1) + 0]; + n4y = normals[3*(num_vertices-1) + 1]; + n4z = normals[3*(num_vertices-1) + 2]; + n3x = normals[3*(num_vertices-2) + 0]; + n3y = normals[3*(num_vertices-2) + 1]; + n3z = normals[3*(num_vertices-2) + 2]; + n2x = normals[3*(num_vertices-3) + 0]; + n2y = normals[3*(num_vertices-3) + 1]; + n2z = normals[3*(num_vertices-3) + 2]; + n1x = normals[3*(num_vertices-4) + 0]; + n1y = normals[3*(num_vertices-4) + 1]; + n1z = normals[3*(num_vertices-4) + 2]; v4x = vertices[3*(num_vertices-1) + 0]; v4y = vertices[3*(num_vertices-1) + 1]; v4z = vertices[3*(num_vertices-1) + 2]; @@ -385,6 +397,10 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render GLfloat tl2x, tl2y; GLfloat tl3x, tl3y; GLfloat tl4x, tl4y; + GLfloat nl1x, nl1y, nl1z; + GLfloat nl2x, nl2y, nl2z; + GLfloat nl3x, nl3y, nl3z; + GLfloat nl4x, nl4y, nl4z; /* Interpolate vertices */ l1x = v1x + u*(v2x-v1x)/x; l1y = v1y + u*(v2y-v1y)/x; @@ -407,42 +423,55 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render tl3y = t1y + (u+1)*(t2y-t1y)/x; tl4x = t4x + (u+1)*(t3x-t4x)/x; tl4y = t4y + (u+1)*(t3y-t4y)/x; + /* Interpolate normals */ + nl1x = n1x + u*(n2x-n1x)/x; + nl1y = n1y + u*(n2y-n1y)/x; + nl1z = n1z + u*(n2z-n1z)/x; + nl2x = n4x + u*(n3x-n4x)/x; + nl2y = n4y + u*(n3y-n4y)/x; + nl2z = n4z + u*(n3z-n4z)/x; + nl3x = n1x + (u+1)*(n2x-n1x)/x; + nl3y = n1y + (u+1)*(n2y-n1y)/x; + nl3z = n1z + (u+1)*(n2z-n1z)/x; + nl4x = n4x + (u+1)*(n3x-n4x)/x; + nl4y = n4y + (u+1)*(n3y-n4y)/x; + nl4z = n4z + (u+1)*(n3z-n4z)/x; /* Calculate vertices */ vertices[3*num_vertices+0] = l1x + v*(l2x-l1x)/y; vertices[3*num_vertices+1] = l1y + v*(l2y-l1y)/y; vertices[3*num_vertices+2] = l1z + v*(l2z-l1z)/y; texcoords[2*num_vertices+0] = tl1x + v*(tl2x-tl1x)/y; texcoords[2*num_vertices+1] = tl1y + v*(tl2y-tl1y)/y; - normals[3*num_vertices+0] = nx; - normals[3*num_vertices+1] = ny; - normals[3*num_vertices+2] = nz; + normals[3*num_vertices+0] = nl1x + v*(nl2x-nl1x)/y; + normals[3*num_vertices+1] = nl1y + v*(nl2y-nl1y)/y; + normals[3*num_vertices+2] = nl1z + v*(nl2z-nl1z)/y; num_vertices++; vertices[3*num_vertices+0] = l3x + v*(l4x-l3x)/y; vertices[3*num_vertices+1] = l3y + v*(l4y-l3y)/y; vertices[3*num_vertices+2] = l3z + v*(l4z-l3z)/y; texcoords[2*num_vertices+0] = tl3x + v*(tl4x-tl3x)/y; texcoords[2*num_vertices+1] = tl3y + v*(tl4y-tl3y)/y; - normals[3*num_vertices+0] = nx; - normals[3*num_vertices+1] = ny; - normals[3*num_vertices+2] = nz; + normals[3*num_vertices+0] = nl3x + v*(nl4x-nl3x)/y; + normals[3*num_vertices+1] = nl3y + v*(nl4y-nl3y)/y; + normals[3*num_vertices+2] = nl3z + v*(nl4z-nl3z)/y; num_vertices++; vertices[3*num_vertices+0] = l3x + (v+1)*(l4x-l3x)/y; vertices[3*num_vertices+1] = l3y + (v+1)*(l4y-l3y)/y; vertices[3*num_vertices+2] = l3z + (v+1)*(l4z-l3z)/y; texcoords[2*num_vertices+0] = tl3x + (v+1)*(tl4x-tl3x)/y; texcoords[2*num_vertices+1] = tl3y + (v+1)*(tl4y-tl3y)/y; - normals[3*num_vertices+0] = nx; - normals[3*num_vertices+1] = ny; - normals[3*num_vertices+2] = nz; + normals[3*num_vertices+0] = nl3x + (v+1)*(nl4x-nl3x)/y; + normals[3*num_vertices+1] = nl3y + (v+1)*(nl4y-nl3y)/y; + normals[3*num_vertices+2] = nl3z + (v+1)*(nl4z-nl3z)/y; num_vertices++; vertices[3*num_vertices+0] = l1x + (v+1)*(l2x-l1x)/y; vertices[3*num_vertices+1] = l1y + (v+1)*(l2y-l1y)/y; vertices[3*num_vertices+2] = l1z + (v+1)*(l2z-l1z)/y; texcoords[2*num_vertices+0] = tl1x + (v+1)*(tl2x-tl1x)/y; texcoords[2*num_vertices+1] = tl1y + (v+1)*(tl2y-tl1y)/y; - normals[3*num_vertices+0] = nx; - normals[3*num_vertices+1] = ny; - normals[3*num_vertices+2] = nz; + normals[3*num_vertices+0] = n1x + (v+1)*(nl2x-nl1x)/y; + normals[3*num_vertices+1] = n1y + (v+1)*(nl2y-nl1y)/y; + normals[3*num_vertices+2] = n1z + (v+1)*(nl2z-nl1z)/y; num_vertices++; } } -- cgit v1.2.3 From ff5127bd6362af909223fb530f1392e7741d3ad9 Mon Sep 17 00:00:00 2001 From: Tom White Date: Thu, 14 Aug 2008 23:09:39 +0100 Subject: Fix references to 'primitives' which should be 'coll_primitives', etc --- src/physics.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/physics.c b/src/physics.c index 38f41b6..af1e9a6 100644 --- a/src/physics.c +++ b/src/physics.c @@ -133,22 +133,22 @@ static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *ot int found = 0; - switch ( other->model->primitives[a]->type ) { + switch ( other->model->coll_primitives[a]->type ) { case PRIMITIVE_QUADS : { /* Faces are quads */ int f; - - for ( f=0; fmodel->primitives[a]->num_vertices/4; f++ ) { + + for ( f=0; fmodel->coll_primitives[a]->num_vertices/4; f++ ) { double face[3*4]; int q; double ttc; - const double nx = other->model->primitives[a]->normals[3*(4*f)+0]; - const double ny = other->model->primitives[a]->normals[3*(4*f)+1]; - const double nz = other->model->primitives[a]->normals[3*(4*f)+2]; + const double nx = other->model->coll_primitives[a]->normals[3*(4*f)+0]; + const double ny = other->model->coll_primitives[a]->normals[3*(4*f)+1]; + const double nz = other->model->coll_primitives[a]->normals[3*(4*f)+2]; /* Skip if moving from the back to the front of this quad */ if ( nx*obj->vx + ny*obj->vy + nz*obj->vz > 0.0 ) continue; @@ -157,9 +157,9 @@ static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *ot 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] = ox + other->model->coll_primitives[a]->vertices[3*((4*f)+q) +0]; + face[3*q + 1] = oy + other->model->coll_primitives[a]->vertices[3*((4*f)+q) +1]; + face[3*q + 2] = oz + other->model->coll_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); @@ -218,7 +218,7 @@ static int physics_check_collide(ModelInstance *obj, ModelInstance *other, doubl const double sz = obj->model->coll_primitives[i]->vertices[3*j+2]; /* ...against all primitives in the static object */ - for ( a=0; amodel->num_primitives; a++ ) { + for ( a=0; amodel->num_coll_primitives; a++ ) { if ( physics_check_collide_all_faces(obj, other, dt, a, sx, sy, sz, coll, room, game) ) { found = 1; @@ -471,6 +471,5 @@ void physics_step(Game *game, int dt) { game->time_physics = us + sec*1e6; - } -- cgit v1.2.3