[英]DirectX 11 2D Camera rotation
I'm trying to make a 2D game using DirectX 11 and I get distortion issues when I rotate the camera我正在尝试使用 DirectX 11 制作 2D 游戏,但在旋转相机时出现失真问题
By rotating the camera I mean rotating it about its Z axis with the X axis being left/right on the screen, the Y axis being up/down on the screen, and the Z axis protruding from the screen.通过旋转相机,我的意思是围绕它的 Z 轴旋转它,X 轴在屏幕上向左/向右,Y 轴在屏幕上向上/向下,Z 轴从屏幕上突出。 so when I rotate the camera, the rest of the world should appear to be orbiting around the center of the screen
所以当我旋转相机时,世界的其他地方应该看起来围绕着屏幕的中心旋转
Here I have a perfectly square sprite在这里,我有一个完美的方形精灵
and when I rotate the camera it becomes stretched当我旋转相机时,它会被拉伸
note this doesn't happen when I rotate the sprite itself, only the camera请注意,当我旋转精灵本身时,这不会发生,只有相机
my current setup with my camera is我目前使用相机的设置是
void Camera::SetOrthoMatrix(float width, float height, float nearZ, float farZ) //called when initializing the camera
{
orthoMatrix=XMMatrixOrthographicOffCenterLH(0.0f, width, 0.0f, height, nearZ, farZ);
}
void Camera::UpdateMatrix() //called whenever the camera's position or rotation changes
{
worldMatrix = XMMatrixTranslation(-pos.x, -pos.y, 0.0f) * XMMatrixRotationZ(rot);
}
XMMatrix Camera::GetViewMatrix()
{
return orthoMatrix * worldMatrix
}
My sprite class just takes it's own world matrix and multiplies it by camera.GetViewMatrix() and then I draw the sprite.我的精灵类只是将它自己的世界矩阵乘以 camera.GetViewMatrix() 然后我绘制精灵。 I'm fairly certain that the distortion is caused by the orthographic matrix, but I can't figure out a way to fix it.
我相当确定失真是由正交矩阵引起的,但我无法找到修复它的方法。
I figured it out by changing XMMatrixOrthographicOffCenterLH to XMMatrixOrthograpghicLH.我通过将 XMMatrixOrthographicOffCenterLH 更改为 XMMatrixOrthographhicLH 来解决这个问题。 then reordering the matrix multiplication from sprite, orthographic, camera to sprite, camera, orthographic.
然后将矩阵乘法从精灵、正交、相机重新排序为精灵、相机、正交。
this changes the coordinate system a little, before I had 0,0 be the bottom left corner of the screen but with XMMatrixOrthograpghicLH the origin is at the center of the screen.这会稍微改变坐标系,在我将 0,0 设置为屏幕的左下角之前,但使用 XMMatrixOrthograpghicLH 时,原点位于屏幕的中心。 It's not quite what I wanted but it's a minor inconvenience.
这不是我想要的,但这是一个小小的不便。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.