Demo entry 6364081

a

   

Submitted by anonymous on May 15, 2017 at 12:59
Language: C#. Code size: 998 Bytes.

List preCloud = new List ();   //初始化存储已生成的单位云位置的列表
for (int i = 0; i < cloudNum; ++i)
{
        CloudChild = new Cloud();
 
        CloudChild.EulerAngles = Random.EulerAngles;
        bool tooNearFlag;
        float allDis = 0;    //用于计算新位置与已生成的位置距离之和
        Vector3 aroundPos;
        do
        {
            allDis = 0;
            tooNearFlag = false;
            aroundPos = position + Random.Position;
            foreach (Vector3 p in preCloud)
            {
                float dis = Vector3.Distance(p, aroundPos);
                if (dis < tooNearDis)
                {
                    tooNearFlag = true;
                    break;
                }
                allDis += dis;
            }
            if (tooNearFlag == false && allDis <= upperBound*preCloud.Count && allDis >= lowerBound *preCloud.Count)
            break;
        } while (true);
        CloudChild.Position = aroundPos;
        preCloud.Add(aroundPos);
}
return preCloud;

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).