Ejemplo n.º 1
0
        private void SubDivideSpline(GameObject theGameObject, CCBezierSpline theSpline, int theDepth)
        {
            int mySubdivs = random.Random(1, subDivisions);

            for (int j = 0; j < mySubdivs; j++)
            {
                CCBezierSpline myBase = theSpline.Clone();
                myBase.BeginEditSpline();
                Vector3 lastPoint = myBase.LastPoint();
                for (int c = 0; c < addPoints; c++)
                {
                    float lastY = lastPoint.y;
                    lastPoint.x += random.Random(-xRange, xRange);
                    lastPoint.z += random.Random(-xRange, xRange);
                    lastPoint.y += random.Random(yStart, yStart + yRange);
                    // myBase.AddPoint(lastPoint, curveTensionA, curveTensionB);
                    myBase.AddControlPoints(new Vector3(lastPoint.x, Mathf.Lerp(lastPoint.y, lastY, curveTensionA), lastPoint.z), lastPoint);
                }
                myBase.EndEditSpline();
                if (theDepth > 0)
                {
                    SubDivideSpline(theGameObject, myBase, theDepth - 1);
                }
                _myPaths.Add(new TreeSpline(theGameObject, myBase));
            }
        }
Ejemplo n.º 2
0
        private CCBezierSpline BuildSpline(Transform theTransform)
        {
            CCBezierSpline mySpline = new CCBezierSpline();

            mySpline.BeginEditSpline();
            mySpline.AddPoint(theTransform.position);

            Transform myLastTransform = theTransform;

            while (myLastTransform.transform.parent != null)
            {
                Vector3 a = myLastTransform.position;
                Vector3 b = myLastTransform.transform.parent.position;

                mySpline.AddControlPoints(
                    new Vector3(a.x, (a.y + b.y) / 2, a.z),
                    new Vector3(b.x, (a.y + b.y) / 2, b.z),
                    b
                    );
                myLastTransform = myLastTransform.transform.parent;
            }
            mySpline.EndEditSpline();
            mySpline.Invert();
            return(mySpline);
        }