bool collideRectangle(physicalPoint_s* o, vect3Df_s p, vect3Df_s s) { if(!o)return false; vect3Df_s o2 = getClosestPointRectangle(p, s, o->position); int i; for(i=0; i < NUM_PORTALS; i++) { if(portals[i].target && portals[i].open && portals[i].target->open)collidePortal(p, s, &portals[i], &o2); } vect3Df_s v = vsubf(o2, o->position); float gval = vdotf(v, normGravityVector); vect3Df_s v2 = vsubf(v, vmulf(normGravityVector, gval)); float sqd = (v2.x*v2.x)+(v2.y*v2.y)+(v2.z*v2.z)+((gval*gval)/ transY); if(sqd < o->sqRadius) { float sqd = (v2.x*v2.x)+(v2.y*v2.y)+(v2.z*v2.z)+(gval*gval)/transY; float d = sqrtf(sqd); v = vdivf(vmulf(vect3Df(v.x, v.y, v.z), -(o->radius-d)), d); o->position = vaddf(o->position, v); return true; } return false; }
vect3D getClosestPointRectangleStruct(rectangle_struct* rec, vect3D o) { vect3D p=vect(rec->position.x*TILESIZE*2,rec->position.y*HEIGHTUNIT,rec->position.z*TILESIZE*2); vect3D s=vect(rec->size.x*TILESIZE*2,rec->size.y*HEIGHTUNIT,rec->size.z*TILESIZE*2); return getClosestPointRectangle(p, s, o); }