예제 #1
0
    public void addForce(float x, float y, float dx, float dy, colorP5 drawColor, int particleNum, float colorMult, float randomRange)
    {
        float speed = dx * dx + dy * dy * aspectRatio2;            // balance the x and y components of speed with the screen aspect ratio

        if (speed > 0)
        {
            if (x < 0)
            {
                x = 0;
            }
            else if (x > 1)
            {
                x = 1;
            }
            if (y < 0)
            {
                y = 0;
            }
            else if (y > 1)
            {
                y = 1;
            }

            //float colorMult = 5;
            float velocityMult = 30.0f;

            int index = fluidSolver.getIndexForNormalizedPosition(x, y);

            if (particleNum > 0)
            {
                fluidSolver.rOld [index] += red(drawColor) * colorMult;
                fluidSolver.gOld [index] += green(drawColor) * colorMult;
                fluidSolver.bOld [index] += blue(drawColor) * colorMult;

                p5particleSystem.addParticles(x * width, y * height, particleNum, drawColor.m_color, randomRange);
            }

            fluidSolver.uOld [index] += dx * velocityMult;
            fluidSolver.vOld [index] += dy * velocityMult;
        }
    }
예제 #2
0
    //public float angle = 0.0f;
    //public Vector3 renderV;

    public void update()
    {
        updateAppearAnime();
        alpha = t_alpha * _alpha_per;

        // only update if particle is visible
        if (alpha == 0)
        {
            return;
        }

        // spark
        if (isSpark)
        {
            //alpha *= (Mathf.Sin(randomV + Time.realtimeSinceStartup * (20.0f * 1.0f/mass)) + 1.0f) / 2.0f + 0.4f;
            //alpha *= (Mathf.Sin((randomV + Time.realtimeSinceStartup) * 20.0f * (mass * mass)) + 1.0f) / 2.0f + 0.4f;
            alpha *= (Mathf.Sin((randomV + Time.realtimeSinceStartup) * 10.0f * 1.0f / (mass * mass)) + 1.0f) / 2.0f + 0.4f;
        }

        if (fluidSolver == null)
        {
            return;
        }
        // read fluid info and add to velocity
        int fluidIndex = fluidSolver.getIndexForNormalizedPosition(x * MSAFluid.invWidth, y * MSAFluid.invHeight);

        /*
         * vx = fluidSolver.u[fluidIndex] * height * mass * FLUID_FORCE + vx * MOMENTUM;
         * vy = fluidSolver.v[fluidIndex] * height * mass * FLUID_FORCE + vy * MOMENTUM;
         */
        float t_vx = fluidSolver.u [fluidIndex] * height * mass * FLUID_FORCE + vx * MOMENTUM;
        float t_vy = fluidSolver.v [fluidIndex] * height * mass * FLUID_FORCE + vy * MOMENTUM;

        //vx += (t_vx - vx)*V_SMOOTH;
        //vy += (t_vy - vy)*V_SMOOTH;

        vx = t_vx;
        vy = t_vy;

        vMagnitude = (new Vector3(vx, vy, 0)).magnitude;

        /*
         * Vector3 v = new Vector3(vx, vy, 0);
         * float tt_angle = Vector3.Angle(new Vector3(1,0,0), v);
         * angle += (tt_angle - angle)*0.025f;
         * renderV = new Vector3(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad), 0)*vMagnitude;
         */

        //if(Mathf.Abs(vx) < 0.075f && Mathf.Abs(vy) < 0.075f){
        if (vMagnitude < P5ParticleSystemRenderer.MIN_MAGNITUDE)
        {
            /*
             * // この処理は無くしたほうがいい?
             * // TODO: あったほうがいいけれど、タイトルのとき消えてしまうので処理を再考する
             * if(!isAppearAnime){
             * _alpha_per *= alphaDelta;
             * if(_alpha_per < 0.05f) _alpha_per = 0;
             * }
             */
            //vx = 0;
            //vy = 0;
            return;
        }

        /*
         * vx += ((fluidSolver.u[fluidIndex] * height * mass * FLUID_FORCE + vx * MOMENTUM) - vx) * 0.1f;
         * vy += ((fluidSolver.v[fluidIndex] * height * mass * FLUID_FORCE + vy * MOMENTUM) - vy) * 0.1f;
         */
        // update position
        x += vx;
        y += vy;

        /*
         * // bounce of edges
         * if(x<0-boundaryOffset) {
         * x = 0-boundaryOffset;
         * vx *= -1;
         * }
         * else if(x > width+boundaryOffset) {
         * x = width+boundaryOffset;
         * vx *= -1;
         * }
         *
         * if(y<0-boundaryOffset) {
         * y = 0-boundaryOffset;
         * vy *= -1;
         * }
         * else if(y > height+boundaryOffset) {
         * y = height+boundaryOffset;
         * vy *= -1;
         * }
         */

        /*
         * // hackish way to make particles glitter when the slow down a lot
         * if(vx * vx + vy * vy < 0.001f) {
         *  vx = Random.Range(-1, 1) * 0.0025f;
         *  vy = Random.Range(-1, 1) * 0.0025f;
         * }
         */


        // fade out a bit (and kill if alpha == 0);
        if (!isStay)
        {
            if (x < 0 - boundaryOffset)
            {
                //x = width+boundaryOffset;
                //vx *= 0.5f;

                _alpha_per = 0;
            }
            else if (x > width + boundaryOffset)
            {
                //x = 0-boundaryOffset;
                //vx *= 0.5f;

                _alpha_per = 0;
            }

            if (y < 0 - boundaryOffset)
            {
                //y = height+boundaryOffset;
                //vy *= 0.5f;

                _alpha_per = 0;
            }
            else if (y > height + boundaryOffset)
            {
                //y = 0-boundaryOffset;
                //vy *= 0.5f;

                _alpha_per = 0;
            }

            if (!isAppearAnime)
            {
                _alpha_per *= alphaDelta;
                if (_alpha_per < 0.05f)
                {
                    _alpha_per = 0;
                }
            }
        }
        else
        {
            // stay
            if (x < 0 - boundaryOffset || x > width + boundaryOffset)
            {
                reset();
            }
            if (y < 0 - boundaryOffset || y > height + boundaryOffset)
            {
                reset();
            }

            if (!isAppearAnime)
            {
                _alpha_per *= 0.99f + 0.009f * randomValue;
                if (_alpha_per < 0.05f)
                {
                    reset();
                }
            }
        }
    }