Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---
- public Rectangle CalculateRenderTargetPosition()
- {
- Rectangle rec = new Rectangle(0, 0, 0, 0);
- Single preferredAspect = Globals.RenderSize.Width / (Single)Globals.RenderSize.Height;
- Single outputAspect = Globals.WindowSize.Width / (Single)Globals.WindowSize.Height;
- if (outputAspect <= preferredAspect)
- {
- // output is taller than it is wider, bars on top/bottom
- Int32 presentHeight = (Int32)((Globals.WindowSize.Width / preferredAspect) + 0.5f);
- Int32 barHeight = (Globals.WindowSize.Height - presentHeight) / 2;
- rec = new Rectangle(0, barHeight, Globals.WindowSize.Width, presentHeight);
- }
- else
- {
- // output is wider than it is tall, bars left/right
- Int32 presentWidth = (Int32)((Globals.WindowSize.Height * preferredAspect) + 0.5f);
- Int32 barWidth = (Globals.WindowSize.Width - presentWidth) / 2;
- rec = new Rectangle(barWidth, 0, presentWidth, Globals.WindowSize.Height);
- }
- return rec;
- }
- //---
- private void CalculateMousePosition()
- {
- //using same mouse code from http://www.david-gouveia.com/portfolio/2d-camera-with-parallax-scrolling-in-xna/
- Matrix cam = Globals.Camera.GetViewMatrix();
- MouseState ms = Mouse.GetState();
- Vector2 pos = new Vector2(0,0);
- if (Globals.WindowSize > Globals.RenderSize)
- {
- Rectangle r = Globals.Draw.CalculateRenderTargetPosition();
- Single aspect = Globals.WindowSize.Width / (Single)Globals.WindowSize.Height;
- pos = Vector2.Transform(new Vector2(
- (ms.X - r.X) / aspect,
- (ms.Y - r.Y) / aspect),
- Matrix.Invert(cam));
- }
- else if (Globals.WindowSize == Globals.RenderSize)
- {
- pos = Vector2.Transform(new Vector2(ms.X, ms.Y, Matrix.Invert(cam));
- }
- this.MousePosition = pos;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement