Dear Guys,
I use a Camera in my 2D XNA Game, and have really Problems to get the right Position of my Mouse Cursor you have maybe a Solution?
//Klassen Variablen
public Matrix transform;
Viewport view;
public Vector2 center;
//Eigenschaften
float _width { get; set; }
float _height { get; set; }
float _rotation { get; set; }
float _zoom { get; set; }
float _camSpeed { get; set; }
bool _follow { get; set; }
//Konstruktor
public Camera(Viewport newView)
{
view = newView;
_zoom = 1f;
_rotation = 0f;
center = new Vector2(0, 0);
_camSpeed = 5f;
_follow = true;
}
#region Kamera Kontrolle
//Camera Position Updaten
public void Update(IFocus focus)
{
if(_follow == true)
center = focus.getFocus();
_width = focus.getWidth() / 2;
_height = focus.getHeight() / 2;
transform = Matrix.CreateTranslation(new Vector3(-center.X - _width, -center.Y - _height, 0)) *
Matrix.CreateRotationZ(_rotation) *
Matrix.CreateScale(_zoom) *
Matrix.CreateTranslation(new Vector3(view.Width / 2, view.Height / 2, 0));
}
}
}
If i try to transform the MousePosition aswell, the Mouse is still a bit off the Center if im in negativ Values of the Screen.
mousePos = Vector2.Transform(mousePos, Matrix.Invert(cam.transform));
I cant do any precise shooting or anything else.
maybe you know a answer.
Greetings Move