Example #1
0
    void Start()
    {
        InitFields();
        InitVisualizerField();
        InitChunkFields();

        spiritParticles = new SpiritParticle[150];
        for (int i = 0; i < 150; ++i)
        {
            spiritParticles[i] = new SpiritParticle(UnityEngine.Random.Range(3.0f, 30.0f));
        }
    }
Example #2
0
    void Start()
    {
        InitFields();
        InitVisualizerField();
        InitChunkFields();

        spiritParticles = new SpiritParticle[150];
        for(int i = 0; i < 150; ++i)
        {
            spiritParticles[i] = new SpiritParticle(UnityEngine.Random.Range(3.0f, 30.0f));
        }
    }
Example #3
0
    public void UpdateSpritParticles()
    {
        if (spiritParticleSystem == null)
        {
            return;
        }

        int pcount = maxSpiritParticles;        //spiritParticleSystem.particleCount;

        UnityEngine.ParticleSystem.Particle[] particles = new UnityEngine.ParticleSystem.Particle[pcount];
        //spiritParticleSystem.GetParticles(particles);

        Vector3 centerOfScreen = camcam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));
        float   minLineDist    = 75.0f;

        int pIdx = 1;
        int numConnectedParticles = 0;

        float dt = Time.deltaTime;

        for (int i = 0; i < pcount; ++i)
        {
            SpiritParticle sp        = spiritParticles[i];
            Vector3        ppos      = sp.position;
            Vector3        screenPos = camcam.WorldToViewportPoint(ppos);
            int            xCell     = (int)(screenPos.x * N);
            int            yCell     = (int)(screenPos.y * N);

            sp.initTime -= dt;
            if (sp.initTime > 0.0f)
            {
                sp.mass = 1.0f - sp.initTime;
            }
            else
            {
                sp.velocity *= 1.0f - (0.5f * dt);

                if (xCell >= 1 && xCell < N - 1 && yCell >= 1 && yCell < N - 1)
                {
                    ppos.x += u[xCell, yCell] * SpirtParticlesEffectedByGridVelocity;
                    ppos.y += v[xCell, yCell] * SpirtParticlesEffectedByGridVelocity;
                    //this.densityField[xCell,yCell] += 0.01f;
                }
                else                 //bring em back towards the center of the screen
                {
                    Vector3 sub = centerOfScreen - ppos;
                    float   len = sub.magnitude;
                    sub.Normalize();
                    sub           *= ((SpiritGravity * (sp.mass * 100) / len));
                    sp.velocity.x += sub.x;
                    sp.velocity.y += sub.y;
                }

                //gravy towards player-finger-downs
                for (int m = 0; m < 2; ++m)
                {
                    if (ownerPlayerMouseInfo[m].player == null)
                    {
                        continue;
                    }
                    if (ownerPlayerMouseInfo[m].playerScript.MouseFingerDown() != PlayerScript.FingerState.None)
                    {
                        Vector3 sub = ownerPlayerMouseInfo[m].player.transform.position - ppos;
                        float   len = sub.magnitude;
                        sub.Normalize();
                        sub           *= ((SpiritToPlayerAttraction * (sp.mass * 400) / len));
                        sp.velocity.x += sub.x;
                        sp.velocity.y += sub.y;
                    }
                }


                //Do N-Body gravitations!
                for (int j = pIdx; j < pcount; ++j)
                {
                    SpiritParticle sp2   = spiritParticles[j];
                    Vector3        ppos2 = sp2.position;
                    Vector3        sub   = ppos2 - ppos;
                    float          len   = sub.magnitude;

                    if (len < minLineDist)
                    {
                        //Add a line between all these guys!
                        float alpha = 1 - (len / minLineDist);
                        Color col   = new Color(1.0f, 1.0f, 1.0f, alpha);
                        linesToDraw.Add(new LineToDraw(ppos, ppos2, col, col));
                        ++numConnectedParticles;
                    }

                    sub.Normalize();
                    sub *= ((SpiritGravity * (sp.mass * sp2.mass) / len)) * 0.25f;

                    if (len < SpritParticleSeperationDistance)
                    {
                        sp.velocity.x -= sub.x;
                        sp.velocity.y -= sub.y;
                    }
                    else
                    {
                        sp.velocity.x += sub.x;
                        sp.velocity.y += sub.y;
                    }
                }
            }

            ++pIdx;

            ppos.x += sp.velocity.x * dt;
            ppos.y += sp.velocity.y * dt;

            sp.position = ppos;
            particles[i].startLifetime = 2.5f;
            particles[i].lifetime      = 5.0f;
            particles[i].position      = ppos;
            particles[i].size          = sp.mass * 20;
            particles[i].color         = new Color32(248, 168, 255, 255);
        }

        //DebugStreamer.message = "maxSpiritParticles: " + maxSpiritParticles.ToString();
        spiritParticlesAllConnected = numConnectedParticles == maxSpiritParticles;
        spiritParticleSystem.SetParticles(particles, maxSpiritParticles);
    }