[SOLVED] How can I get the world coords of the mouse (2D).

It is somewhat odd that you would ask what these matrixs are and also need to have a world position for the mouse. Out of curiosity can i ask what this is for ?

Anyways to be as succinct as possible.

If you are only using spritebatch and passing it a BasicEffect basicEffect then these matrices are basicEffect.World
basicEffect.View
basicEffect.Projection;

If you are not passing a basic effect to spritebatch and using it as is then you don’t even need the above functions and can directly caluculate world coordinates by linear math.

pesudo code.

`Vector2 worldpos = ((mousepos / GraphicsDevice.Viewport.Bounds.Size ) * 2)-Vector2.One;`

Edit.
If you want to create your own basic Effect that matches spritebatch and then pass that to spriteBatch.Begin You can see the equivalent matrices and how to make them and pass them to spritebatch begin, in the below post were i put a full example that can be copy pasted.

This also includes a second example of how to make your own custom effect that matches spritebatch matrice setup.

Edit sorry that might not be the best example. If you look at set states it shows how to set up a basic effect though in the actual draw using spritebatch you add the basic effect to begin.

    spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, RasterizerState.CullNone, basicEffect, null);

    spriteBatch.Draw(generatedTexture, new Rectangle(000, 000, 200, 200), Color.Beige);
    spriteBatch.Draw(generatedTexture, new Rectangle(100, 100, 200, 200), Color.Green);

    spriteBatch.End();