protected override void OnResize(EventArgs e)
        {
            var manager = game.Services.GetService(typeof(IGraphicsDeviceManager)) as GraphicsDeviceManager;

            if (game._initialized)
            {
                manager.OnDeviceResetting(EventArgs.Empty);
            }

            Microsoft.Xna.Framework.Graphics.Viewport _vp =
                new Microsoft.Xna.Framework.Graphics.Viewport();

            _vp.X      = (int)Bounds.X;
            _vp.Y      = (int)Bounds.Y;
            _vp.Width  = (int)Bounds.Width;
            _vp.Height = (int)Bounds.Height;

            game.GraphicsDevice.Viewport = _vp;

            clientBounds = new Rectangle((int)Bounds.X, (int)Bounds.Y, (int)Bounds.Width, (int)Bounds.Height);

            base.OnResize(e);
            OnClientSizeChanged(e);

            if (game._initialized)
            {
                manager.OnDeviceReset(EventArgs.Empty);
            }
        }
Exemple #2
0
 private static bool CanInitializeView(Map map, Microsoft.Xna.Framework.Graphics.Viewport xnaViewport)
 {
     if (xnaViewport.Width == 0)
     {
         return(false);
     }
     if (xnaViewport.Height == 0)
     {
         return(false);
     }
     if (map == null)
     {
         return(false);
     }
     if (map.Envelope == null)
     {
         return(false);
     }
     if (map.Envelope.Width.IsNanOrZero())
     {
         return(false);
     }
     if (map.Envelope.Height.IsNanOrZero())
     {
         return(false);
     }
     if (map.Envelope.GetCentroid() == null)
     {
         return(false);
     }
     return(true);
 }
Exemple #3
0
//		protected override void OnUpdateFrame (FrameEventArgs e)
//		{
//			base.OnUpdateFrame (e);
//
//		}
        protected override void OnResize(EventArgs e)
        {
            var manager = (GraphicsDeviceManager)_game.Services.GetService(typeof(IGraphicsDeviceManager));

            if (_game.Initialized)
            {
                manager.OnDeviceResetting(EventArgs.Empty);

                Microsoft.Xna.Framework.Graphics.Viewport _vp =
                    new Microsoft.Xna.Framework.Graphics.Viewport();

                _game.GraphicsDevice.PresentationParameters.BackBufferWidth  = (int)Bounds.Width;
                _game.GraphicsDevice.PresentationParameters.BackBufferHeight = (int)Bounds.Height;

                _vp.X      = (int)Bounds.X;
                _vp.Y      = (int)Bounds.Y;
                _vp.Width  = (int)Bounds.Width;
                _vp.Height = (int)Bounds.Height;

                _game.GraphicsDevice.Viewport = _vp;
            }

            clientBounds = new Rectangle((int)Bounds.X, (int)Bounds.Y, (int)Bounds.Width, (int)Bounds.Height);

            base.OnResize(e);
            OnClientSizeChanged(e);

            if (_game.Initialized)
            {
                manager.OnDeviceReset(EventArgs.Empty);
            }
        }
        /// <summary>
        /// Transform a screen position to a world position at a given depth, using the pass defined by PassID
        /// </summary>
        /// <param name="screenPos"></param>
        /// <param name="depth"></param>
        /// <param name="PassID"></param>
        /// <returns></returns>
        public static Vector3 ScreenToWorld(Vector2 screenPos, float depth, String PassID = "Unsorted")
        {
            // Grab the viewport and transformer.  Used the built in viewport unprojection to get the
            // coordinates.
            Microsoft.Xna.Framework.Graphics.Viewport vp = XNAGame.Instance.GraphicsDevice.Viewport;
            ITransformer trans = XNAGame.Instance.GetBroadphase <Broadphases.Graphics>("Graphics").GetTransformer(PassID);

            // This finds the point on the near plane.
            Vector3 v;

            v.X = (((2.0f * screenPos.X) / vp.Width) - 1) * (float)Math.Tan(MathHelper.ToRadians(20.0f));
            v.Y = -(((2.0f * screenPos.Y) / vp.Height) - 1) * (float)Math.Tan(MathHelper.ToRadians(20.0f));
            v.Z = -1.0f;

            // And it scales perfectly up to the point in space.
            // This position is relative to the camera XY on the plane requested, so we
            // need to add the camera position to that offset.
            // NOTE: THIS ONLY WORKS BECAUSE WE'RE 100% TOP DOWN.
            v   *= trans.Position.Z - depth;
            v.X *= vp.Width / 2;
            v.Y *= -vp.Height / 2;
            Vector3 result = trans.Position + v;

            return(result);
        }
Exemple #5
0
        public override void Update(Microsoft.Xna.Framework.GameTime gametime, Microsoft.Xna.Framework.Graphics.Viewport viewport)
        {
            _position.X += xspeed;
            _position.Y += yspeed;


            if (_position.X + _texture.Width > viewport.Width || _position.X < 0)
            {
                xspeed *= -1;
            }

            base.Update(gametime, viewport);
        }
Exemple #6
0
        public static Vector3 ProjectMousePosition(Vector2 mousePos, Microsoft.Xna.Framework.Graphics.Viewport viewport, Matrix world, Matrix view, Matrix projection, float depth)
        {
            Vector3 nearSource = new Vector3(mousePos.X, mousePos.Y, 0);
            Vector3 farSource  = new Vector3(mousePos.X, mousePos.Y, 1);

            Vector3 nearPoint = viewport.Unproject(nearSource, projection, view, world);
            Vector3 farPoint  = viewport.Unproject(farSource, projection, view, world);

            Ray   ray   = new Ray(nearPoint, Vector3.Normalize(farPoint - nearPoint));
            Plane plane = new Plane(new Vector3(0, 0, -1), depth);

            float denominator = Vector3.Dot(plane.Normal, ray.Direction);
            float numerator   = Vector3.Dot(plane.Normal, ray.Position) + plane.D;
            float t           = -(numerator / denominator);

            return(nearPoint + ray.Direction * t);
        }
Exemple #7
0
 public override void Apply(RenderTargetI renderTarget)
 {
     #if SILVERLIGHT
     try {
     #endif
     var viewPort = new Microsoft.Xna.Framework.Graphics.Viewport()
     {
         X = Position.X,
         Y = renderTarget.Size.Height - Size.Height - Position.Y,
         Width = Size.Width,
         Height = Size.Height,
         MinDepth = 0,
         MaxDepth = 1
     };
     video.Device.Viewport = viewPort;
     #if SILVERLIGHT
     } catch {}
     #endif
 }
Exemple #8
0
 public override void Apply()
 {
     #if SILVERLIGHT
     try {
     #endif
     var viewPort = new Microsoft.Xna.Framework.Graphics.Viewport()
     {
         X = Position.X,
         Y = video.Device.PresentationParameters.BackBufferHeight - Size.Height - Position.Y,
         Width = Size.Width,
         Height = Size.Height,
         MinDepth = 0,
         MaxDepth = 1
     };
     video.Device.Viewport = viewPort;
     #if SILVERLIGHT
     } catch {}
     #endif
 }
Exemple #9
0
        public override void Apply(RenderTargetI renderTarget)
        {
                        #if SILVERLIGHT
            try {
                        #endif
            var viewPort = new Microsoft.Xna.Framework.Graphics.Viewport()
            {
                X        = Position.X,
                Y        = renderTarget.Size.Height - Size.Height - Position.Y,
                Width    = Size.Width,
                Height   = Size.Height,
                MinDepth = 0,
                MaxDepth = 1
            };
            video.Device.Viewport = viewPort;
                        #if SILVERLIGHT
        }

        catch {}
                        #endif
        }
Exemple #10
0
        public override void Apply()
        {
                        #if SILVERLIGHT
            try {
                        #endif
            var viewPort = new Microsoft.Xna.Framework.Graphics.Viewport()
            {
                X        = Position.X,
                Y        = video.Device.PresentationParameters.BackBufferHeight - Size.Height - Position.Y,
                Width    = Size.Width,
                Height   = Size.Height,
                MinDepth = 0,
                MaxDepth = 1
            };
            video.Device.Viewport = viewPort;
                        #if SILVERLIGHT
        }

        catch {}
                        #endif
        }
Exemple #11
0
//		protected override void OnUpdateFrame (FrameEventArgs e)
//		{
//			base.OnUpdateFrame (e);
//
//			if (_game != null) {
//				Console.WriteLine("Update");
//				if (_isFirstTime) {
//					// Initialize GameTime
//					_updateGameTime = new GameTime ();
//					_drawGameTime = new GameTime ();
//					_lastUpdate = DateTime.Now;
//					_now = DateTime.Now;
//				}
//				else {
//					_now = DateTime.Now;
//					_updateGameTime.Update (_now - _lastUpdate);
//					if (_needsToResetElapsedTime) {
//						_updateGameTime.ResetElapsedTime();
//						_drawGameTime.ResetElapsedTime();
//						_needsToResetElapsedTime = false;
//					}
//				}
//				_isFirstTime = false;
//				_game.DoUpdate (_updateGameTime);
//			}
//		}
		protected override void OnResize (EventArgs e)
		{
            var manager = (GraphicsDeviceManager)_game.Services.GetService(typeof(IGraphicsDeviceManager));
            if (_game.Initialized)
            {
    			manager.OnDeviceResetting(EventArgs.Empty);
    			
    			Microsoft.Xna.Framework.Graphics.Viewport _vp =
    			new Microsoft.Xna.Framework.Graphics.Viewport();
    				
    			_vp.X = (int)Bounds.X;
    			_vp.Y = (int)Bounds.Y;
    			_vp.Width = (int)Bounds.Width;
    			_vp.Height = (int)Bounds.Height;

    			_game.GraphicsDevice.Viewport = _vp;
            }
			
			clientBounds = new Rectangle((int)Bounds.X,(int)Bounds.Y,(int)Bounds.Width,(int)Bounds.Height);
			
			base.OnResize(e);
			OnClientSizeChanged(e);

            if (_game.Initialized)
    			manager.OnDeviceReset(EventArgs.Empty);
		}
Exemple #12
0
        public void UnprojectTest1()
        {
            Vector3 vector = Utilities.GenerateVector3();
            Vector3 vectorExpected = vector;
            float x = (float)Math.Floor(Utilities.GenerateFloat());
            float y = (float)Math.Floor(Utilities.GenerateFloat());
            float width = (float)Math.Floor(Utilities.GenerateFloat() + x);
            float height = (float)Math.Floor(Utilities.GenerateFloat() + y);
            float minZ = Utilities.GenerateFloat();
            float maxZ = Utilities.GenerateFloat() + minZ + 1f;
            Matrix worldViewProjection = Utilities.GenerateMatrix();
            Matrix worldViewProjectionExpected = worldViewProjection;
            Vector3 result;

            Microsoft.Xna.Framework.Graphics.Viewport viewport = new Microsoft.Xna.Framework.Graphics.Viewport()
            {
                X = (int)x,
                Y = (int)y,
                Width = (int)width,
                Height = (int)height,
                MinDepth = minZ,
                MaxDepth = maxZ
            };
            Vector3 resultExpected = Utilities.ConvertFrom(viewport.Unproject(
                Utilities.ConvertToXna(vector),
                Utilities.ConvertToXna(worldViewProjection),
                Utilities.ConvertToXna(Matrix.Identity),
                Utilities.ConvertToXna(Matrix.Identity)));

            Vector3.Unproject(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out result);
            Utilities.AreEqual(vectorExpected, vector);
            Utilities.AreEqual(worldViewProjectionExpected, worldViewProjection);
            Utilities.AreEqual(resultExpected, result);
        }
Exemple #13
0
        public void ProjectTest()
        {
            Vector3 vector = Utilities.GenerateVector3();
            float x = (float)Math.Floor(Utilities.GenerateFloat());
            float y = (float)Math.Floor(Utilities.GenerateFloat());
            float width = (float)Math.Floor(Utilities.GenerateFloat() + x);
            float height = (float)Math.Floor(Utilities.GenerateFloat() + y);
            float minZ = Utilities.GenerateFloat();
            float maxZ = Utilities.GenerateFloat() + minZ + 1f;
            Matrix worldViewProjection = Utilities.GenerateMatrix();

            Microsoft.Xna.Framework.Graphics.Viewport viewport = new Microsoft.Xna.Framework.Graphics.Viewport()
            {
                X = (int)x,
                Y = (int)y,
                Width = (int)width,
                Height = (int)height,
                MinDepth = minZ,
                MaxDepth = maxZ
            };
            Vector3 expected = Utilities.ConvertFrom(viewport.Project(
                Utilities.ConvertToXna(vector),
                Utilities.ConvertToXna(worldViewProjection),
                Utilities.ConvertToXna(Matrix.Identity),
                Utilities.ConvertToXna(Matrix.Identity)));

            Vector3 actual;
            actual = Vector3.Project(vector, x, y, width, height, minZ, maxZ, worldViewProjection);
            Utilities.AreEqual(expected, actual);
        }