예제 #1
0
    public List <Vector3> GetGenPositions(STPattern pattern, Vector3 nodePosition, int prevPatternPos, List <int> paternVects, int branchLength)
    {
        //return iNet.GetGenPoint();


        return(iNet.GetGenPositions(pattern, nodePosition, prevPatternPos, paternVects, branchLength));
    }
예제 #2
0
 void setRandomPatterns()
 {
     for (int i = 0; i < 6; i++)
     {
         STPattern pattern = new STPattern();
         randomPaterns.Add(pattern);
     }
 }
예제 #3
0
    void setSecondLevelPatterns()
    {
        STPattern p = new STPattern();


        p.AddVertics(10);
        p.AddVertics(16);

        secondLevelPatterns.Add(p);
    }
예제 #4
0
    void setThirdLevelPatterns()
    {
        STPattern p = new STPattern();

        p.AddVertics(1);
        p.AddVertics(2);
        p.AddVertics(8);

        thirdLevelPatterns.Add(p);
    }
예제 #5
0
    void setFirstLevelPatterns()
    {
        STPattern p = new STPattern();

        p.AddVertics(10);
        p.AddVertics(12);
        p.AddVertics(14);
        p.AddVertics(16);

        firstLevelPatterns.Add(p);
    }
예제 #6
0
    public void GenNextNode(int N, int depth, int prevPattern, int curBranchLength)
    {
        if (N == 0)
        {
            return;
        }

        STPattern      pattern       = STPatternManager.GetPattern(depth);
        List <int>     paternVects   = new List <int>();
        List <Vector3> vectPositions = STLevel.GetNodesNet().GetGenPositions(pattern, transform.position, prevPattern, paternVects, curBranchLength);
        int            i             = 0;

        if (vectPositions != null)
        {
            foreach (Vector3 nodePos in vectPositions)
            {
                STRootNode root     = STLevel.GetRootNode();
                STNode     nodePref = Instantiate(root.NodePref) as STNode;
                if (nodePref != null)
                {
                    nodePref.brenchLength = this.brenchLength + (((paternVects[i] - 1) / 8) + 1);

                    nodePref.transform.parent = mRotor.transform;
                    nodePref.mParent          = this;

                    nodePref.nodeDepth = depth;
                    mRotor.mChilds.Add(nodePref);
                    nodePref.transform.position = new Vector3(nodePos.x, nodePos.y, -depth);

                    STLevel.GetRootNode().SetTreeDepth(depth);
                }

                i++;
            }
        }

        i = 0;

        foreach (STNode node in mRotor.mChilds)
        {
            node.GenNextNode(N - 1, depth + 1, paternVects[i], node.brenchLength);
            i++;
        }
    }
예제 #7
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);
    }
예제 #9
0
 public List <Vector3> GetGenPositions(STPattern pattern, Vector3 nodePosition, int prevPatternPos, List <int> paternVects, int branchLength)
 {
     return(null);
 }