Ejemplo n.º 1
0
        //replace with StepDetection Event trigger
        private Vector2 testStepTrigger(float _heading)
        {
            string start, end;
            float  x, y;

            var nHeading = (float)(Math.PI / 2 - _heading);

            x = realPosition.X + strideLength * (float)Math.Cos(nHeading);
            y = realPosition.Y - strideLength * (float)Math.Sin(nHeading);


            var newPosition = new Vector2(x, y);

            var realHolder    = realPosition;
            var nearestHolder = nearestGraphNode;

            realPosition = newPosition;
            var check = CalculateNearestNode();

            if (check != -1)
            {
                if (!nearestHolder.Equals(nearestGraphNode))
                {
                    start = nearestGraphNode.ToPointString();
                    end   = nearestHolder.ToPointString();

                    if (start != end)
                    {
                        if (!WallCol.IsValidStep((int)nearestGraphNode.X, (int)nearestGraphNode.Y, (int)nearestHolder.X, (int)nearestHolder.Y))
                        {
                            realPosition     = realHolder;
                            nearestGraphNode = nearestHolder;
                        }
                    }
                    else
                    {
                        //realPosition = realHolder;
                    }
                }
            }
            else
            {
                realPosition = realHolder;
            }
            return(realPosition);
        }
Ejemplo n.º 2
0
        /*
         * public override void Draw(CGRect rect)
         * {
         *  base.Draw(rect);
         *
         *
         *
         *  //get graphics context
         *  using (var g = UIGraphics.GetCurrentContext())
         *  {
         *      //set up drawing attributes
         *      g.SetLineWidth(3/_scaleFactor);
         *      UIColor.Cyan.SetStroke ();
         *      g.SetShadow (new CGSize (1, 1), 10, UIColor.Blue.CGColor);
         *      //use a dashed line
         *      //g.SetLineDash(0, new[] {5, 2/_scaleFactor});
         *
         *      //add geometry to graphics context and draw it
         *      g.AddPath(path);
         *      g.DrawPath(CGPathDrawingMode.Stroke);
         *  }
         * }
         */

        public override void Draw(CGRect rect)
        {
            if (pathSet == true)
            {
                base.Draw(rect);

                using (var context = UIGraphics.GetCurrentContext()) {
                    //set up drawing attributes
                    context.SetLineWidth(3 / _scaleFactor);
                    UIColor.Cyan.SetStroke();
                    context.SetShadow(new CGSize(1, 1), 10, UIColor.Blue.CGColor);

                    var lineStart = pointsList[0];
                    var lineEnd   = pointsList[0];

                    var line = new CGPoint[2];


                    foreach (var pathPoint in pointsList)
                    {
                        // If we can make a non obstructed path from our start to end , just continue
                        int originX = (int)lineStart.X;
                        int originY = (int)lineStart.Y;
                        int targetX = (int)pathPoint.X;
                        int targetY = (int)pathPoint.Y;
                        if (wallCol.IsValidStep(originX, originY, targetX, targetY))
                        {
                            // Our step is valid
                            lineEnd = pathPoint;
                        }
                        else
                        {
                            // We cannot perform this step, revert to last one
                            line[0] = lineStart;
                            line[1] = lineEnd;
                            context.AddLines(line);
                            context.StrokePath();
                            lineStart = lineEnd;
                        }
                    }

                    line[0] = lineStart;
                    line[1] = lineEnd;
                    context.AddLines(line);
                    context.StrokePath();
                    //directionPoints.Add (line[1]);

                    //mainView.pushDirectionsPointsList (directionPoints);
                    //context.AddPath(path);
                    //context.DrawPath(CGPathDrawingMode.Stroke);



                    /*
                     * // Draw a quad curve with end points s,e and control point cp1
                     * context.SetStrokeColor (1, 1, 1, 1);
                     * s = new CGPoint (30, 300);
                     * e = new CGPoint (270, 300);
                     * cp1 = new CGPoint (150, 180);
                     * context.MoveTo (s.X, s.Y);
                     * context.AddQuadCurveToPoint (cp1.X, cp1.Y, e.X, e.Y);
                     * context.AddQuadCurveToPoint (cp1.X + 100, cp1.Y + 100, e.X + 100, e.Y + 100);
                     *
                     * context.StrokePath ();
                     */
                }
            }
        }