I have a working 2D camera in XNA with these guts:
ms = Mouse.GetState(); msv = new Vector2(ms.X, ms.Y); //screenspace mouse vecor pos = new Vector2(0, 0); //camera center of view zoom_center = cursor; //I would like to be able to define the zoom center in world coords offset = new Vector2(scrnwidth / 2, scrnheight / 2); transmatrix = Matrix.CreateTranslation(-pos.X, -pos.Y, 0) * Matrix.CreateScale(scale, scale, 1) * Matrix.CreateTranslation(offset.X, offset.Y, 0); inverse = Matrix.Invert(transmatrix); cursor = Vector2.Transform(msv, inverse); //the mouse position in world coords
I can move the position of the camera and change the zoom level (with a different code, which I did not insert here for brevity). The camera always scales around the center of the screen, but I would like to be able to scale any arbitrary zoom point (cursor in this case), for example, indie game dyson http://www.youtube.com/watch?v=YiwjjCMqnpg&feature=player_detailpage#t= 144s
I tried all the combinations that make sense to me, but I'm completely stuck.
source share