aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/physics.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/physics.c b/src/physics.c
index 6d3ed49..ce0b9bc 100644
--- a/src/physics.c
+++ b/src/physics.c
@@ -138,13 +138,10 @@ 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, Uint32 dt, int a,
double sx, double sy, double sz, double vx, double vy, double vz) {
- const double nx = other->model->primitives[a]->normals[0];
- const double ny = other->model->primitives[a]->normals[1];
- const double nz = other->model->primitives[a]->normals[2];
-
switch ( other->model->primitives[a]->type ) {
case PRIMITIVE_QUADS : {
@@ -158,6 +155,13 @@ static int physics_check_collide_all_faces(ModelInstance *obj, ModelInstance *ot
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];
+
+ /* Skip if moving from the back to the front of this quad */
+ if ( nx*vx + ny*vy + nz*vz > 0.0 ) continue;
+
for ( q=0; q<4; q++ ) {
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];