Ejemplo n.º 1
0
        public Point[] GetTickLocations(double interval, int count, int length)
        {
            List <Point> ticks = new List <Point>();

            //Make the number of steps 1000 for each curve
            double steps = 1000 / controlpoints.Count - 2 - 1;
            //how much to increment t by with every loop
            double increment = 1 / steps;
            //how much along the curve we have traveled so far
            double travelled = 0;
            //where to get the next point on a given curve
            //assign increment to get the next intended point
            double t = increment;
            //track which curve (defined by two points) is being looked at
            //start at 1 to not break tangent points
            int   curvestartpoint = 1;
            Point prev            = controlpoints[0];

            //Subtract two for the extra points to get the number of curves
            while (curvestartpoint < controlpoints.Count - 2)
            {
                Point  next     = GetPointBetween(curvestartpoint, curvestartpoint + 1, t);
                double distance = Dewlib.GetDistance(prev.x, prev.y, next.x, next.y);
                travelled += distance;
                prev       = next;
                if (travelled >= interval)
                {
                    ticks.Add(next);
                    travelled = 0;
                    if (ticks.Count == count)
                    {
                        break;
                    }
                }
                t += increment;
                if (t > 1)
                {
                    curvestartpoint++;
                    t -= 1;
                }
            }

            if (travelled > 0)
            {
                throw new Exception("Error, too many ticks to get in catmull curve");
            }

            return(ticks.ToArray());
        }
Ejemplo n.º 2
0
        protected override Point GetLastPoint()
        {
            //Necessary to avoid cases where the pixellength is something like 105.000004005432
            int length = Convert.ToInt32(Math.Floor(Double.Parse(HitObjectParser.GetProperty(id, "pixelLength"), CultureInfo.InvariantCulture)));

            //how many steps to travel through the curve
            //divide by curves.Length to scale this with the number of curves
            double steps = length * 2 / curves.Length;
            //how much to increment t by with every loop
            double increment = 1 / steps;
            //how much along the curve we have traveled so far
            double travelled = 0;
            //where to get the next point on a given curve
            //assign increment to get the next intended point
            double t    = increment;
            Point  prev = new Point();

            prev.x = Int32.Parse(HitObjectParser.GetProperty(id, "x"));
            prev.y = Int32.Parse(HitObjectParser.GetProperty(id, "y"));
            //which curve we are looking at
            int curvenumber = 0;

            while (curvenumber < curves.Length)
            {
                Point  next     = curves[curvenumber].Bezier(t);
                double distance = Dewlib.GetDistance(prev.x, prev.y, next.x, next.y);
                travelled += distance;
                prev       = next;
                if (travelled >= length)
                {
                    return(next);
                }

                t += increment;
                if (t > 1)
                {
                    curvenumber++;
                    t -= 1;
                }
            }

            //If we reached the end of the slider without accumulated sliderlength distance,
            //just assume that the last point is the last point of the bezier curve
            return(curves[curves.Length - 1].Bezier(1));
        }
Ejemplo n.º 3
0
        public Point GetPointAlong(int along)
        {
            //Make the number of steps 1000 for each curve
            double steps = 1000 / controlpoints.Count - 2 - 1;
            //how much to increment t by with every loop
            double increment = 1 / steps;
            //how much along the curve we have traveled so far
            double length = 0;
            //where to get the next point on a given curve
            //assign increment to get the next intended point
            double t = increment;
            //track which curve (defined by two points) is being looked at
            //start at 1 to not break tangent points
            int   curvestartpoint = 1;
            Point prev            = controlpoints[0];

            //Subtract two for the extra points to get the number of curves
            while (curvestartpoint < controlpoints.Count - 2)
            {
                Point  next     = GetPointBetween(curvestartpoint, curvestartpoint + 1, t);
                double distance = Dewlib.GetDistance(prev.x, prev.y, next.x, next.y);
                length += distance;
                prev    = next;
                if (length >= along)
                {
                    return(next);
                }

                t += increment;
                if (t > 1)
                {
                    curvestartpoint++;
                    t -= 1;
                }
            }

            //If we reached the end of the slider without accumulated sliderlength distance,
            //just assume that the last point is the last point of the curve
            return(GetPointBetween(controlpoints.Count - 2 - 1, controlpoints.Count - 2, 1));
        }
Ejemplo n.º 4
0
        protected override int[] GetTickLocations()
        {
            //Necessary to avoid cases where the pixellength is something like 105.000004005432
            int length = Convert.ToInt32(Math.Floor(Double.Parse(HitObjectParser.GetProperty(id, "pixelLength"), CultureInfo.InvariantCulture)));

            int sliderruns = Int32.Parse(HitObjectParser.GetProperty(id, "repeat"));
            //Only need ticks for one slider length (no repeats needed)
            //Also no need for double conversion since TickCount is always divisible by sliderruns
            int tickcount = this.GetTickCount() / sliderruns;

            double slidervelocity = this.GetSliderVelocity();
            double tickrate       = Double.Parse(map.GetTag("Difficulty", "SliderTickRate"), CultureInfo.InvariantCulture);
            int    ticklength     = (int)Math.Round(slidervelocity * (100 / tickrate));

            if (length <= ticklength)
            {
                return(new int[0]);
            }

            List <Point> ticks = new List <Point>();

            //how many steps to travel through the curve
            //divide by curves.Length to scale this with the number of curves
            double steps = length * 2 / curves.Length;
            //how much to increment t by with every loop
            double increment = 1 / steps;
            //how much along the curve we have traveled so far
            double travelled = 0;
            //where to get the next point on a given curve
            //assign increment to get the next intended point
            double t    = increment;
            Point  prev = new Point();

            prev.x = Int32.Parse(HitObjectParser.GetProperty(id, "x"));
            prev.y = Int32.Parse(HitObjectParser.GetProperty(id, "y"));
            //which curve we are looking at
            int curvenumber = 0;

            while (curvenumber < curves.Length)
            {
                Point  next     = curves[curvenumber].Bezier(t);
                double distance = Dewlib.GetDistance(prev.x, prev.y, next.x, next.y);
                travelled += distance;
                prev       = next;
                if (travelled >= ticklength)
                {
                    ticks.Add(next);
                    travelled = 0;
                    if (ticks.Count == tickcount)
                    {
                        break;
                    }
                }
                t += increment;
                if (t > 1)
                {
                    curvenumber++;
                    t -= 1;
                }
            }

            if (travelled > 0)
            {
                throw new Exception("Error, too many ticks to get in bezier curve, travelled=" + travelled);
            }

            List <int> locations = new List <int>();

            foreach (Point i in ticks)
            {
                locations.Add(i.IntX());
            }

            return(locations.ToArray());
        }
Ejemplo n.º 5
0
 //Gets the distance between the start point and end point
 //Note that this is NOT the length of the slider
 public double DistanceBetween()
 {
     return(Dewlib.GetDistance(begin.x, begin.y, end.x, end.y));
 }