private static Vector closestVertexOnOBB(Vector p, RectangleParticle r) { Vector d = p.minus(r.curr); Vector q = new Vector(r.curr.x, r.curr.y); int i = 0; for (i = 0; i <= 1; i++) { double dist = d.dot((Vector)r.getAxes()[i]); if (dist >= 0) { dist = ((double)r.getExtents()[i]); } else if (dist < 0) { dist = -((double)r.getExtents()[i]); } q.plusEquals(((Vector)r.getAxes()[i]).mult(dist)); // System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) } return(q); }
private static void testOBBvsOBB(RectangleParticle ra, RectangleParticle rb) { Vector collisionNormal = new Vector(0, 0); double collisionDepth = ModEnumConst.POSITIVE_INFINITY; int i = 0; for (i = 0; i <= 1; i++) { Vector axisA = (Vector)ra.getAxes()[i]; double depthA = testIntervals(ra.getProjection(axisA), rb.getProjection(axisA)); if (depthA == 0) { return; return; } Vector axisB = (Vector)rb.getAxes()[i]; double depthB = testIntervals(ra.getProjection(axisB), rb.getProjection(axisB)); if (depthB == 0) { return; return; } double absA = Math.Abs(depthA); double absB = Math.Abs(depthB); if (absA < Math.Abs(collisionDepth) || absB < Math.Abs(collisionDepth)) { bool altb = absA < absB; collisionNormal = altb ? axisA : axisB; collisionDepth = altb ? depthA : depthB; //*************collision ModEnumConst.nofcollosions = ModEnumConst.nofcollosions + 1; //************* //My.Computer.Audio.Play(System.AppDomain.CurrentDomain.BaseDirectory & "\fall.wav") } } //System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) CollisionResolver.resolveParticleParticle(ra, rb, collisionNormal, collisionDepth); }
private static void testOBBvsCircle(RectangleParticle ra, CircleParticle ca) { Vector collisionNormal = new Vector(0, 0); double collisionDepth = ModEnumConst.POSITIVE_INFINITY; ArrayList depths = new ArrayList(2); int i = 0; //While i < 2 for (i = 0; i <= 1; i++) { Vector boxAxis = (Vector)ra.getAxes()[i]; double depth = testIntervals(ra.getProjection(boxAxis), ca.getProjection(boxAxis)); if (depth == 0) { return; return; } if (Math.Abs(depth) < Math.Abs(collisionDepth)) { collisionNormal = boxAxis; collisionDepth = depth; } depths.Insert(i, depth); // System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) } //End While double r = ca.getRadius(); //SByte objSByte0 = (SByte)depths[0]; int objSByte0 = Convert.ToInt32(depths[0]); //SByte objSByte1 = (SByte)depths[1]; int objSByte1 = Convert.ToInt32(depths[1]); if (Math.Abs(objSByte0) < r && Math.Abs(objSByte1) < r) { Vector vertex = closestVertexOnOBB(ca.curr, ra); collisionNormal = vertex.minus(ca.curr); double mag = collisionNormal.magnitude(); collisionDepth = r - mag; if (collisionDepth > 0) { collisionNormal.divEquals(mag); //*************collision ModEnumConst.nofcollosions = ModEnumConst.nofcollosions + 1; //************* //If ra.myColor = ca.myColor Then // Totalscore = Totalscore + 1 // 'APEngine1.removeParticle(ca) // 'APEngine1.removeParticle(ra) //End If } else { return; return; } } CollisionResolver.resolveParticleParticle(ra, ca, collisionNormal, collisionDepth); }