【发布时间】:2012-02-19 11:47:16
【问题描述】:
我在 XNA 中有一台工作正常的 2D 相机,具有以下功能:
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
我可以移动相机位置并更改缩放级别(为简洁起见,我没有在此处粘贴其他代码)。相机始终围绕屏幕中心进行缩放,但我希望能够围绕任意缩放点(在本例中为光标)进行缩放,例如独立游戏dyson http://www.youtube.com/watch?v=YiwjjCMqnpg&feature=player_detailpage#t=144s
我已经尝试了所有对我有意义的组合,但完全卡住了。
【问题讨论】: