I have a problem with a camera class I got from the internet. It does a transformation like this:
public Matrix get_transformation(GraphicsDevice graphicsDevice)
{
_transform =
Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *
Matrix.CreateRotationZ(Rotation) *
Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) *
Matrix.CreateTranslation(new Vector3(ViewportWidth * 0.5f, ViewportHeight * 0.5f, 0));
return _transform;
}
Later the spritebatch is called like this:
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
null,
null,
null,
null,
cam.get_transformation(device));
The problem is that at this point the mouse coordinates are not relative anymore to the other sprites I draw. This is a problem because I try detect which sprite has been clicked. I understand that this issue can be solved by considering the following picture:
This was posted in a very good awnser before, here. But somehow this does not really help me. So my question is:
Is there a way to create a Camera class which does not use transformation, can be moved with keys and keeps the viewport coordinates relative?
Thanks in advance!