Beispiel #1
0
    public void CreateScenario(ParticleSystem a_ParticleSystem)
    {
        const int internalParticles = 8; //amount of particles in hair is this + 2
        Vector2   start             = new Vector2(-4f, 0f);
        Vector2   end = new Vector2(4f, 0f);

        Vector2 step = (end - start) / (internalParticles + 1);

        for (int i = 0; i <= internalParticles + 1; i++)
        {
            Particle p = new Particle(1f);
            p.Position = start + step * i;
            a_ParticleSystem.AddParticle(p);
        }

        //m_ParticleSystem.AddForce(new GravityForce(0.1f));
        float rest = step.magnitude;
        float ks   = 2f;
        float kd   = 1f;

        for (int i = 0; i <= internalParticles; i++)
        {
            a_ParticleSystem.AddForce(new HooksLawSpring(a_ParticleSystem.Particles[i], a_ParticleSystem.Particles[i + 1], rest, ks, kd));
        }
        ks = 2f;
        kd = 1f;
        float angle = 3 * Mathf.PI / 4;

        for (int i = 1; i <= internalParticles; i++)
        {
            a_ParticleSystem.AddForce(new AngularSpringForce(a_ParticleSystem.Particles[i], a_ParticleSystem.Particles[i - 1],
                                                             a_ParticleSystem.Particles[i + 1], angle, ks, kd));
        }
        a_ParticleSystem.AddForce(new ViscousDragForce(1f));
    }
Beispiel #2
0
    public void CreateScenario(ParticleSystem a_ParticleSystem)
    {
        Particle p1 = new Particle(1f);

        p1.Position = new Vector2(3, 4);
        Particle p2 = new Particle(1f);

        p2.Position = new Vector2(-3, 4);
        a_ParticleSystem.AddParticle(p1);
        a_ParticleSystem.AddParticle(p2);
        new CircularWireConstraint(p1, p1.Position + Vector2.right, a_ParticleSystem);
        new CircularWireConstraint(p2, p2.Position + Vector2.left, a_ParticleSystem);
        Particle p3 = new Particle(1);

        p3.Position = new Vector2(3, 2);
        Particle p4 = new Particle(1);

        p4.Position = new Vector2(-3, 2);
        Particle p5 = new Particle(1);

        p5.Position = new Vector2(-4, 0);
        Particle p6 = new Particle(1);

        p6.Position = new Vector2(0, 0);
        Particle p7 = new Particle(1);

        p7.Position = new Vector2(4, 0);
        a_ParticleSystem.AddParticle(p3);
        a_ParticleSystem.AddParticle(p4);
        a_ParticleSystem.AddParticle(p5);
        a_ParticleSystem.AddParticle(p6);
        a_ParticleSystem.AddParticle(p7);

        Force f1 = new HooksLawSpring(p1, p3, 1, 1, 1f);
        Force f2 = new HooksLawSpring(p2, p4, 1, 1, 1f);
        Force f3 = new HooksLawSpring(p3, p7, 1, 1, 1f);
        Force f4 = new HooksLawSpring(p3, p6, 1, 1, 1f);
        Force f5 = new HooksLawSpring(p4, p6, 1, 1, 1f);
        Force f6 = new HooksLawSpring(p4, p5, 1, 1, 1f);
        Force f7 = new HooksLawSpring(p7, p6, 3, 1, 1f);
        Force f8 = new HooksLawSpring(p7, p5, 3, 1, 1f);
        Force f9 = new HooksLawSpring(p6, p5, 3, 1, 1f);

        a_ParticleSystem.AddForce(f1);
        a_ParticleSystem.AddForce(f2);
        a_ParticleSystem.AddForce(f3);
        a_ParticleSystem.AddForce(f4);
        a_ParticleSystem.AddForce(f5);
        a_ParticleSystem.AddForce(f6);
        a_ParticleSystem.AddForce(f7);
        a_ParticleSystem.AddForce(f8);
        a_ParticleSystem.AddForce(f9);

        a_ParticleSystem.AddForce(new GravityForce(.1f));
    }
Beispiel #3
0
    public void CreateScenario(ParticleSystem a_ParticleSystem)
    {
        const float flatness = .95f;
        Vector2     a        = new Vector2(4, -6);
        Vector2     a2       = new Vector2(a.y, -a.x);
        Vector2     b        = new Vector2(-a.x / 2, -a.y / 2);

        Particle p1 = new Particle(1);

        p1.Position = b;
        a_ParticleSystem.AddParticle(p1);
        Vector2 f1 = p1.Position + (1 - flatness) * a;
        Vector2 f2 = p1.Position + flatness * a;

        new EllipticalWireConstraint(p1, f1, f2, a_ParticleSystem);

        Particle p2 = new Particle(1);

        p2.Position = b;
        a_ParticleSystem.AddParticle(p2);
        new AnyLineConstraint(p2, a, a_ParticleSystem);

        Particle p3 = new Particle(1);

        p3.Position = new Vector2(0, 0);
        a_ParticleSystem.AddParticle(p3);
        new AnyLineConstraint(p3, a2, a_ParticleSystem);

        a_ParticleSystem.AddForce(new HooksLawSpring(p1, p2, 0, 5, 1));
        a_ParticleSystem.AddForce(new HooksLawSpring(p1, p3, 0, 1, 1));

        Particle q1 = new Particle(1);
        Particle q2 = new Particle(1);

        q1.Position = f1;
        q2.Position = f2;
        a_ParticleSystem.AddParticle(q1);
        a_ParticleSystem.AddParticle(q2);
        new FixedPointConstraint(q1, a_ParticleSystem);
        new FixedPointConstraint(q2, a_ParticleSystem);

        Particle p4 = new Particle(1);

        p4.Position = p1.Position + a;
        a_ParticleSystem.AddParticle(p4);
        new EllipticalWireConstraint(p4, f1, f2, a_ParticleSystem);
        a_ParticleSystem.AddForce(new HooksLawSpring(q1, p4, 0, 0, 0));
        a_ParticleSystem.AddForce(new HooksLawSpring(q2, p4, 0, 0, 0));
    }
    public void CreateScenario(ParticleSystem a_ParticleSystem)
    {
        int max  = 10;
        int max1 = max - 1;

        for (int i = 0; i < max; i++)
        {
            int   y = i >= max / 2 ? 0 : 4;
            float x = i >= max / 2 ? 3 * (i - max / 2) - 6 : 3 * i - 6;
            createPendulum(a_ParticleSystem, x, y, .5f, i + 2);
        }
        Force f = new GravityForce(1f);

        a_ParticleSystem.AddForce(f);
        f = new ViscousDragForce(.05f);
        a_ParticleSystem.AddForce(f);
    }
Beispiel #5
0
    public void CreateScenario(ParticleSystem a_ParticleSystem)
    {
        Particle p1 = new Particle(1f);

        p1.Position = new Vector2(0, 3);
        a_ParticleSystem.AddParticle(p1);
        new CircularWireConstraint(p1, p1.Position + new Vector2(1, -1), a_ParticleSystem);
        new CircularWireConstraint(p1, p1.Position + new Vector2(-1, -1), a_ParticleSystem);

        Particle p2 = new Particle(1);

        a_ParticleSystem.AddParticle(p2);
        p2.Position = new Vector2(3, 3);
        new RodConstraint(p1, p2, a_ParticleSystem);

        Particle p3 = new Particle(1);
        Particle p4 = new Particle(1);
        Particle p5 = new Particle(1);

        p3.Position = new Vector2(3, 1);
        p4.Position = new Vector2(2, 0);
        p5.Position = new Vector2(4, 0);
        a_ParticleSystem.AddParticle(p3);
        a_ParticleSystem.AddParticle(p4);
        a_ParticleSystem.AddParticle(p5);
        a_ParticleSystem.AddForce(new HooksLawSpring(p3, p4, Mathf.Sqrt(2), 2, 1));
        a_ParticleSystem.AddForce(new HooksLawSpring(p3, p5, Mathf.Sqrt(2), 2, 1));
        a_ParticleSystem.AddForce(new HooksLawSpring(p5, p4, 2, 2, 1));

        a_ParticleSystem.AddForce(new HooksLawSpring(p2, p3, 2, 5, 1));

        a_ParticleSystem.AddForce(new GravityForce(.2f));

        Particle p6 = new Particle(1);

        p6.Position = new Vector2(-3, 4);
        a_ParticleSystem.AddParticle(p6);
        new HLineConstraint(p6, a_ParticleSystem);
        new VLineConstraint(p6, a_ParticleSystem);
    }
    public void CreateScenario(ParticleSystem a_ParticleSystem)
    {
        ViscousDragForce drag = new ViscousDragForce(0.1f);

        a_ParticleSystem.AddForce(drag);

        GravityForce gravity = new GravityForce(0.1f);

        a_ParticleSystem.AddForce(gravity);

        Particle p1 = new Particle(1f);

        p1.Position = new Vector2(-3f, 0f);
        a_ParticleSystem.AddParticle(p1);

        Particle p2 = new Particle(1f);

        p2.Position = new Vector2(3f, 0f);
        a_ParticleSystem.AddParticle(p2);

        HooksLawSpring spring1 = new HooksLawSpring(p1, p2, 3f, 10f, 10f);

        a_ParticleSystem.AddForce(spring1);
    }
Beispiel #7
0
    public void CreateScenario(ParticleSystem a_ParticleSystem)
    {
        const float flatness = .975f;
        Vector2     dir      = new Vector2(2, -8);
        Vector2     dir2     = new Vector2(2, 8);

        Particle p1 = new Particle(1);

        p1.Position = new Vector2(-6, 4);
        a_ParticleSystem.AddParticle(p1);
        new EllipticalWireConstraint(p1, p1.Position + (1 - flatness) * dir, p1.Position + flatness * dir, a_ParticleSystem);

        Particle p2 = new Particle(1);

        p2.Position = new Vector2(-3, -4);
        a_ParticleSystem.AddParticle(p2);
        new EllipticalWireConstraint(p2, p2.Position + flatness * dir2, p2.Position + (1 - flatness) * dir2, a_ParticleSystem);


        Particle p3 = new Particle(1);

        p3.Position = new Vector2(0, 4);
        a_ParticleSystem.AddParticle(p3);
        new EllipticalWireConstraint(p3, p3.Position + (1 - flatness) * dir, p3.Position + flatness * dir, a_ParticleSystem);

        Particle p4 = new Particle(1);

        p4.Position = new Vector2(3, -4);
        a_ParticleSystem.AddParticle(p4);
        new EllipticalWireConstraint(p4, p4.Position + flatness * dir2, p4.Position + (1 - flatness) * dir2, a_ParticleSystem);

        a_ParticleSystem.AddForce(new HooksLawSpring(p1, p3, (p1.Position - p3.Position).magnitude, 1, 1));
        a_ParticleSystem.AddForce(new HooksLawSpring(p2, p4, (p2.Position - p4.Position).magnitude, 1, 1));
        //a_ParticleSystem.AddForce(new HooksLawSpring(p3, p4, (p3.Position - p4.Position).magnitude, 1, 1));

        Particle p5 = new Particle(1);

        p5.Position = new Vector2(6, 0);
        a_ParticleSystem.AddParticle(p5);
        new HLineConstraint(p5, a_ParticleSystem);
        Particle p6 = new Particle(1);

        p6.Position = new Vector2(6, 0);
        a_ParticleSystem.AddParticle(p6);
        new HLineConstraint(p6, a_ParticleSystem);
        a_ParticleSystem.AddForce(new HooksLawSpring(p1, p5, 1, 1));
        a_ParticleSystem.AddForce(new HooksLawSpring(p2, p6, 1, 1));
        a_ParticleSystem.AddForce(new HooksLawSpring(p3, p5, 1, 1));
        a_ParticleSystem.AddForce(new HooksLawSpring(p4, p6, 1, 1));
    }
    private void HandleUserInteraction()
    {
        if (Input.touchSupported)
        {
            if (Input.touchCount > 0)
            {
                Touch[] touches = Input.touches;
                for (int i = 0; i < touches.Length; ++i)
                {
                    Touch   touch      = touches[i];
                    int     id         = touch.fingerId;
                    Vector3 touchPos3D = Camera.main.ScreenToWorldPoint(touch.position);
                    Vector2 touchPos   = new Vector2(touchPos3D.x, touchPos3D.y);
                    if (touch.phase == TouchPhase.Began)
                    {
                        Particle closestParticle;
                        if (GetClosestParticle(touchPos, m_ParticleSelectThreshold, out closestParticle))
                        {
                            MouseSpringForce touchForce = new MouseSpringForce(closestParticle, touchPos, m_MouseSelectRestLength, m_MouseSelectSpringConstant, m_MouseSelectDampingConstant);
                            // This should never happen, but adding anyway for robustness:
                            MouseSpringForce existingForce;
                            if (m_TouchForces.TryGetValue(id, out existingForce))
                            {
                                m_ParticleSystem.RemoveForce(existingForce);
                            }
                            m_TouchForces[id] = touchForce;
                            m_ParticleSystem.AddForce(touchForce);
                        }
                    }
                    else if (touch.phase == TouchPhase.Moved)
                    {
                        MouseSpringForce existingForce;
                        if (m_TouchForces.TryGetValue(id, out existingForce))
                        {
                            existingForce.UpdateMousePosition(touchPos);
                        }
                    }
                    else if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
                    {
                        MouseSpringForce existingForce;
                        if (m_TouchForces.TryGetValue(id, out existingForce))
                        {
                            m_ParticleSystem.RemoveForce(existingForce);
                            m_TouchForces.Remove(id);
                        }
                    }
                }
            }
        }
        if (Input.mousePresent && Input.touchCount == 0)
        {
            Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 mousePos   = new Vector2(mousePos3D.x, mousePos3D.y);

            if (!m_HasMouseSelection && Input.GetMouseButtonDown(0))
            {
                Particle closestParticle;
                if (GetClosestParticle(mousePos, m_ParticleSelectThreshold, out closestParticle))
                {
                    m_CurrentMouseForce = new MouseSpringForce(closestParticle, mousePos, m_MouseSelectRestLength,
                                                               m_MouseSelectSpringConstant, m_MouseSelectDampingConstant);
                    m_ParticleSystem.AddForce(m_CurrentMouseForce);
                    m_HasMouseSelection = true;
                }
            }
            else if (m_HasMouseSelection && Input.GetMouseButtonDown(1))
            {
                m_ParticleSystem.RemoveForce(m_CurrentMouseForce);
                m_CurrentMouseForce = null;
                m_HasMouseSelection = false;
            }
            else if (m_HasMouseSelection)
            {
                m_CurrentMouseForce.UpdateMousePosition(mousePos);
            }
        }
    }
    public void CreateScenario(ParticleSystem a_ParticleSystem)
    {
        const float particleMass = 1f;

        Particle p1 = new Particle(particleMass);

        p1.Position = new Vector2(-3f, 3.5f);
        a_ParticleSystem.AddParticle(p1);
        new CircularWireConstraint(p1, new Vector2(-2f, 3.5f), a_ParticleSystem);

        Particle p3 = new Particle(particleMass);

        p3.Position = p1.Position + new Vector2(0.5f, 0f);
        a_ParticleSystem.AddParticle(p3);
        new RodConstraint(p1, p3, a_ParticleSystem);

        Particle p2 = new Particle(particleMass);

        p2.Position = new Vector2(2f, 3.5f);
        a_ParticleSystem.AddParticle(p2);
        new CircularWireConstraint(p2, new Vector2(3f, 3.5f), a_ParticleSystem);

        Particle p4 = new Particle(particleMass);

        p4.Position = p2.Position + new Vector2(0.5f, 0f);
        a_ParticleSystem.AddParticle(p4);
        new RodConstraint(p2, p4, a_ParticleSystem);

        new RodConstraint(p3, p4, a_ParticleSystem);

        // With springs
        const float springConstant  = 75f;
        const float dampingConstant = 40f;

        Particle p5 = new Particle(particleMass);

        p5.Position = new Vector2(-3f, 1);
        a_ParticleSystem.AddParticle(p5);
        new CircularWireConstraint(p5, new Vector2(-2f, 1), a_ParticleSystem);

        Particle p6 = new Particle(particleMass);

        p6.Position = p5.Position + new Vector2(0.5f, 1f);
        a_ParticleSystem.AddParticle(p6);
        HooksLawSpring s1 = new HooksLawSpring(p5, p6, 0.5f, springConstant, dampingConstant);

        a_ParticleSystem.AddForce(s1);

        Particle p7 = new Particle(particleMass);

        p7.Position = new Vector2(2f, 1);
        a_ParticleSystem.AddParticle(p7);
        new CircularWireConstraint(p7, new Vector2(3f, 1), a_ParticleSystem);

        Particle p8 = new Particle(particleMass);

        p8.Position = p7.Position + new Vector2(0.5f, 1f);
        a_ParticleSystem.AddParticle(p8);
        HooksLawSpring s2 = new HooksLawSpring(p7, p8, 0.5f, springConstant, dampingConstant);

        a_ParticleSystem.AddForce(s2);

        new RodConstraint(p6, p8, a_ParticleSystem);



        Particle q1 = new Particle(particleMass);

        q1.Position = new Vector2(-3f, -1.5f);
        a_ParticleSystem.AddParticle(q1);
        new CircularWireConstraint(q1, new Vector2(-2f, -1.5f), a_ParticleSystem);


        Particle q2 = new Particle(particleMass);

        q2.Position = new Vector2(2f, -1.5f);
        a_ParticleSystem.AddParticle(q2);
        new CircularWireConstraint(q2, new Vector2(3f, -1.5f), a_ParticleSystem);
        new RodConstraint(q1, q2, a_ParticleSystem);


        Particle a1 = new Particle(1);
        Particle a2 = new Particle(1);
        Particle a3 = new Particle(1);
        Particle a4 = new Particle(1);

        a1.Position = new Vector2(-4, -3);
        a2.Position = new Vector2(0, -3);
        a3.Position = new Vector2(0, -5);
        a4.Position = new Vector2(4, -5);
        a_ParticleSystem.AddParticle(a1);
        a_ParticleSystem.AddParticle(a2);
        a_ParticleSystem.AddParticle(a3);
        a_ParticleSystem.AddParticle(a4);
        new CircularWireConstraint(a1, a1.Position + Vector2.down, a_ParticleSystem);
        new CircularWireConstraint(a2, a2.Position + Vector2.down, a_ParticleSystem);
        new CircularWireConstraint(a3, a3.Position + Vector2.up, a_ParticleSystem);
        new CircularWireConstraint(a4, a4.Position + Vector2.up, a_ParticleSystem);
        new RodConstraint(a1, a2, a_ParticleSystem);
        new RodConstraint(a2, a3, a_ParticleSystem);
        new RodConstraint(a3, a4, a_ParticleSystem);
    }
    public void CreateScenario(ParticleSystem a_ParticleSystem)
    {
        //Note; Without cross fibers appears to function better
        const int dim         = 14;
        Vector2   bottomLeft  = new Vector2(-5f, -5f);
        Vector2   topLeft     = new Vector2(-5f, 5f);
        Vector2   bottomRight = new Vector2(5f, -5f);
        Vector2   offsetX     = (bottomRight - bottomLeft) / dim;
        Vector2   offsetY     = (topLeft - bottomLeft) / dim;
        float     dist        = offsetX.x;

        for (int i = 0; i <= dim; i++)
        {
            for (int j = 0; j <= dim; j++)
            {
                Particle p = new Particle(1f);
                p.Position = bottomLeft + offsetX * i + offsetY * j;
                a_ParticleSystem.AddParticle(p);
            }
        }
        const float ks   = 10f;
        const float kd   = 1f;
        float       rest = dist / 1.05f;

        for (int i = 0; i < dim; i++)
        {
            for (int j = 0; j < dim; j++)
            {
                int cur   = j * (dim + 1) + i;
                int right = cur + dim + 1;
                int below = cur + 1;
                a_ParticleSystem.AddForce(new HooksLawSpring(a_ParticleSystem.Particles[cur], a_ParticleSystem.Particles[right], rest, ks, kd));
                a_ParticleSystem.AddForce(new HooksLawSpring(a_ParticleSystem.Particles[cur], a_ParticleSystem.Particles[below], rest, ks, kd));
            }
        }
        for (int i = 0; i < dim; i++)
        {
            int cur1  = (i + 1) * (dim + 1) - 1;
            int right = cur1 + dim + 1;
            a_ParticleSystem.AddForce(new HooksLawSpring(a_ParticleSystem.Particles[cur1], a_ParticleSystem.Particles[right], rest, ks, kd));

            int cur2  = i + dim * (dim + 1);
            int below = cur2 + 1;
            a_ParticleSystem.AddForce(new HooksLawSpring(a_ParticleSystem.Particles[cur2], a_ParticleSystem.Particles[below], rest, ks, kd));
        }
        if (m_WithCrossFibers)
        {
            float drest = rest * Mathf.Sqrt(2f);
            for (int i = 0; i < dim; i++)
            {
                for (int j = 0; j < dim; j++)
                {
                    int cur        = j * (dim + 1) + i;
                    int rightbelow = cur + dim + 2;
                    a_ParticleSystem.AddForce(new HooksLawSpring(a_ParticleSystem.Particles[cur], a_ParticleSystem.Particles[rightbelow], drest, ks, kd));
                }
            }
            for (int i = 1; i <= dim; i++)
            {
                for (int j = 0; j < dim; j++)
                {
                    int cur        = j * (dim + 1) + i;
                    int rightabove = cur + dim;
                    a_ParticleSystem.AddForce(new HooksLawSpring(a_ParticleSystem.Particles[cur], a_ParticleSystem.Particles[rightabove], drest, ks, kd));
                }
            }
        }
        a_ParticleSystem.AddForce(new GravityForce(Mathf.Pow(10, -2.5f)));
        for (int i = 0; i <= dim; i++)
        {
            new HLineConstraint(a_ParticleSystem.Particles[i * (dim + 1) + dim], a_ParticleSystem);
        }
    }
    public void CreateScenario(ParticleSystem a_ParticleSystem)
    {
        Particle particle1 = new Particle(1000f);

        particle1.Position = new Vector2(-2f, 0f);
        a_ParticleSystem.AddParticle(particle1);
        Particle particle2 = new Particle(1f);

        particle2.Position = new Vector2(0f, 5f);
        a_ParticleSystem.AddParticle(particle2);
        Particle particle3 = new Particle(1f);

        particle3.Position = new Vector2(4f, 4f);
        a_ParticleSystem.AddParticle(particle3);

        Force angleforce = new AngularSpringForce(particle2, particle1, particle3, Mathf.PI / 2, 1f, 0.1f);

        a_ParticleSystem.AddForce(angleforce);
        Force spring1 = new HooksLawSpring(particle1, particle2, 2, 1, .1f);
        Force spring2 = new HooksLawSpring(particle3, particle2, 2, 1, .1f);

        a_ParticleSystem.AddForce(spring1);
        a_ParticleSystem.AddForce(spring2);
        Force gravityForce = new GravityForce(.001f);

        a_ParticleSystem.AddForce(gravityForce);

        Particle p6 = new Particle(.5f);

        p6.Position = new Vector2(0, -4);
        a_ParticleSystem.AddParticle(p6);
        Particle p7 = new Particle(1);

        p7.Position = new Vector2(0, -5f);
        a_ParticleSystem.AddParticle(p7);
        new RodConstraint(p6, p7, a_ParticleSystem);


        Particle p5 = new Particle(500f);

        p5.Position = new Vector2(2, 2);
        a_ParticleSystem.AddParticle(p5);
        new CircularWireConstraint(p5, p5.Position + Vector2.right, a_ParticleSystem);

        Particle p8 = new Particle(0.5f);

        p8.Position = new Vector2(-3, -1);
        a_ParticleSystem.AddParticle(p8);
        new FixedPointConstraint(p8, a_ParticleSystem);


        Particle p9 = new Particle(.5f);

        p9.Position = new Vector2(-3, -2);
        a_ParticleSystem.AddParticle(p9);
        new HLineConstraint(p9, a_ParticleSystem);

        Particle p10 = new Particle(.5f);

        p10.Position = new Vector2(5, -2);
        a_ParticleSystem.AddParticle(p10);
        new VLineConstraint(p10, a_ParticleSystem);


        Particle q1 = new Particle(.5f);

        q1.Position = new Vector2(-3, 3);
        a_ParticleSystem.AddParticle(q1);
        new EllipticalWireConstraint(q1, q1.Position + new Vector2(1f, -.3f), q1.Position + new Vector2(-1f, -1f), a_ParticleSystem);

        Force dragForce = new ViscousDragForce(.2f);

        a_ParticleSystem.AddForce(dragForce);
    }