Exemplo n.º 1
0
    void AddForce()
    {
        string[] smBodyName = new string[] { "Penguin", "rubberduck", "Soccerball", "plane_lower" };
        foreach (string strName in smBodyName)
        {
            GameObject goBody = GameObject.Find(strName);
            if (null == goBody)
            {
                continue;
            }

            SmBody sb = goBody.GetComponent <SmBody>();
            if (null == sb)
            {
                continue;
            }

            float velocityMax  = 25.0f;
            float velocityHalf = velocityMax / 2.0f;

            Vector3 randomVelocity = new Vector3(0,
                                                 Random.Range(0.5f, 1.0f) * velocityMax - velocityHalf,
                                                 0);

            for (int i = 0; i != sb.mDeformableModel.mParticles.Count; ++i)
            {
                SmParticle particle = sb.mDeformableModel.mParticles[i];
                //particle.mX.y += 5.0f;
                particle.mV += (randomVelocity);
            }
        }
    }
Exemplo n.º 2
0
    void AddForce2()
    {
        string[] smBodyName = new string[] { "Penguin", "rubberduck", "Soccerball", "plane_lower" };
        foreach (string strName in smBodyName)
        {
            GameObject goBody = GameObject.Find(strName);
            if (null == goBody)
            {
                continue;
            }

            SmBody sb = goBody.GetComponent <SmBody>();
            if (null == sb)
            {
                continue;
            }

            float velocityMax  = 500.0f;
            float velocityHalf = velocityMax / 2.0f;

            /*
             * Vector3 randomVelocity = new Vector3(0,
             * Random.Range(0.5f, 1.0f) * velocityMax - velocityHalf,
             * 0);
             */

            Vector3 randomVelocity = new Vector3(Random.Range(0.5f, 1.0f) * velocityMax - velocityHalf,
                                                 Random.Range(0.5f, 1.0f) * velocityMax - velocityHalf,
                                                 Random.Range(0.5f, 1.0f) * velocityMax - velocityHalf);

            /*
             * for (int i = 0; i != sb.mDeformableModel.mParticles.Count; ++i)
             * {
             * SmParticle particle = sb.mDeformableModel.mParticles[i];
             * //particle.mX.y += 5.0f;
             * particle.mV += (randomVelocity);
             * }
             */
            while (true)
            {
                int             index = Random.Range(0, sb.mDeformableModel.mLatticeLocations.Count);
                LatticeLocation ll    = sb.mDeformableModel.mLatticeLocations[index];
                if (ll.IsEdge)
                {
                    for (int i = 0; i != ll.mParticles.Length; ++i)
                    {
                        SmParticle particle = ll.mParticles[i];
                        particle.mF = randomVelocity;
                    }
                    break;
                }
            }
        }
    }
Exemplo n.º 3
0
    void AddBody()
    {
        GameObject goPenguin = GameObject.Find("Penguin");

        if (null == goPenguin)
        {
            return;
        }

        SmBody smBody = goPenguin.GetComponent <SmBody>();

        if (null == smBody)
        {
            return;
        }


        DeformableModel body = new DeformableModel(new Vector3(smBody.Spacing, smBody.Spacing, smBody.Spacing));

        //body.W = 1;
        //body.Alpha = Random.Range(0.1f, 1.0f);
        //body.RegionDamping = Random.Range(0.1f, 1.0f);

        body.W             = 1;
        body.Alpha         = 0.75f;
        body.RegionDamping = 0.25f;

        mBodies.Add(body);


        //int width   = Random.Range(0, 3) + 2;
        //int height  = Random.Range(0, 20) + 2;
        //int depth     = Random.Range(0, 3) + 2;

        int width  = smBody.mCellInfos.GetLength(0);
        int height = smBody.mCellInfos.GetLength(1);
        int depth  = smBody.mCellInfos.GetLength(2);

        for (int x = 0; x != width; ++x)
        {
            for (int y = 0; y != height; ++y)
            {
                for (int z = 0; z != depth; ++z)
                {
                    SmBody.SmCellInfo info = smBody.mCellInfos[x, y, z];
                    if (info.mValid)
                    {
                        //body.AddParticle(new Point3(x, y, z));
                        body.AddCell(new Point3(x, y, z));
                    }
                }
            }
        }

        body.Complete();

        float velocityMax  = 25.0f;
        float velocityHalf = velocityMax / 2.0f;


        Vector3 randomVelocity = new Vector3(Random.Range(0.0f, 1.0f) * velocityMax - velocityHalf,
                                             Random.Range(0.5f, 1.0f) * velocityMax - velocityHalf,
                                             Random.Range(0.0f, 1.0f) * velocityMax - velocityHalf);



        //Vector3 randomVelocity = new Vector3(0.5f * velocityMax - velocityHalf,
        //    0.5f * velocityMax - velocityHalf,
        //    0.5f * velocityMax - velocityHalf);

        //Vector3 randomVelocity = new Vector3(9.0f, 2.8f, -6.8f);

        for (int i = 0; i != body.mParticles.Count; ++i)
        {
            SmParticle particle = body.mParticles[i];
            particle.mX.y += 5.0f;
            particle.mV   += (randomVelocity);
        }

        Debug.LogWarning("W[" + body.W.ToString() + "], Width[" + width.ToString() + "], Height[" + height.ToString() + "], Depth[" + depth.ToString() + "], Velocity[" + randomVelocity.ToString() + "]");
    }