Beispiel #1
0
        public override void OnClick(InputState input)
        {
            //Attempt to remove wall at clicked position
            Ray?mouseRay = input.GetMouseRay();

            if (mouseRay != null)
            {
                AbstractWorldObject selectedObject = VoxelRaycastUtility.GetNearestIntersectingWorldObject((Ray)mouseRay);

                if (selectedObject != null && selectedObject is Wall)
                {
                    BuildTools.RemoveWall(selectedObject as Wall);
                }
            }
        }
        public override void OnClick(InputState input)
        {
            //Attempt to place the first point of the wall
            Ray?mouseRay = input.GetMouseRay();

            if (mouseRay != null)
            {
                AbstractWorldObject selectedObject = VoxelRaycastUtility.GetNearestIntersectingWorldObject((Ray)mouseRay);

                if (selectedObject != null)
                {
                    Vector3?wallAnchor = VoxelRaycastUtility.GetNearestWallAnchor(VoxelRaycastUtility.GetNearestCollisionFace(selectedObject.GetCollisionFaces(), (Ray)mouseRay), (Ray)mouseRay);

                    if (wallAnchor != null)
                    {
                        Vector3 anchor = (Vector3)wallAnchor;


                        //Add anchor to start of collection of wall points...
                    }
                }
            }
        }
Beispiel #3
0
        public override void OnClick(InputState input)
        {
            //Attempt to add block at clicked position
            Ray?mouseRay = input.GetMouseRay();

            if (mouseRay != null)
            {
                AbstractWorldObject selectedObject = VoxelRaycastUtility.GetNearestIntersectingWorldObject((Ray)mouseRay);

                if (selectedObject != null)
                {
                    //Need a way to determine what type of block to create based on BlockType
                    bool blockAdded = BuildTools.AddBlock((Ray)mouseRay, selectedObject as AbstractBlock);

                    if (blockAdded)
                    {
                        RemoveQuantity(1);
                    }
                }
            }


            //If successful, decrement _quantity and _numUses
        }
Beispiel #4
0
        public override void HandleInput(Microsoft.Xna.Framework.GameTime gameTime, InputState input)
        {
            /*  if (input.CurrentKeyboardState.IsKeyDown(Keys.D1) && input.PreviousKeyboardState.IsKeyUp(Keys.D1))
             * {
             *    tools = TEMP_Tools.AddBlock;
             * }
             * if (input.CurrentKeyboardState.IsKeyDown(Keys.D2) && input.PreviousKeyboardState.IsKeyUp(Keys.D2))
             * {
             *    tools = TEMP_Tools.RemoveBlock;
             * }
             * if (input.CurrentKeyboardState.IsKeyDown(Keys.D3) && input.PreviousKeyboardState.IsKeyUp(Keys.D3))
             * {
             *    tools = TEMP_Tools.AddWall;
             * }
             * if (input.CurrentKeyboardState.IsKeyDown(Keys.D4) && input.PreviousKeyboardState.IsKeyUp(Keys.D4))
             * {
             *    tools = TEMP_Tools.RemoveWall;
             * }
             * if (input.CurrentKeyboardState.IsKeyDown(Keys.D5) && input.PreviousKeyboardState.IsKeyUp(Keys.D5))
             * {
             *    tools = TEMP_Tools.PaintFace;
             * }
             * if (input.CurrentKeyboardState.IsKeyDown(Keys.D6) && input.PreviousKeyboardState.IsKeyUp(Keys.D6))
             * {
             *    tools = TEMP_Tools.PaintHalfFace;
             * }*/

            TEMP_MouseClick = null;

            TEMP_MouseClick = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y);

            if (camera != null && tools != TEMP_Tools.NULL)
            {
                TEMP_MouseRay = GetPointRay((Vector2)TEMP_MouseClick, camera);

                TEMP_selectedObject = VoxelRaycastUtility.GetNearestIntersectingWorldObject(TEMP_MouseRay);
            }


            switch (tools)
            {
            case TEMP_Tools.AddBlock:
            {
                if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.PreviousMouseState.LeftButton == ButtonState.Released)
                {
                    if (TEMP_selectedObject != null && TEMP_selectedObject is AbstractBlock)
                    {
                        BuildTools.AddBlock(TEMP_MouseRay, TEMP_selectedObject as AbstractBlock);
                    }
                }

                break;
            }

            case TEMP_Tools.RemoveBlock:
            {
                if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.PreviousMouseState.LeftButton == ButtonState.Released)
                {
                    if (TEMP_selectedObject != null && TEMP_selectedObject is AbstractBlock)
                    {
                        BuildTools.RemoveBlock(TEMP_selectedObject as AbstractBlock);
                    }
                }

                break;
            }

            case TEMP_Tools.AddWall:
            {
                if (input.CurrentMouseState.LeftButton == ButtonState.Pressed)
                {
                    BuildTools.AddWall((AbstractTerrainObject)TEMP_selectedObject, TEMP_MouseRay);
                }

                if (input.CurrentMouseState.LeftButton == ButtonState.Released)
                {
                    //Clear wall, build wall
                    BuildTools.BuildWalls_Released();
                }

                break;
            }

            case TEMP_Tools.RemoveWall:
            {
                if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.PreviousMouseState.LeftButton == ButtonState.Released)
                {
                    if (TEMP_selectedObject != null && TEMP_selectedObject is Wall)
                    {
                        BuildTools.RemoveWall(TEMP_selectedObject as Wall);
                    }
                }
                break;
            }

            case TEMP_Tools.PaintFace:
            {
                if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.PreviousMouseState.LeftButton == ButtonState.Released)
                {
                    BuildTools.PaintFullFace((AbstractTerrainObject)TEMP_selectedObject, TEMP_MouseRay);
                }
                break;
            }

            case TEMP_Tools.PaintHalfFace:
            {
                break;
            }
            }

            if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.PreviousMouseState.LeftButton == ButtonState.Released)
            {
                TEMP_selectedObjects = null;


                /*    TEMP_selectedObjects = VoxelRaycastUtility.VoxelIntersectionGrid(TEMP_MouseRay);
                 *
                 *  mouseRayLine = new List<VertexPositionColor>();
                 *  mouseRayLine.Add(new VertexPositionColor(TEMP_MouseRay.Position, Color.White));
                 *  mouseRayLine.Add(new VertexPositionColor(TEMP_MouseRay.Position + TEMP_MouseRay.Direction * 1000, Color.White));
                 *
                 */

                if (TEMP_selectedObject != null && TEMP_selectedObject is AbstractBlock)
                {
                    //   ((AbstractBlock)TEMP_selectedObject).OnHit();
                }
            }


            if (input.CurrentKeyboardState.IsKeyDown(Keys.Tab) && input.PreviousKeyboardState.IsKeyUp(Keys.Tab))
            {
                BuildTools.ToggleWallHeight();
            }

            if (input.CurrentMouseState.LeftButton == ButtonState.Released)
            {
            }

            if (input.CurrentMouseState.LeftButton == ButtonState.Pressed /*&& input.PreviousMouseState.LeftButton == ButtonState.Released*/)
            {
                /*  if(input.CurrentKeyboardState.IsKeyDown(Keys.LeftControl))
                 * {
                 *    TEMP_removeBlock=false;
                 * }
                 * else
                 * {
                 *    TEMP_removeBlock = true;
                 * }
                 *
                 * if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift))
                 * {
                 *    TEMP_ColourBlock = true;
                 * }
                 * else
                 * {
                 *    TEMP_ColourBlock = false;
                 * }*/



                if (camera != null)
                {
                    Ray     mouseRay = GetPointRay((Vector2)TEMP_MouseClick, camera);
                    Vector3 point    = GetWorldSpacePoint(new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y), camera);



                    Vector3 rotVec = position - point;
                    rotVec = new Vector3((float)Math.Round(rotVec.X, 2), (float)Math.Round(rotVec.Y, 2), (float)Math.Round(rotVec.Z, 2));
                    if (rotVec != Vector3.Zero)
                    {
                        rotVec.Normalize();
                    }

                    //Default rotation is along x axis
                    Vector3 defRotVec = new Vector3(1, 0, 0);


                    float dot = Vector3.Dot(rotVec, defRotVec);

                    int sign = 1;

                    //If angle is greater than 180 degrees (i.e. on the negative side of the default rotation vector), give it
                    //a negative angle
                    if (point.Z < position.Z)
                    {
                        sign = -1;
                    }

                    double angle = sign * Math.Acos(dot) * (180 / Math.PI);
                    rotation.Y = MathHelper.ToRadians((float)angle);
                }
            }

            /*   if (input.CurrentMouseState.MiddleButton == ButtonState.Pressed)
             * {
             *     ScreenManager.GetInstance().Game.IsMouseVisible = false;
             *     //Only record position on click
             *     if (input.PreviousMouseState.MiddleButton == ButtonState.Released)
             *     {
             *         TEMP_mouseClickPosition = new Vector2(input.CurrentMouseState.X, input.CurrentMouseState.Y);
             *     }
             *
             *     TEMP_mouseDelta = input.CurrentMouseState.X - TEMP_mouseClickPosition.X;
             *     RotateY(TEMP_mouseDelta);
             *     Mouse.SetPosition((int)TEMP_mouseClickPosition.X, (int)TEMP_mouseClickPosition.Y);
             * }
             * else
             * {
             *     ScreenManager.GetInstance().Game.IsMouseVisible = true;
             * }*/

            //    Vector3 positiveCameraDirection = cameraTarget - CameraPosition;
            velocity = Vector3.Zero;

            float slow = 1;

            if (input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift))
            {
                slow = 5;
            }
            else
            {
                slow = 1;
            }

            if (input.CurrentKeyboardState.IsKeyDown(Keys.W))
            {
                velocity.X -= moveSpeed / slow;
            }

            if (input.CurrentKeyboardState.IsKeyDown(Keys.D))
            {
                velocity.Z -= moveSpeed / slow;
            }
            if (input.CurrentKeyboardState.IsKeyDown(Keys.S))
            {
                velocity.X += moveSpeed / slow;
            }
            if (input.CurrentKeyboardState.IsKeyDown(Keys.A))
            {
                velocity.Z += moveSpeed / slow;
            }

            if (input.CurrentKeyboardState.IsKeyDown(Keys.Space) /* && input.PreviousKeyboardState.IsKeyUp(Keys.Space)*/)
            {
                //  if (OnGround)
                {
                    // position = new Vector3(0, 2, 0);
                    TEMP_velJump = 0.4f;
                    // velocity.Y = -4;
                }
            }
        }