Exemplo n.º 1
0
 public void destroyParticlesFillShape(FluidFixtureShape shape)
 {
     for (int i = 0; i < count; i++)
     {
         if (shape.testPoint(particleBuffer [i].position))
         {
             destroyParticle(particleBuffer [i], true);
         }
     }
 }
Exemplo n.º 2
0
        public List <FluidParticle> getParticlesInShape(FluidFixtureShape shape)
        {
            List <FluidParticle> fp = new List <FluidParticle> ();

            for (int i = 0; i < count; i++)
            {
                if (shape.testPoint(particleBuffer [i].position))
                {
                    fp.Add(particleBuffer[i]);
                }
            }
            return(fp);
        }
Exemplo n.º 3
0
            public override void reportFixtureAndParticle(FluidFixtureShape fixture, FluidParticle fp)
            {
                //Rigidbody2D body = fixture.GetComponent<Rigidbody2D> ();
                Vector2 ap  = fp.position;
                Vector2 av  = fp.velocity;
                Ray2D   ray = new Ray2D();

                //RaycastHit2D hit;
                if (fluidSystem.iterationIndex == 0)
                {
                    //					// Put 'ap' in the local space of the previous frame
                    //					b2Vec2 p1 = b2MulT(body->m_xf0, ap);
                    //					if (fixture->GetShape()->GetType() == b2Shape::e_circle)
                    //					{
                    //						// Make relative to the center of the circle
                    //						p1 -= body->GetLocalCenter();
                    //						// Re-apply rotation about the center of the
                    //						// circle
                    //						p1 = b2Mul(body->m_xf0.q, p1);
                    //						// Subtract rotation of the current frame
                    //						p1 = b2MulT(body->m_xf.q, p1);
                    //						// Return to local space
                    //						p1 += body->GetLocalCenter();
                    //					}
                    //					// Return to global space and apply rotation of current frame
                    //					input.p1 = b2Mul(body->m_xf, p1);
                    ray.origin = fp.prevPosition;
                }
                else
                {
                    ray.origin = ap;
                }
                ray.direction = av;

                //hit = Physics2D.Raycast (ray.origin, ray.direction, av.magnitude * dt);
                Physics2D.Raycast(ray.origin, ray.direction, av.magnitude * dt);
                //if (hit) {
                //					b2Vec2 p =
                //						(1 - output.fraction) * input.p1 +
                //							output.fraction * input.p2 +
                //							b2_linearSlop * n;
                //Vector2 v = (hit.point - ap) / dt;
                //				fp.velocity = v;
                //Vector2 f = fluidSystem.getParticleMass () * (av - v);
                //				fluidSystem.particleApplyForce(fp, f);
                //}
            }
Exemplo n.º 4
0
            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);
                }
            }
Exemplo n.º 5
0
        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--;
                }
            }
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
 void Start()
 {
     shape = GetComponent <FluidFixtureShape> ();
 }
Exemplo n.º 8
0
 public void removeFixture(FluidFixtureShape fixture)
 {
     fixtureBuffer.Remove(fixture);
     fixture.removeFrom(this);
 }
Exemplo n.º 9
0
 public void addFixture(FluidFixtureShape fixture)
 {
     fixtureBuffer.Add(fixture);
     fixture.addTo(this);
 }
 public abstract void reportFixtureAndParticle(FluidFixtureShape fixture, FluidParticle fp);