//
        public RecastNavigationSystemExtendedFunctionalityDescriptor( Control parentControl, object owner )
            : base(parentControl, owner)
        {
            recastSystem = (RecastNavigationSystem)owner;

            Button button;

            int posY = 8;

            //Geometries toolbox button
            button = new Button();
            parentControl.Controls.Add( button );
            button.Location = new System.Drawing.Point( 8, posY );
            button.Size = new System.Drawing.Size( 140, 32 );
            button.Text = Translate( "Collision" );
            button.UseVisualStyleBackColor = true;
            button.Click += new EventHandler( geometriesButton_Click );

            //Build toolbox button
            button = new Button();
            parentControl.Controls.Add( button );
            button.Location = new System.Drawing.Point( 140 + 8 * 2, posY );
            button.Size = new System.Drawing.Size( 140, 32 );
            button.Text = Translate( "Rebuild" );
            button.UseVisualStyleBackColor = true;
            button.Click += new EventHandler( buildButton_Click );

            posY += 36;

            //Destroy toolbox button
            button = new Button();
            buttonClear = button;
            parentControl.Controls.Add( button );
            button.Location = new System.Drawing.Point( 8, posY );
            button.Size = new System.Drawing.Size( 140, 32 );
            button.Text = Translate( "Clear" );
            button.UseVisualStyleBackColor = true;
            button.Click += new EventHandler( clearButton_Click );

            //Test NavMesh toolbox button
            button = new Button();
            buttonTest = button;
            parentControl.Controls.Add( button );
            button.Location = new System.Drawing.Point( 140 + 8 * 2, posY );
            button.Size = new System.Drawing.Size( 140, 32 );
            button.Text = Translate( "Test" );
            button.UseVisualStyleBackColor = true;
            button.Click += new EventHandler( testButton_Click );

            timer = new Timer();
            timer.Interval = 50;
            timer.Start();
            timer.Tick += new EventHandler( timer_Tick );

            UpdateControls();
        }
Ejemplo n.º 2
0
        //

        public RecastNavigationSystemExtendedFunctionalityDescriptor(Control parentControl, object owner)
            : base(parentControl, owner)
        {
            recastSystem = (RecastNavigationSystem)owner;

            Button button;

            int posY = 8;

            //Geometries toolbox button
            button = new EditorBase.Theme.EditorButton();
            parentControl.Controls.Add(button);
            button.Location = new System.Drawing.Point(8, posY);
            button.Size     = new System.Drawing.Size(140, 32);
            button.Text     = Translate("Collision");
            button.UseVisualStyleBackColor = true;
            button.Click += new EventHandler(geometriesButton_Click);

            //Build toolbox button
            button = new EditorBase.Theme.EditorButton();
            parentControl.Controls.Add(button);
            button.Location = new System.Drawing.Point(140 + 8 * 2, posY);
            button.Size     = new System.Drawing.Size(140, 32);
            button.Text     = Translate("Rebuild");
            button.UseVisualStyleBackColor = true;
            button.Click += new EventHandler(buildButton_Click);

            posY += 36;

            //Destroy toolbox button
            button      = new EditorBase.Theme.EditorButton();
            buttonClear = button;
            parentControl.Controls.Add(button);
            button.Location = new System.Drawing.Point(8, posY);
            button.Size     = new System.Drawing.Size(140, 32);
            button.Text     = Translate("Clear");
            button.UseVisualStyleBackColor = true;
            button.Click += new EventHandler(clearButton_Click);

            //Test NavMesh toolbox button
            button     = new EditorBase.Theme.EditorButton();
            buttonTest = button;
            parentControl.Controls.Add(button);
            button.Location = new System.Drawing.Point(140 + 8 * 2, posY);
            button.Size     = new System.Drawing.Size(140, 32);
            button.Text     = Translate("Test");
            button.UseVisualStyleBackColor = true;
            button.Click += new EventHandler(testButton_Click);

            timer          = new Timer();
            timer.Interval = 50;
            timer.Start();
            timer.Tick += new EventHandler(timer_Tick);

            UpdateControls();
        }
Ejemplo n.º 3
0
            public void Update(float delta, Vec3 unitPosition, Vec3 targetPosition, bool dropPath)
            {
                if (dropPath)
                {
                    DropPath();
                }

                //wait before last path find
                if (pathFindWaitTime > 0)
                {
                    pathFindWaitTime -= delta;
                    if (pathFindWaitTime < 0)
                    {
                        pathFindWaitTime = 0;
                    }
                }

                //already on target position?
                if ((unitPosition.ToVec2() - targetPosition.ToVec2()).LengthSqr() <
                    reachDestinationPointDistance * reachDestinationPointDistance &&
                    Math.Abs(unitPosition.Z - targetPosition.Z) < reachDestinationPointZDifference)
                {
                    DropPath();
                    return;
                }

                //drop path when target position was updated
                if (path != null && (foundPathForTargetPosition - targetPosition).Length() >
                    updatePathWhenTargetPositionHasChangedMoreThanDistance)
                {
                    DropPath();
                }

                //drop path when unit goaway from path
                if (path != null && currentIndex > 0)
                {
                    Vec3 previous = path[currentIndex - 1];
                    Vec3 next     = path[currentIndex];

                    float min = Math.Min(previous.Z, next.Z);
                    float max = Math.Max(previous.Z, next.Z);

                    Vec2 projectedPoint = MathUtils.ProjectPointToLine(
                        previous.ToVec2(), next.ToVec2(), unitPosition.ToVec2());
                    float distance2D = (unitPosition.ToVec2() - projectedPoint).Length();

                    if (distance2D > maxAllowableDeviationFromPath ||
                        unitPosition.Z + reachDestinationPointZDifference < min ||
                        unitPosition.Z - reachDestinationPointZDifference > max)
                    {
                        DropPath();
                    }
                }

                //check if need update path
                if (path == null && pathFindWaitTime == 0)
                {
                    bool found;

                    RecastNavigationSystem system = GetNavigationSystem();
                    if (system != null)
                    {
                        found = system.FindPath(unitPosition, targetPosition, stepSize, polygonPickExtents,
                                                maxPolygonPath, maxSmoothPath, maxSteerPoints, out path);
                    }
                    else
                    {
                        found = true;
                        path  = new Vec3[] { targetPosition };
                    }

                    currentIndex = 0;

                    if (found)
                    {
                        foundPathForTargetPosition = targetPosition;
                        //can't find new path during specified time.
                        pathFindWaitTime = .3f;
                    }
                    else
                    {
                        foundPathForTargetPosition = new Vec3(float.NaN, float.NaN, float.NaN);
                        //can't find new path during specified time.
                        pathFindWaitTime = 1.0f;
                    }
                }

                //progress
                if (path != null)
                {
                    Vec3 point;
                    while (true)
                    {
                        point = path[currentIndex];

                        if ((unitPosition.ToVec2() - point.ToVec2()).LengthSqr() <
                            reachDestinationPointDistance * reachDestinationPointDistance &&
                            Math.Abs(unitPosition.Z - point.Z) < reachDestinationPointZDifference)
                        {
                            //reach point
                            currentIndex++;
                            if (currentIndex == path.Length)
                            {
                                //path is ended
                                DropPath();
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }