コード例 #1
0
        private ICurve GetCurve(RoadGraphNode node1, RoadGraphNode node2)
        {
            ICurve curve;

            if (node1.Neighbors.Count == 1 && node2.Neighbors.Count == 1)
            {
                curve = new CubicBezierCurve(
                    node1.Position,
                    GetControlPoint(node1),
                    GetControlPoint(node2),
                    node2.Position);
            }
            else if (node1.Neighbors.Count == 1 && node2.Neighbors.Count > 1)
            {
                curve = new QuadraticBezierCurve(
                    node1.Position,
                    GetControlPoint(node1),
                    node2.Position);
            }
            else if (node2.Neighbors.Count == 1 && node1.Neighbors.Count > 1)
            {
                curve = new QuadraticBezierCurve(
                    node1.Position,
                    GetControlPoint(node2),
                    node2.Position);
            }
            else
            {
                curve = new LinearBezierCurve(node1.Position, node2.Position);
            }

            return(curve);
        }
コード例 #2
0
    void LaunchRocket()
    {
        if (!buildingHandler.building && timePassed > timeBetweenLaunches)
        {
            if (rockets > 0)
            {
                Vector3 start = transform.position;

                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                Physics.Raycast(ray, out hit);
                if (hit.collider != null)
                {
                    Vector3 end = hit.collider.transform.position;
                    end.y = 0;

                    Vector3 middle = Vector3.Lerp(start, end, 0.8f);
                    middle.y = 20;

                    curve = new QuadraticBezierCurve(start, middle, end);

                    Rocket rocket = Instantiate(rocketPrefab).GetComponent <Rocket>();
                    rocket.target = end;
                    rocket.curve  = curve;
                    rocket.Launch();
                    timePassed = 0;
                    rockets   -= 1;
                }
            }
        }
    }
コード例 #3
0
 protected QuadraticBezierCurve updatePath(QuadraticBezierCurve curve)
 {
     bezierPointPosition = 0f;
     curve = bezierLines.NextDots(curve,
                                  targetPosition,
                                  GameControl.gameControl.BatBoundaries);
     renewedPosition = curve.p0;
     return(curve);
 }
コード例 #4
0
ファイル: BezierLines.cs プロジェクト: Niggita/Ravenloft
    //Рассчитывает следующую точку квадратичной кривой Безье по заданным точкам
    public Vector3 CalculateBezierPoint(float t, QuadraticBezierCurve curve)
    {
        Vector3 position = new Vector3();

        position =
            Mathf.Pow(1f - t, 2) * curve.p0 +
            (1f - t) * 2 * t * curve.p1 +
            Mathf.Pow(t, 2) * curve.p2;
        return(position);
    }
コード例 #5
0
    protected QuadraticBezierCurve createPathQuadratic(Vector3 start)
    {
        QuadraticBezierCurve quadraticCurve = bezierLines.CreateQuadraticLineDots(
            start,
            GameControl.gameControl.PlayerInstance.CurrentPosition,
            GameControl.gameControl.BatBoundaries);

        bezierPointPosition = 0f;
        calculateMovementParameters(quadraticCurve);
        return(quadraticCurve);
    }
コード例 #6
0
ファイル: EnemyAttacking.cs プロジェクト: Niggita/Ravenloft
 protected virtual void InitializeAttack(Vector3 start)
 {
     targetPosition = GameControl.gameControl.PlayerInstance.CurrentPosition;
     do
     {
         quadraticCurve = createPathQuadratic(start);
     }while(Vector3.Angle(
                quadraticCurve.p1 - start,
                targetPosition - start)
            < 45f);
 }
コード例 #7
0
ファイル: BezierLines.cs プロジェクト: Niggita/Ravenloft
    //Возвращает три точки, нужные для построения квадратичной кривой Безье
    public QuadraticBezierCurve CreateQuadraticLineDots(Vector3 startPosition, Vector3 finishPosition, EnemyBoundaries boundaries)
    {
        QuadraticBezierCurve quadraticCurve = new QuadraticBezierCurve();

        quadraticCurve.p0 = startPosition;
        quadraticCurve.p1 = GenerationMath.RandomPositionOnCylinder(
            startPosition,
            Vector3.Distance(startPosition, finishPosition),
            boundaries);
        quadraticCurve.p2 = finishPosition;
        return(quadraticCurve);
    }
コード例 #8
0
ファイル: BezierLines.cs プロジェクト: Niggita/Ravenloft
    //Возвращает следующий сегмент квадратичной кривой Безье,
    //Зависящий от предыдущего
    public QuadraticBezierCurve NextDots(QuadraticBezierCurve oldSettings, Vector3 nextPosition, EnemyBoundaries boundaries)
    {
        QuadraticBezierCurve quadraticCurve = new QuadraticBezierCurve();

        quadraticCurve.p0 = oldSettings.p2;

        quadraticCurve.p2 = nextPosition;
        quadraticCurve.p1 = GenerationMath.RandomPositionInCylinder(
            quadraticCurve.p2,
            Vector3.Distance(quadraticCurve.p0, nextPosition),
            boundaries);
        return(quadraticCurve);
    }
コード例 #9
0
ファイル: BezierLines.cs プロジェクト: Niggita/Ravenloft
    //Высчитывает приблизительную длину квадратичной кривой Безье
    public float ApproximateLineLength(QuadraticBezierCurve curve)
    {
        float   length = 0f;
        Vector3 point1 = curve.p0;
        Vector3 point2;

        for (float i = 0.05f; i < 1f; i += 0.05f)
        {
            point2  = CalculateBezierPoint(i, curve);
            length += Vector3.Distance(point1, point2);
            point1  = point2;
        }
        return(length);
    }
コード例 #10
0
    private void LaunchMissile()                         //Function used to launch missile
    {
        if (Input.GetMouseButtonDown(1) && target != -1) //Ensures target is selected when mouse clicked
        {
            tempPath.Clear();

            GameObject missile = (GameObject)GameObject.Instantiate(missilePrefab, MasterScript.systemListConstructor.systemList[system].systemObject.transform.position, Quaternion.identity);

            curveBuilder        = missile.GetComponent <QuadraticBezierCurve>();
            curveBuilder.target = target;

            tempPath.Add(missile.transform.position);

            bool pathfinding = true;

            Vector2 tempPos = missile.transform.position;

            while (pathfinding == true)
            {
                tempPos = FindTrajectoryIntersections(tempPos, MasterScript.systemListConstructor.systemList[target].systemObject.transform.position);

                if (tempPos == Vector2.zero)
                {
                    tempPath.Add(MasterScript.systemListConstructor.systemList[curveBuilder.target].systemObject.transform.position);
                    pathfinding = false;
                    break;
                }

                else
                {
                    tempPath.Add(tempPos);
                }
            }

            for (int i = 0; i < tempPath.Count; ++i)
            {
                curveBuilder.pathToFollow.Add(new Vector3(tempPath[i].x, tempPath[i].y, 0f));
            }

            curveBuilder.moving = true;
        }
    }
コード例 #11
0
        /// <summary>
        /// This function creates the flight path of the disc regardless
        /// of whether the disc is travelling to a person or into space.
        /// </summary>
        /// <param name="msBetweenPoints">The number of ms between each pair of 
        /// adjacent points.</param>
        /// <returns>The full list of points that the disc traverses</returns>
        internal List<PointF> FlightPath(float msBetweenPoints)
        {
            QuadraticBezierCurve curve = new QuadraticBezierCurve(StartPosition(),
                                                            ControlPoint,
                                                            EndPosition());

              float distPerDivision = msBetweenPoints / 1000.0f * DiscSpeed;

              return curve.Points(distPerDivision).ToList();
        }
コード例 #12
0
        /// <summary>
        /// Calculates the nearest distance from the given coordinates to 
        /// the discs flight path.
        /// 
        /// This assumes that the disc travels a long a quadratic bezier curve to
        /// get an analytic solution.
        /// </summary>
        /// <param name="mouseLocation"></param>
        /// <returns></returns>
        internal float DistFromFlightPath(PointF mouseLocation)
        {
            QuadraticBezierCurve curve = new QuadraticBezierCurve(StartPosition(),
                                                            ControlPoint,
                                                            EndPosition());

              return curve.DistanceFromPoint(mouseLocation);
        }
コード例 #13
0
            /// <summary>
            ///     Changes the type of the selected line.
            /// </summary>
            /// <param name="value">The value.</param>
            private void ChangeLineType(object value)
            {
                Type type = value as Type;

                if (type == null)
                {
                    throw new ArgumentException();
                }

                SelectedLine selectedLine = _selectedLine;

                if (selectedLine == null)
                {
                    return;
                }

                ILine currLine     = selectedLine.Line;
                Type  currLineType = currLine.GetType();

                if (type == currLineType)
                {
                    return;
                }

                ILine newLine;

                if (type == typeof(Line))
                {
                    newLine = new Line(currLine.Start, currLine.End);
                }
                else if (type == typeof(QuadraticBezierCurve))
                {
                    if (currLineType == typeof(Line))
                    {
                        newLine = new QuadraticBezierCurve(
                            currLine.Start,
                            new LineVector((currLine.Start.Vector + currLine.End.Vector) / 2),
                            currLine.End);
                    }
                    else if (currLineType == typeof(CubicBezierCurve))
                    {
                        CubicBezierCurve cubic = (CubicBezierCurve)currLine;

                        Vector2 vec = currLine.Start.Vector + (currLine.End.Vector - currLine.Start.Vector) / 2;
                        newLine = new QuadraticBezierCurve(
                            cubic.Start,
                            new LineVector(vec),
                            cubic.End);
                    }
                    else
                    {
                        throw new NotSupportedException(
                                  $"Cannot change a line of type '{currLineType.FullName}' to a line of type '{type.FullName}'.");
                    }
                }
                else if (type == typeof(CubicBezierCurve))
                {
                    if (currLineType == typeof(Line))
                    {
                        Vector2 vec = (currLine.End.Vector - currLine.Start.Vector) / 3;
                        newLine = new CubicBezierCurve(
                            currLine.Start,
                            new LineVector(currLine.Start.Vector + vec),
                            new LineVector(currLine.Start.Vector + vec + vec),
                            currLine.End);
                    }
                    else if (currLineType == typeof(QuadraticBezierCurve))
                    {
                        QuadraticBezierCurve quad = (QuadraticBezierCurve)currLine;

                        Vector2 start   = quad.Start.Vector;
                        Vector2 end     = quad.End.Vector;
                        Vector2 control = quad.ControlPoint.Vector;

                        newLine = new CubicBezierCurve(
                            quad.Start,
                            new LineVector(start + (2f / 3f * (control - start))),
                            new LineVector(end + (2f / 3f * (control - end))),
                            quad.End);
                    }
                    else
                    {
                        throw new NotSupportedException(
                                  $"Cannot change a line of type '{currLineType.FullName}' to a line of type '{type.FullName}'.");
                    }
                }
                else
                {
                    throw new NotSupportedException(
                              $"Cannot change a line of type '{currLineType.FullName}' to a line of type '{type.FullName}'.");
                }

                Debug.Assert(newLine.GetType() == type, "newLine.GetType() == type");

                selectedLine.EdgePart.Lines.Replace(currLine, newLine);

                _selectedLine = new SelectedLine(
                    selectedLine.Tile,
                    selectedLine.EdgePart,
                    newLine,
                    selectedLine.LineTransform);
            }
コード例 #14
0
 protected void calculateMovementParameters(QuadraticBezierCurve curve)
 {
     uniformMotion.Distance = bezierLines.ApproximateLineLength(curve);
     uniformMotion.Speed    = thisEnemy.Speed;
     uniformMotion.GetTime();
 }
コード例 #15
0
ファイル: VDCanvas.cs プロジェクト: Alex-Malik/VeDraw
        private void Create()
        {
            RemoveThumbs();

            // Create Move (M) command if this is the first token
            if (!CurrentFigure.Tokens.Any())
            {
                CurrentFigure.Tokens.Add(
                    new Move(
                        Cache.MouseDownPoint.X - 50.0,
                        Cache.MouseDownPoint.Y + 50.0));
            }

            if (StartWithMove && !(CurrentFigure.Tokens.Last() is Move))
            {
                CurrentFigure.Tokens.Add(
                    new Move(
                        Cache.MouseDownPoint.X - 50.0,
                        Cache.MouseDownPoint.Y + 50.0));
            }

            // Token which will be created
            Token token = null;

            // Depending on command create corresponding token
            if (CreateCommand == VDCanvasCommand.CreateLine)
            {
                token = new Line(Cache.MouseDownPoint.X + 50.0, Cache.MouseDownPoint.Y - 50.0);
            }
            else if (CreateCommand == VDCanvasCommand.CreateCubicCurve)
            {
                token = new CubicBezierCurve(
                    Cache.MouseDownPoint.X - 50.0,
                    Cache.MouseDownPoint.Y,
                    Cache.MouseDownPoint.X + 50.0,
                    Cache.MouseDownPoint.Y,
                    Cache.MouseDownPoint.X + 50.0,
                    Cache.MouseDownPoint.Y - 50.0);
            }
            else if (CreateCommand == VDCanvasCommand.CreateQuadraticCurve)
            {
                token = new QuadraticBezierCurve(
                    Cache.MouseDownPoint.X,
                    Cache.MouseDownPoint.Y,
                    Cache.MouseDownPoint.X + 50.0,
                    Cache.MouseDownPoint.Y - 50.0);
            }
            else if (CreateCommand == VDCanvasCommand.CreateSmoothCubicCurve)
            {
                token = new SmoothCubicBezierCurve(
                    Cache.MouseDownPoint.X,
                    Cache.MouseDownPoint.Y,
                    Cache.MouseDownPoint.X + 50.0,
                    Cache.MouseDownPoint.Y - 50.0);
            }
            else if (CreateCommand == VDCanvasCommand.CreateSmoothQuadraticCurve)
            {
                token = new SmoothQuadraticBezierCurve(
                    Cache.MouseDownPoint.X,
                    Cache.MouseDownPoint.Y,
                    Cache.MouseDownPoint.X + 50.0,
                    Cache.MouseDownPoint.Y - 50.0);
            }
            else if (CreateCommand == VDCanvasCommand.CreateClose)
            {
                token = new Close();
            }

            // Add just created token to the figure
            CurrentFigure.Tokens.Add(token);

            // Depending on Shift key status continue to create elements
            if (Keyboard.GetKeyStates(Key.LeftShift) != KeyStates.Down)
            {
                Edit(token);
            }
            else
            {
                GoToCreateMode();
            }

            InvalidateMeasure();
        }
コード例 #16
0
        /// <summary>
        /// Draw the disc flight.
        /// 
        /// Currently simply a straight line from A to B. Could enhance this so
        /// that it draws a cardinal spline instead at some point. The UI to draw
        /// that is the more difficult area.
        /// </summary>
        /// <param name="display"></param>
        /// <param name="startLocation"></param>
        /// <param name="controlPoint"></param>
        /// <param name="endLocation"></param>
        /// <param name="converter"></param>
        private void DrawDiscFlight(Graphics display,
                                PointF startLocation,
                                PointF controlPoint,
                                PointF endLocation,
                                PitchScreenCoordConverter converter)
        {
            Point screenCoordsStart = converter.pitchToScreenCoords(startLocation);
              Point screenCoordsEnd = converter.pitchToScreenCoords(endLocation);
              Point screenControlPoint = converter.pitchToScreenCoords(controlPoint);

              QuadraticBezierCurve curve = new QuadraticBezierCurve(screenCoordsStart,
                                                            screenControlPoint,
                                                            screenCoordsEnd);

              display.DrawBeziers(mDiscFlightPen, curve.ToCubic());

              display.DrawRectangle(mDiscFlightPen,
                            screenControlPoint.X - 1,
                            screenControlPoint.Y - 1,
                            2, 2);
        }
コード例 #17
0
            /// <summary>
            ///     Changes the type of the selected line.
            /// </summary>
            /// <param name="value">The value.</param>
            private void ChangeLineType(object value)
            {
                Type type = value as Type;
                if (type == null) throw new ArgumentException();

                SelectedLine selectedLine = _selectedLine;
                if (selectedLine == null) return;

                ILine currLine = selectedLine.Line;
                Type currLineType = currLine.GetType();
                if (type == currLineType) return;

                ILine newLine;

                if (type == typeof(Line))
                    newLine = new Line(currLine.Start, currLine.End);
                else if (type == typeof(QuadraticBezierCurve))
                {
                    if (currLineType == typeof(Line))
                    {
                        newLine = new QuadraticBezierCurve(
                            currLine.Start,
                            new LineVector((currLine.Start.Vector + currLine.End.Vector) / 2),
                            currLine.End);
                    }
                    else if (currLineType == typeof(CubicBezierCurve))
                    {
                        CubicBezierCurve cubic = (CubicBezierCurve) currLine;

                        Vector2 vec = currLine.Start.Vector + (currLine.End.Vector - currLine.Start.Vector) / 2;
                        newLine = new QuadraticBezierCurve(
                            cubic.Start,
                            new LineVector(vec),
                            cubic.End);
                    }
                    else
                    {
                        throw new NotSupportedException(
                            $"Cannot change a line of type '{currLineType.FullName}' to a line of type '{type.FullName}'.");
                    }
                }
                else if (type == typeof(CubicBezierCurve))
                {
                    if (currLineType == typeof(Line))
                    {
                        Vector2 vec = (currLine.End.Vector - currLine.Start.Vector) / 3;
                        newLine = new CubicBezierCurve(
                            currLine.Start,
                            new LineVector(currLine.Start.Vector + vec),
                            new LineVector(currLine.Start.Vector + vec + vec),
                            currLine.End);
                    }
                    else if (currLineType == typeof(QuadraticBezierCurve))
                    {
                        QuadraticBezierCurve quad = (QuadraticBezierCurve) currLine;

                        Vector2 start = quad.Start.Vector;
                        Vector2 end = quad.End.Vector;
                        Vector2 control = quad.ControlPoint.Vector;

                        newLine = new CubicBezierCurve(
                            quad.Start,
                            new LineVector(start + (2f / 3f * (control - start))),
                            new LineVector(end + (2f / 3f * (control - end))),
                            quad.End);
                    }
                    else
                    {
                        throw new NotSupportedException(
                            $"Cannot change a line of type '{currLineType.FullName}' to a line of type '{type.FullName}'.");
                    }
                }
                else
                {
                    throw new NotSupportedException(
                        $"Cannot change a line of type '{currLineType.FullName}' to a line of type '{type.FullName}'.");
                }

                Debug.Assert(newLine.GetType() == type, "newLine.GetType() == type");

                selectedLine.EdgePart.Lines.Replace(currLine, newLine);

                _selectedLine = new SelectedLine(
                    selectedLine.Tile,
                    selectedLine.EdgePart,
                    newLine,
                    selectedLine.LineTransform);
            }