コード例 #1
0
            /// <summary>
            /// Update the edit brush for texture and heightmap editing.
            /// </summary>
            public void UpdateEditBrush()
            {
                float secs = Time.WallClockFrameSeconds;

                // Grab the current state of the gamepad.
                GamePadInput pad = GamePadInput.GetGamePad0();

                if (InGame.inGame.CurrentUpdateMode == UpdateMode.MouseEdit &&
                    InGame.inGame.mouseEditUpdateObj.ToolBar.CurrentMode != BaseEditUpdateObj.ToolMode.EditObject &&
                    InGame.inGame.mouseEditUpdateObj.ToolBar.CurrentMode != BaseEditUpdateObj.ToolMode.Paths)
                {
                    ColorPalette.Active = false;
                }

                parent.cursor3D.Position = shared.CursorPosition;
                shared.CursorPosition    = parent.cursor3D.Position;

                Vector2 newPosition = new Vector2(shared.CursorPosition.X, shared.CursorPosition.Y);

                if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                {
                    newPosition = parent.MouseEdit.DoTerrain(parent.Camera);
                    parent.Cursor3D.AltPosition = new Vector3(newPosition, 0);
                }
                else if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch)
                {
                    newPosition = parent.TouchEdit.DoTerrain(parent.Camera);

                    parent.Cursor3D.AltPosition = new Vector3(newPosition, 0);

                    ToggleTouch3DCursor();

                    //every frame track whether or not it's valid to apply the current terrain tool (paint, etc.)
                    //this ensures we don't apply the tool just by selecting it
                    if (TouchInput.TouchCount == 1 && InGame.inGame.TouchEdit.HasNonUITouch() && !TouchInput.WasMultiTouch)
                    {
                        float touchAge = (float)(Time.WallClockTotalSeconds - TouchInput.Touches[0].startTime);

                        //edit brush only allowed if touch has been around for at least 1/4 of a second
                        shared.editBrushAllowedForTouch = touchAge >= 0.25f;
                    }
                    else
                    {
                        shared.editBrushAllowedForTouch = false;
                    }
                }
                else
                {
                    parent.Cursor3D.AltPosition = parent.Cursor3D.Position;
                }

                const float minEditBrushMoveSq = 0.25f * 0.25f;

                if (Vector2.DistanceSquared(newPosition, shared.editBrushPosition) >= minEditBrushMoveSq)
                {
                    shared.editBrushMoved = true;
                }
                else
                {
                    shared.editBrushMoved = false;
                }
                // Update the position, even if it's only a tiny movement.
                if (InGame.inGame.SnapToGrid)
                {
                    Vector2 pos = newPosition + brushPositionError;

                    pos -= brushPositionError;
                    Vector2 prevPos = pos;

                    pos = InGame.SnapPosition(pos);

                    brushPositionError = pos - prevPos;

                    shared.editBrushPosition = pos;
                }
                else
                {
                    shared.editBrushPosition = newPosition;
                }

                //
                // Adjust brush size, but only if it's not the selection brush (handled elsewhere).
                //
                Brush2DManager.Brush2D brush
                    = Brush2DManager.GetBrush(shared.editBrushIndex);
                if (shared.editBrushSizeActive && (brush != null) && ((brush.Type & Brush2DManager.BrushType.Selection) == 0))
                {
                    if (InGame.inGame.SnapToGrid)
                    {
                        if (Actions.BrushSmaller.WasPressedOrRepeat || InGame.inGame.touchEditUpdateObj.ToolBar.TouchBrushControls.IsToggled(Boku.ToolBar.TouchControls.BrushActionIDs.baBrushLess))
                        {
                            shared.editBrushRadius -= 0.5f;
                            shared.editBrushRadius  = MathHelper.Max(0.5f, shared.editBrushRadius);
                        }
                        if (Actions.BrushLarger.WasPressedOrRepeat || InGame.inGame.touchEditUpdateObj.ToolBar.TouchBrushControls.IsToggled(Boku.ToolBar.TouchControls.BrushActionIDs.baBrushMore))
                        {
                            shared.editBrushRadius += 0.5f;
                        }
                    }
                    else
                    {
                        const float brushGrowthRate = 1.0f;
                        if (Actions.BrushSmaller.IsPressed || InGame.inGame.touchEditUpdateObj.ToolBar.TouchBrushControls.IsToggled(Boku.ToolBar.TouchControls.BrushActionIDs.baBrushLess))
                        {
                            shared.editBrushRadius *= 1.0f - brushGrowthRate * secs;
                        }
                        if (Actions.BrushLarger.IsPressed || InGame.inGame.touchEditUpdateObj.ToolBar.TouchBrushControls.IsToggled(Boku.ToolBar.TouchControls.BrushActionIDs.baBrushMore))
                        {
                            shared.editBrushRadius *= 1.0f + brushGrowthRate * secs;
                        }
                    }
                    if (shared.editBrushRadius < Terrain.Current.CubeSize)
                    {
                        shared.editBrushRadius = Terrain.Current.CubeSize;
                    }
                    /// A radius of about 400 adds roughly the entire terrain budget
                    /// to the scene at once. We'll try for allowing the user 1/3 of the
                    /// budget at a single go (1/3 of the budget is the top of the green zone)
                    /// and see what kind of complaints we get.
                    /// ***-taking it down further, for many benefits.
                    if (shared.editBrushRadius > kMaxBrushRadius)
                    {
                        shared.editBrushRadius = kMaxBrushRadius;
                    }
                }
            }   // end of BaseEditUpdateObj UpdateEditBrush()