title: Mouse position to World Position. And Mouse position to Screen Re-scaled World Position
body: <p>So I am using a Camera(View Matrix) to move a tile world. <strong>In XNA(MONOGAME)</strong></p>
  
  <p>I am getting the raw mouse position with this code:</p>
  
  <pre><code>MouseState ms = Mouse.GetState();
  Vector2 mousePosition = new Vector2(ms.X, ms.Y);
  </code></pre>
  
  <p>Now If I divide the X by TILE_WIDTH and the Y by TILE_WIDTH it gives me the tile which I can grab out of my array. But once I move the matrix it offsets. How can I add the world offset to my mouse position?</p>
  
  <p>There is also another problem. When I re-size my window. The mouse will offset even more. Anyway of fixing this. So it will work in full-screen windowed in any resolution the mouse can convert to worldPosition?</p>
  
  <p><strong>My Render:</strong></p>
  
  <pre><code>spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, c2d.get_transformation(GraphicsDevice));
  spriteBatch.End();
  </code></pre>
  
  <p><strong>My view matrix:</strong></p>
  
  <pre><code>    public Matrix get_transformation(GraphicsDevice graphicsDevice)
      {
          _transform =       // Thanks to o KB o for this solution
            Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
                                       Matrix.CreateRotationZ(Rotation) *
                                       Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
                                       Matrix.CreateTranslation(new Vector3(graphicsDevice.Viewport.Width * 0.5f, 
                                       graphicsDevice.Viewport.Height * 0.5f, 0));
          return _transform;
      }
  </code></pre>
  
  <p><strong>My Way Of Getting The Tile:</strong></p>
  
  <pre><code> tile[(int)worldPosition.Y / TILE_SIZE, (int)worldPosition.X /  TILE_SIZE].color = Color.Red;
  </code></pre>
  
  <p><strong>Things I have Tried:</strong></p>
  
  <pre><code>Vector2 worldPosition = Vector2.Transform(mousePosition, Matrix.Invert(viewMatrix));
  </code></pre>
  
  <p>(<a href="https://gamedev.stackexchange.com/questions/21681/how-to-get-mouse-position-relative-to-the-map">https://gamedev.stackexchange.com/questions/21681/how-to-get-mouse-position-relative-to-the-map</a>)</p>
  
  <h1>TL;DR</h1>
  
  <p><strong>How do I get my mouse position in world view even if I re-size my window move my camera2D, Zoom, X,Y.</strong></p>