Example #1
0
 public static Ray ConvertFrom(Microsoft.Xna.Framework.Ray value)
 {
     return(new Ray()
     {
         Position = ConvertFrom(value.Position),
         Direction = ConvertFrom(value.Direction)
     });
 }
        //Ray
        public static Ray Convert(Microsoft.Xna.Framework.Ray ray)
        {
            Ray toReturn;

            Convert(ref ray.Position, out toReturn.Position);
            Convert(ref ray.Direction, out toReturn.Direction);
            return(toReturn);
        }
Example #3
0
File: Ray.cs Project: Joelone/FFWD
 public Ray(Vector3 origin, Vector3 direction)
 {
     ray = new Microsoft.Xna.Framework.Ray();
     this.origin = origin;
     this.direction = direction;
 }
Example #4
0
        /// <summary>
        /// check for new updates
        /// </summary>
        public void Update()
        {
            // get the mousestate
            Microsoft.Xna.Framework.Input.MouseState ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
            this.lastKeyboardState = this.currentKeyboardState;
            this.currentKeyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            // get the movement and position

            this.mouseMovement = new Microsoft.Xna.Framework.Vector2((FenrirGame.Instance.Properties.ScreenWidth / 2 - ms.X), (FenrirGame.Instance.Properties.ScreenHeight / 2 - ms.Y));
            this.currentMousePosition -= mouseMovement * 1.05f;
            Microsoft.Xna.Framework.Input.Mouse.SetPosition(FenrirGame.Instance.Properties.ScreenWidth / 2, FenrirGame.Instance.Properties.ScreenHeight / 2);

            if (this.currentMousePosition.X < 0)
                this.currentMousePosition.X = 0;
            else if (this.currentMousePosition.X > FenrirGame.Instance.Properties.ScreenWidth)
                this.currentMousePosition.X = FenrirGame.Instance.Properties.ScreenWidth;

            if (this.currentMousePosition.Y < 0)
                this.currentMousePosition.Y = 0;
            else if (this.currentMousePosition.Y > FenrirGame.Instance.Properties.ScreenHeight)
                this.currentMousePosition.Y = FenrirGame.Instance.Properties.ScreenHeight;

            // get the scrollwheel
            this.scrollValue = scrollValueOld - ms.ScrollWheelValue;
            this.scrollValueOld = ms.ScrollWheelValue;

            // calculate boundingbox
            this.boundingBox.X = (int)FenrirGame.Instance.Properties.Input.CurrentMousePosition.X;
            this.boundingBox.Y = (int)FenrirGame.Instance.Properties.Input.CurrentMousePosition.Y;

            // buttonstates
            Boolean leftPressed = ms.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;
            Boolean rightPressed = ms.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;

            // reset click events
            this.releaseLeft = false;
            this.releaseRight = false;
            this.leftClick = false;
            this.rightClick = false;

            // check if dragging or clicked
            if (leftPressed)
            {
                if (!this.dragLeftStart.HasValue)
                    this.dragLeftStart = this.currentMousePosition;
                else if (!this.leftDrag && (Math.Abs(this.currentMousePosition.X - this.dragLeftStart.Value.X) > 5) || (Math.Abs(this.currentMousePosition.Y - this.dragLeftStart.Value.Y) > 5))
                    this.leftDrag = true;
            }
            else
            {
                if (this.dragLeftStart.HasValue)
                {
                    this.dragLeftStart = null;
                    this.leftDrag = false;
                    this.releaseLeft = true;

                    if (!this.leftDrag)
                        this.leftClick = true;
                }
            }

            if (rightPressed)
            {
                if (!this.dragRightStart.HasValue)
                    this.dragRightStart = this.currentMousePosition;
                else if (!this.rightDrag && (Math.Abs(this.currentMousePosition.X - this.dragRightStart.Value.X) > 5) || (Math.Abs(this.currentMousePosition.Y - this.dragRightStart.Value.Y) > 5))
                    this.rightDrag = true;
            }
            else
            {
                if (this.dragRightStart.HasValue)
                {
                    this.dragRightStart = null;
                    this.rightDrag = false;
                    this.releaseRight = true;

                    if (!this.rightDrag)
                        this.rightClick = true;
                }
            }

            // keaboard stuff
            this.moveCamLeft = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A);
            this.moveCamRight = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D);
            this.moveCamUp = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W);
            this.moveCamDown = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S);
            this.resetCamRot = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D0);

            if (currentKeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape) && !lastKeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape))
                this.endCurrentAction = true;
            else
                this.endCurrentAction = false;

            if (FenrirGame.Instance.Properties.CurrentGameState == GameState.InGame)
            {
                Microsoft.Xna.Framework.Vector3 nearsource = new Microsoft.Xna.Framework.Vector3(this.currentMousePosition.X, this.currentMousePosition.Y, 0f);
                Microsoft.Xna.Framework.Vector3 farsource = new Microsoft.Xna.Framework.Vector3(this.currentMousePosition.X, this.currentMousePosition.Y, 1f);

                Microsoft.Xna.Framework.Vector3 nearPoint = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    nearsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    FenrirGame.Instance.InGame.Camera.World);
                Microsoft.Xna.Framework.Vector3 farPoint = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    farsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    FenrirGame.Instance.InGame.Camera.World);

                Microsoft.Xna.Framework.Vector3 direction = farPoint - nearPoint;
                direction.Normalize();
                this.mouseRay = new Microsoft.Xna.Framework.Ray(nearPoint, direction);

                this.currentMousePositionInWorld = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    nearsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    Microsoft.Xna.Framework.Matrix.Identity
                    );
            }
        }
 public static SlimDX.Ray dx(this Microsoft.Xna.Framework.Ray v)
 {
     return(new SlimDX.Ray(v.Position.dx(), v.Direction.dx()));
 }
 public void FindAll(ref Microsoft.Xna.Framework.Ray ray, ICollection <ISpatialQueryable> result)
 {
     throw new NotImplementedException();
 }
Example #7
0
        /// <summary>
        /// check for new updates
        /// </summary>
        public void Update()
        {
            // get the mousestate
            Microsoft.Xna.Framework.Input.MouseState ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
            this.lastKeyboardState    = this.currentKeyboardState;
            this.currentKeyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            // get the movement and position

            this.mouseMovement         = new Microsoft.Xna.Framework.Vector2((FenrirGame.Instance.Properties.ScreenWidth / 2 - ms.X), (FenrirGame.Instance.Properties.ScreenHeight / 2 - ms.Y));
            this.currentMousePosition -= mouseMovement * 1.05f;
            Microsoft.Xna.Framework.Input.Mouse.SetPosition(FenrirGame.Instance.Properties.ScreenWidth / 2, FenrirGame.Instance.Properties.ScreenHeight / 2);

            if (this.currentMousePosition.X < 0)
            {
                this.currentMousePosition.X = 0;
            }
            else if (this.currentMousePosition.X > FenrirGame.Instance.Properties.ScreenWidth)
            {
                this.currentMousePosition.X = FenrirGame.Instance.Properties.ScreenWidth;
            }

            if (this.currentMousePosition.Y < 0)
            {
                this.currentMousePosition.Y = 0;
            }
            else if (this.currentMousePosition.Y > FenrirGame.Instance.Properties.ScreenHeight)
            {
                this.currentMousePosition.Y = FenrirGame.Instance.Properties.ScreenHeight;
            }

            // get the scrollwheel
            this.scrollValue    = scrollValueOld - ms.ScrollWheelValue;
            this.scrollValueOld = ms.ScrollWheelValue;

            // calculate boundingbox
            this.boundingBox.X = (int)FenrirGame.Instance.Properties.Input.CurrentMousePosition.X;
            this.boundingBox.Y = (int)FenrirGame.Instance.Properties.Input.CurrentMousePosition.Y;

            // buttonstates
            Boolean leftPressed  = ms.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;
            Boolean rightPressed = ms.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;

            // reset click events
            this.releaseLeft  = false;
            this.releaseRight = false;
            this.leftClick    = false;
            this.rightClick   = false;

            // check if dragging or clicked
            if (leftPressed)
            {
                if (!this.dragLeftStart.HasValue)
                {
                    this.dragLeftStart = this.currentMousePosition;
                }
                else if (!this.leftDrag && (Math.Abs(this.currentMousePosition.X - this.dragLeftStart.Value.X) > 5) || (Math.Abs(this.currentMousePosition.Y - this.dragLeftStart.Value.Y) > 5))
                {
                    this.leftDrag = true;
                }
            }
            else
            {
                if (this.dragLeftStart.HasValue)
                {
                    this.dragLeftStart = null;
                    this.leftDrag      = false;
                    this.releaseLeft   = true;

                    if (!this.leftDrag)
                    {
                        this.leftClick = true;
                    }
                }
            }

            if (rightPressed)
            {
                if (!this.dragRightStart.HasValue)
                {
                    this.dragRightStart = this.currentMousePosition;
                }
                else if (!this.rightDrag && (Math.Abs(this.currentMousePosition.X - this.dragRightStart.Value.X) > 5) || (Math.Abs(this.currentMousePosition.Y - this.dragRightStart.Value.Y) > 5))
                {
                    this.rightDrag = true;
                }
            }
            else
            {
                if (this.dragRightStart.HasValue)
                {
                    this.dragRightStart = null;
                    this.rightDrag      = false;
                    this.releaseRight   = true;

                    if (!this.rightDrag)
                    {
                        this.rightClick = true;
                    }
                }
            }

            // keaboard stuff
            this.moveCamLeft  = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A);
            this.moveCamRight = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D);
            this.moveCamUp    = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W);
            this.moveCamDown  = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S);
            this.resetCamRot  = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D0);

            if (currentKeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape) && !lastKeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                this.endCurrentAction = true;
            }
            else
            {
                this.endCurrentAction = false;
            }

            if (FenrirGame.Instance.Properties.CurrentGameState == GameState.InGame)
            {
                Microsoft.Xna.Framework.Vector3 nearsource = new Microsoft.Xna.Framework.Vector3(this.currentMousePosition.X, this.currentMousePosition.Y, 0f);
                Microsoft.Xna.Framework.Vector3 farsource  = new Microsoft.Xna.Framework.Vector3(this.currentMousePosition.X, this.currentMousePosition.Y, 1f);

                Microsoft.Xna.Framework.Vector3 nearPoint = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    nearsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    FenrirGame.Instance.InGame.Camera.World);
                Microsoft.Xna.Framework.Vector3 farPoint = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    farsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    FenrirGame.Instance.InGame.Camera.World);

                Microsoft.Xna.Framework.Vector3 direction = farPoint - nearPoint;
                direction.Normalize();
                this.mouseRay = new Microsoft.Xna.Framework.Ray(nearPoint, direction);

                this.currentMousePositionInWorld = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    nearsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    Microsoft.Xna.Framework.Matrix.Identity
                    );
            }
        }
 public static void Convert(ref Ray ray, out Microsoft.Xna.Framework.Ray xnaRay)
 {
     Convert(ref ray.Position, out xnaRay.Position);
     Convert(ref ray.Direction, out xnaRay.Direction);
 }
 public static void Convert(ref Microsoft.Xna.Framework.Ray ray, out Ray bepuRay)
 {
     Convert(ref ray.Position, out bepuRay.Position);
     Convert(ref ray.Direction, out bepuRay.Direction);
 }
Example #10
0
 public Ray(Vector3 origin, Vector3 direction)
 {
     ray            = new Microsoft.Xna.Framework.Ray();
     this.origin    = origin;
     this.direction = direction;
 }