예제 #1
0
        public override void Apply(Path p)
        {
            //Good Game
            Vector3[] vectorPath = IntMath.Int3s2Vector3s(p.vectorPath).ToArray();
            //VInt3[] vectorPath = p.vectorPath.ToArray();

            if (vectorPath == null || vectorPath.Length <= 2)
            {
                return;
            }

            //Good Game
            List <Vector3> newPath = new List <Vector3>();

            //List<VInt3> newPath = new List<VInt3>();
            newPath.Add(vectorPath[0]);

            TurnConstructor.turningRadius = turningRadius;

            for (int i = 1; i < vectorPath.Length - 1; i++)
            {
                List <Turn> turnList = new List <Turn>();

                TurnConstructor.Setup(i, vectorPath);
                turnConstruct1.Prepare(i, vectorPath);
                turnConstruct2.Prepare(i, vectorPath);

                TurnConstructor.PostPrepare();

                if (i == 1)
                {
                    turnConstruct1.PointToTangent(turnList);
                    turnConstruct2.PointToTangent(turnList);
                }
                else
                {
                    turnConstruct1.TangentToTangent(turnList);
                    turnConstruct2.TangentToTangent(turnList);
                }

                EvaluatePaths(turnList, newPath);

                //Last point
                if (i == vectorPath.Length - 2)
                {
                    turnConstruct1.TangentToPoint(turnList);
                    turnConstruct2.TangentToPoint(turnList);
                }

                EvaluatePaths(turnList, newPath);
            }

            newPath.Add(vectorPath[vectorPath.Length - 1]);
            //Good Game
            //p.vectorPath = newPath;
            p.vectorPath = IntMath.Vector3s2Int3s(newPath);
        }
예제 #2
0
 public override void Apply(Path p)
 {
     Vector3[] vectorPath = p.vectorPath.ToArray();
     if ((vectorPath != null) && (vectorPath.Length > 2))
     {
         List <Vector3> output = new List <Vector3>();
         output.Add(vectorPath[0]);
         TurnConstructor.turningRadius = this.turningRadius;
         for (int i = 1; i < (vectorPath.Length - 1); i++)
         {
             List <Turn> turnList = new List <Turn>();
             TurnConstructor.Setup(i, vectorPath);
             this.turnConstruct1.Prepare(i, vectorPath);
             this.turnConstruct2.Prepare(i, vectorPath);
             TurnConstructor.PostPrepare();
             if (i == 1)
             {
                 this.turnConstruct1.PointToTangent(turnList);
                 this.turnConstruct2.PointToTangent(turnList);
             }
             else
             {
                 this.turnConstruct1.TangentToTangent(turnList);
                 this.turnConstruct2.TangentToTangent(turnList);
             }
             this.EvaluatePaths(turnList, output);
             if (i == (vectorPath.Length - 2))
             {
                 this.turnConstruct1.TangentToPoint(turnList);
                 this.turnConstruct2.TangentToPoint(turnList);
             }
             this.EvaluatePaths(turnList, output);
         }
         output.Add(vectorPath[vectorPath.Length - 1]);
         p.vectorPath = output;
     }
 }
예제 #3
0
        public override void Apply(Path p, ModifierData source)
        {
            Vector3[] vectorPath = p.vectorPath.ToArray();

            if (vectorPath == null || vectorPath.Length <= 2)
            {
                return;
            }

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

            newPath.Add(vectorPath[0]);

            TurnConstructor.turningRadius = turningRadius;

            for (int i = 1; i < vectorPath.Length - 1; i++)
            {
                List <Turn> turnList = new List <Turn> ();

                TurnConstructor.Setup(i, vectorPath);
                turnConstruct1.Prepare(i, vectorPath);
                turnConstruct2.Prepare(i, vectorPath);

                TurnConstructor.PostPrepare();

                if (i == 1)
                {
                    turnConstruct1.PointToTangent(turnList);
                    turnConstruct2.PointToTangent(turnList);
                }
                else
                {
                    turnConstruct1.TangentToTangent(turnList);
                    turnConstruct2.TangentToTangent(turnList);
                }

                EvaluatePaths(turnList, newPath);

                //Last point
                if (i == vectorPath.Length - 2)
                {
                    turnConstruct1.TangentToPoint(turnList);
                    turnConstruct2.TangentToPoint(turnList);
                }

                EvaluatePaths(turnList, newPath);

                /*Debug.DrawLine (AngleToVector (va)*2+rightCircleCenter,rightCircleCenter,Color.magenta);
                 *
                 * List<Turn> turnList = new List<Turn> ();
                 *
                 * if (i == 1) {
                 *
                 *
                 *      PointToCurve (prev , turnList);
                 *
                 *
                 * } else if (i < vectorPath.Length) {
                 *
                 * }
                 *
                 * if (i == vectorPath.Length-2) {
                 *      //End Point
                 *
                 *      float prevTurnRadius = turningRadius;
                 *
                 *      float minRadi = Mathf.Min ((next-rightCircleCenter).magnitude, (next-leftCircleCenter).magnitude);
                 *      //No curved path is possible with the current turning radius
                 *      if (minRadi <= turningRadius) {
                 *              continue;
                 *
                 *              /*turningRadius = minRadi-0.001F;
                 *
                 *              rightCircleCenter = currentVertice + normal * turningRadius;
                 *              leftCircleCenter = currentVertice - normal * turningRadius;
                 *
                 *              Debug.DrawLine (rightCircleCenter,leftCircleCenter,Color.black);
                 *              DebugCircle (rightCircleCenter,turningRadius,new Color (0,0,0,0.4F));
                 *              DebugCircle (leftCircleCenter,turningRadius,new Color (0,0,0,0.4F));*
                 *      }
                 *
                 *      double alfaRight = Atan2 (next - rightCircleCenter);
                 *      double deltaRight = (ThreeSixtyRadians * 0.25) - Math.Asin (turningRadius / (rightCircleCenter - next).magnitude);
                 *
                 *      //Angle to the point where turning ends
                 *      double gammaRight = alfaRight - deltaRight;
                 *
                 *      Debug.DrawLine (rightCircleCenter+ AngleToVector (gammaRight)*turningRadius, rightCircleCenter, Color.green);
                 *
                 *      double betaRight = ClockwiseAngle (gammaRight, va);
                 *      //double counterClockwiseAngle = ClampAngle (gamma1 - va);
                 *
                 *      double alfaLeft = Atan2 (next - leftCircleCenter);
                 *      double deltaLeft = (ThreeSixtyRadians * 0.25) - Math.Asin (turningRadius / (leftCircleCenter - next).magnitude);
                 *
                 *      //Angle to the point where turning ends
                 *      double gammaLeft = alfaLeft + deltaLeft;
                 *
                 *      Debug.DrawLine (leftCircleCenter+ AngleToVector (gammaLeft)*turningRadius, leftCircleCenter, Color.green);
                 *
                 *      //double vaLeft = ClampAngle (va + ThreeSixtyRadians * 0.5);
                 *      double betaLeft = CounterClockwiseAngle (vaLeft, gammaLeft);
                 *
                 *      Vector3 pRight = AngleToVector (gammaRight)+rightCircleCenter;
                 *      Vector3 pLeft = AngleToVector (gammaLeft)+leftCircleCenter;
                 *
                 *      betaLeft = GetLengthFromAngle (betaLeft,turningRadius);
                 *      betaRight = GetLengthFromAngle (betaRight,turningRadius);
                 *
                 *      betaRight += (pRight-next).magnitude;
                 *      betaLeft += (pLeft-next).magnitude;
                 *
                 *      Debug.Log ("=== Right: "+betaRight+" Left: "+betaLeft+" ===");
                 *
                 *      if (betaRight < betaLeft) {
                 *              AddCircleSegment (va, gammaRight, true, rightCircleCenter, newPath);
                 *      } else {
                 *              AddCircleSegment (vaLeft, gammaLeft, false, leftCircleCenter, newPath);
                 *      }
                 *
                 *      turningRadius = prevTurnRadius;
                 * }
                 *
                 * preRightCircleCenter = rightCircleCenter;
                 * preLeftCircleCenter = leftCircleCenter;
                 *
                 * preVaRight =  vaRight;
                 * preVaLeft = vaLeft;*/

                /*Debug.Log ("Gamma: "+ToDegrees(gamma1));
                 * double clockwiseAngle = Mathf.Min (ClampAngle (va - gamma1),ClampAngle (gamma - va));
                 *
                 * double counterClockwiseAngle = ;
                 *
                 * Debug.DrawLine (AngleToVector (gamma)*2+rightCircleCenter,rightCircleCenter,Color.orange);
                 *
                 *
                 * Debug.Log ("Adding Circle Segment "+ToDegrees(gamma).ToString ()+" "+ToDegrees (va).ToString ()+" "+ToDegrees (delta).ToString ());
                 * AddCircleSegment (gamma,va, clockwiseAngle < counterClockwiseAngle, rightCircleCenter, newPath);
                 */
            }

            newPath.Add(vectorPath[vectorPath.Length - 1]);

            /*for (int i=0;i<newPath.Count-1;i++) {
             *      Debug.DrawLine (newPath[i],newPath[i+1],Color.yellow);
             * }*/

            p.vectorPath = newPath;
        }