public override void reportFixtureAndParticle(FluidFixtureShape fixture, FluidParticle fp) { float d; Vector2 n; fixture.computeDistance(fp, out d, out n); if ((d < fluidSystem.particleDiameter) && ((fp.flags & FluidParticleType.WallParticle) == 0)) { Rigidbody2D b = fixture.GetComponent <Rigidbody2D> (); //Vector2 bp = b.transform.position; float bm = b.mass; // b2Vec2 bp = b->GetWorldCenter(); // float32 bI = // b->GetInertia() - bm * b->GetLocalCenter().LengthSquared(); float invBm = bm > 0 ? 1 / bm : 0; // float32 invBI = bI > 0 ? 1 / bI : 0; float invAm = (fp.flags & FluidParticleType.WallParticle) > 0 ? 0 : fluidSystem.getParticleInvMass(); //Vector2 rp = fp.position - bp; // float rpn = rp * n; // float32 rpn = b2Cross(rp, n); // float32 invM = invAm + invBm + invBI * rpn * rpn; float invM = invAm + invBm; FluidParticleBodyContact contact = new FluidParticleBodyContact { fp = fp, body = b, fixture = fixture, weight = 1 - d * fluidSystem.inverseDiameter, normal = -n, mass = invM > 0 ? 1 / invM : 0 }; if (fixture.isTrigger()) { fluidSystem.triggerContactBuffer.Add(contact); fixture.notifyOnTrigger(contact); } else { fluidSystem.bodyContactBuffer.Add(contact); } // m_system->DetectStuckParticle(a); } }
void queryAABB(FluidFixtureParticleQueryCallback callback, FluidAABB aabb) { if (iterationIndex == 0) { triggerContactBuffer.Clear(); } for (int i = 0; i < fixtureBuffer.Count; i++) { FluidFixtureShape fixture = fixtureBuffer [i]; if (fixture != null) { if (fixture.enabled && fixture.gameObject.activeInHierarchy) { if (!fixture.isTrigger() || iterationIndex == 0) { FluidAABB fixtureAABB = fixture.getAABB(); if (fixtureAABB.isOverlap(aabb)) { int lowerTag = computeTag(inverseDiameter * fixtureAABB.lowerBound.x - 1, inverseDiameter * fixtureAABB.upperBound.y + 1); int upperTag = computeTag(inverseDiameter * fixtureAABB.upperBound.x + 1, inverseDiameter * fixtureAABB.lowerBound.y - 1); int beginProxy = 0; int endProxy = count - 1; int firstProxy = findLowerBoundProxy(beginProxy, endProxy, lowerTag); int lastProxy = findUpperBoundProxy(beginProxy, endProxy, upperTag); for (int j = firstProxy; j < lastProxy; j++) { callback.reportFixtureAndParticle(fixture, proxyBuffer [j].fp); } } } } } else { // removeFixture(fi fixtureBuffer.RemoveAt(i); i--; } } }