void solveCollision(float dt) { // This function detects particles which are crossing boundary of bodies // and modifies velocities of them so that they will move just in front of // boundary. This function function also applies the reaction force to // bodies as precisely as the numerical stability is kept. FluidAABB aabb = new FluidAABB(); aabb.lowerBound.x = +float.MaxValue; aabb.lowerBound.y = +float.MaxValue; aabb.upperBound.x = -float.MaxValue; aabb.upperBound.y = -float.MaxValue; for (int i = 0; i < count; i++) { FluidParticle fp = particleBuffer [i]; Vector2 p1 = fp.position; Vector2 p2 = p1 + dt * fp.velocity; aabb.lowerBound = Vector2.Min(aabb.lowerBound, Vector2.Min(p1, p2)); aabb.upperBound = Vector2.Max(aabb.upperBound, Vector2.Max(p1, p2)); } SolveCollisionCallback callback = new SolveCollisionCallback(this, dt); queryAABB(callback, aabb); }
public bool contains(FluidAABB aabb) { bool result = true; result = result && lowerBound.x <= aabb.lowerBound.x; result = result && lowerBound.y <= aabb.lowerBound.y; result = result && aabb.upperBound.x <= upperBound.x; result = result && aabb.upperBound.y <= upperBound.y; return(result); }
public override FluidAABB getAABB() { FluidAABB aabb = new FluidAABB(); aabb.lowerBound.x = transform.position.x - radius; aabb.lowerBound.y = transform.position.y - radius; aabb.upperBound.x = transform.position.x + radius; aabb.upperBound.y = transform.position.y + radius; return(aabb); }
public override FluidAABB getAABB() { FluidAABB aabb = new FluidAABB(); aabb.lowerBound.x = +float.MaxValue; aabb.lowerBound.y = +float.MaxValue; aabb.upperBound.x = -float.MaxValue; aabb.upperBound.y = -float.MaxValue; for (int i = 0; i < vertices.Length; i++) { aabb.lowerBound = Vector2.Min(aabb.lowerBound, vertices [i]); aabb.upperBound = Vector2.Max(aabb.upperBound, vertices [i]); } return(aabb); }
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--; } } }
public bool isOverlap(FluidAABB b) { Vector2 d1, d2; d1 = b.lowerBound - upperBound; d2 = lowerBound - b.upperBound; if (d1.x > 0.0f || d1.y > 0.0f) { return(false); } if (d2.x > 0.0f || d2.y > 0.0f) { return(false); } return(true); }
void computeAABB(out FluidAABB aabb) { aabb = new FluidAABB(); aabb.lowerBound.x = +float.MaxValue; aabb.lowerBound.y = +float.MaxValue; aabb.upperBound.x = -float.MaxValue; aabb.upperBound.y = -float.MaxValue; for (int i = 0; i < count; i++) { Vector2 p = particleBuffer [i].position; aabb.lowerBound = Vector2.Min(aabb.lowerBound, p); aabb.upperBound = Vector2.Max(aabb.upperBound, p); } aabb.lowerBound.x -= particleDiameter; aabb.lowerBound.y -= particleDiameter; aabb.upperBound.x += particleDiameter; aabb.upperBound.y += particleDiameter; }
public void createParticlesFillShapeForGroup(FluidFixtureShape shape, FluidParticleDef def) { float stride = getParticleStride(); FluidAABB aabb = shape.getAABB(); // Color c = def.color; for (float y = Mathf.Floor(aabb.lowerBound.y / stride) * stride; y < aabb.upperBound.y; y += stride) { for (float x = Mathf.Floor(aabb.lowerBound.x / stride) * stride; x < aabb.upperBound.x; x += stride) { Vector2 p = new Vector2(x, y); if (shape.testPoint(p)) { def.position = p; // def.color = new Color(Random.Range(0,2),Random.Range(0,2),Random.Range(0,2)); createParticle(def); } } } // def.color = c; }
public void combine(FluidAABB aabb1, FluidAABB aabb2) { lowerBound = Vector2.Min(aabb1.lowerBound, aabb2.lowerBound); upperBound = Vector2.Max(aabb1.upperBound, aabb2.upperBound); }
public void combine(FluidAABB aabb) { lowerBound = Vector2.Min(lowerBound, aabb.lowerBound); upperBound = Vector2.Max(upperBound, aabb.upperBound); }