Example #1
0
 static List <int> GetPatternVertices(STPattern pattern)
 {
     return(pattern.GetVertices());
 }
    public List <Vector3> GetGenPositions(STPattern pattern, Vector3 nodePosition, int prevPatternPos, List <int> paternVects, int branchLength)
    {
        foreach (STNetNode netNode in elementNetNodesArray)
        {
            netNode.transform.position += nodePosition - prevElementPostion;
        }

        prevElementPostion.x = nodePosition.x;
        prevElementPostion.y = nodePosition.y;
        prevElementPostion.z = nodePosition.z;

        Vector3 genPos = new Vector3();


        List <Vector3> genPoints = new List <Vector3> ();

        //Debug.Log ("GEN");


        if (STPatternManager.GetMode() == GenMode.patternMode)
        {
            List <int> verts = pattern.GetVertices();
            if (verts != null)
            {
                foreach (int vert in verts)
                {
                    int circleN           = (vert - 1) / 8;
                    int prevPatternCircle = (prevPatternPos - 1) % 8;
                    int posInCircle       = ((vert - 1) % 8 + prevPatternCircle) % 8;

                    genPos = elementNetNodesArray [circleN * 8 + posInCircle + 1].transform.position;
                    genPoints.Add(genPos);
                    paternVects.Add(circleN * 8 + posInCircle + 1);
                }
            }
        }
        else
        {
            int randN;
            int nBranches = (int)(Random.value * (pattern.maxBranches - pattern.minBranches)) + pattern.minBranches;
            //	int nBranches = 1;
            int genCount      = 0;
            int totalGenCount = 0;

            do
            {
                bool goodVect = false;
                //int index;


                do
                {
                    int minLength = pattern.minLength;
                    int maxLength = pattern.maxLength;

                    //		Debug.Log ("MIN" + minLength);
                    //		Debug.Log ("MAX" + maxLength);


                    //	randN = (int) (Random.value * 23) + 1;
                    randN = (int)((minLength - 1) * 8 + Mathf.Round(Random.value * (maxLength - minLength + 1) * 8.0f));

                    if (randN == 0)
                    {
                        continue;
                    }

                    //Debug.Log (randN);

                    //	int circleN = (randN - 1) / 8;
                    //	int prevPatternCircle = (prevPatternPos - 1) % 8;
                    //	int posInCircle = ((randN - 1) % 8 + prevPatternCircle) % 8;

                    //	index = circleN * 8 + posInCircle + 1;
                    genPos = elementNetNodesArray [randN].transform.position;


                    bool checkGenPos = true;



                    SymetryMode mode = STPatternManager.GetSymetryMode();

                    if (mode == SymetryMode.symetry_4)
                    {
                        if ((genPos.x <= STNode.nodeSize) || (genPos.y <= STNode.nodeSize))
                        {
                            checkGenPos = false;
                        }
                    }
                    else if ((mode == SymetryMode.symetry_2) || (mode == SymetryMode.symetry_2fliped))
                    {
                        if (genPos.y <= STNode.nodeSize)
                        {
                            checkGenPos = false;

                            //	Debug.Log ("GEN POS ERR");
//							Debug.Log (genPos);
                        }
                    }


                    if ((Mathf.Abs(genPos.y + STNode.nodeSize) > Camera.main.orthographicSize) || (Mathf.Abs(genPos.x + STNode.nodeSize) > Camera.main.orthographicSize))
                    {
                        checkGenPos = false;
//						Debug.Log ("OUT OF SCREEN");
                    }

//					if (branchLength + ( randN - 1) / 8 + 1 > 6)
//					{
//						checkGenPos = false;
//						goodVect = false;
//					}


                    if (((prevPatternPos == 0) || (Mathf.Abs(randN - prevPatternPos) % 8 != 4)) && (checkGenPos))
                    {
                        goodVect = true;
                        foreach (int pos in paternVects)
                        {
                            if ((randN % 8) == (pos % 8))
                            {
                                goodVect = false;
                                //	Debug.Log ("PREV GEN POS ERR");
                            }
                        }
                    }
                    else
                    {
                        //Debug.Log ("BACK GEN ERR");
                    }


                    genCount++;
                    if (genCount > 30)
                    {
                        //					Debug.Log ("FAIL 1" + genCount);
                        break;
                    }
                } while (goodVect == false);



                //	if (goodVect == true)
                if (STLevel.GetRootNode().CheckForIntersection(genPos.x, genPos.y, nodePosition.x, nodePosition.y, 0, 0) == true)
                {
                    goodVect = false;
                }

                totalGenCount += genCount;
                genCount       = 0;
                if (totalGenCount > 300)
                {
//					Debug.Log ("FAIL 2" + totalGenCount);
                    goodVect = false;
                }
                else
                if (goodVect == false)
                {
                    continue;
                }

                //Debug.Log ("PREV - " + prevPatternPos);
                //	Debug.Log (randN);
                //	Debug.Log (genPos);

                if (goodVect == true)
                {
                    genPoints.Add(genPos);
                    paternVects.Add(randN);
                }
                //else
                //Debug.Log ("FAIL");


                totalGenCount = 0;
                nBranches--;
            }while (nBranches > 0);

            //paternVects = verts;
        }

        return(genPoints);
    }