Help with PathMeasure - please help instructors

nick5454nick5454 USUniversity ✭✭✭

I have this code, which simply positions a sprite, with every screen update ( .003 ticks ), uses PathMeasure to grab the new location. when the distance traveled on the path is greater than the path's length it stops. Very simple.

The problem I have is that when I execute a lineTo and then ArcTo the arc is never found by the path, but if I comment out the LineTo, then the Arc works. I can have multiple LineTo's and it's fine, but if I add an ArcTo the Arc is never executed, nor is it considered part of the path in the length method. This seems like a bug. This is an openGL app. I can email the project, but I don't want to post it on the interwebs,

I also used the drawing2d recipe example on xamarin and plugged in the values and it works fine.

Here is the path construction:
_pathLine.MoveTo (0, 600); //_pathLine.LineTo (100, 500); _pathLine.ArcTo (new RectF (50, 400, 150, 500), 90, 180, true);

Here is the update routine called every 3 ticks, note: NextContour() never returns true

`public void UpdatePosition () {
PathMeasure pathMeasure = new PathMeasure (_currentPath, false);
float[] aCords = new float[]{ 0f, 0f };
float[] bCords = new float[]{ 0f, 0f };

        // last update time * velocity
        if (_hasFinishedCurrentPath) {
            // begin new path
            _distanceTraveledOnPath = 0f;

            pathMeasure.GetPosTan (0f, aCords, bCords);
            _hasFinishedCurrentPath = false;

        } else {
            // calculate next position

            _distanceTraveledOnPath += 3f;
            pathMeasure.GetPosTan (_distanceTraveledOnPath, aCords, bCords);

        }

        // has path ended
        if (_distanceTraveledOnPath >= pathMeasure.Length) { 
            pathMeasure.GetSegment (0, _distanceTraveledOnPath, _currentPath, true);
            bool c = pathMeasure.NextContour ();
            //_hasFinishedCurrentPath = true;
        }

        this.Position = new PointF (aCords [0], aCords [1]);


    }`

If anyone has seen this before please let me know

Posts

  • nick5454nick5454 USUniversity ✭✭✭

    Anyone?

  • CheesebaronCheesebaron DKInsider, University mod

    From the documentation:

    sweepAngle Sweep angle (in degrees) measured clockwise, treated mod 360.

    Although, that should not interfere with 180 degrees...

    Will try see if I can reproduce later :)

  • nick5454nick5454 USUniversity ✭✭✭

    Yeah, that's ok.

    The problem is that the arcTo when coming after a lineTo is not being considered. If I take the same code and use it in a drawing2d recipe with canvas it works fine. It seems when using for a path that is not visually displayed, it has issues calculating an arc.

    As a work around I have an array of paths so I can split up the arc statements, but this is very ugly.

    If you paste this code with your recommended change in the Drawing2d recipe on xamarin's site showing the code draws.

    ` Path path = new Path ();

            float topScreen = 400;
            path.MoveTo (0, 600);
            path.LineTo (100, 500);
    
            path.ArcTo (new RectF (50, 400, 150, 500), 90, -180, true);
    
            canvas.DrawPath (path, paint);`
    
  • MarkSmith.8123MarkSmith.8123 USXamarin Team, University, XamUProfessors Xamurai

    What happens if you change the order of drawing - for example draw the arc first, then move back to the original position and draw the line?

  • nick5454nick5454 USUniversity ✭✭✭
    edited April 2015

    [https://flic.kr/p/rNoWPh](Android with LineToAfter)
    [https://flic.kr/p/s5Wn5M](Android with LineToAfter)

    The issue I have with this is that monster ( mosquito in galaga for the example ) has to following a continuous path, so changing the order will causes a bad path, so I have to follow a set.

    I even tried using next contour, but it seems that it won't work either.

  • nick5454nick5454 USUniversity ✭✭✭
  • nick5454nick5454 USUniversity ✭✭✭

    https://flic.kr/p/rNoWPh

    posted again because the link tool has an issue with flicker. This link shows lineTo before and the link about shows LineToBefore. Notice it works fine when the arc is first. This is a quicktime 10 second movie showing the code and the android player next to it

Sign In or Register to comment.