我在DirectX中有一个3D程序,我想让鼠标控制到相机。问题是鼠标从屏幕上移开(在窗口模式下),然后相机不再转动。我试图使用SetCusorPos将鼠标移动后锁定到位。这样我就可以得到一个dx,然后将鼠标设置回屏幕的中心。我最终得到了一个无尽的白色屏幕。这是我到目前为止的相机/鼠标移动代码。如果您需要更多信息,请询问。
void PhysicsApp::OnMouseMove(WPARAM btnState, int x, int y)
{
// Make each pixel correspond to a quarter of a degree.
float dx = XMConvertToRadians(0.25f*static_cast<float>(x - mLastMousePos.x));
float dy = XMConvertToRadians(0.25f*static_cast<float>(y - mLastMousePos.y));
// Update angles based on input to orbit camera around box.
mTheta += -dx;
mPhi += -dy;
// Update players direction to always face forward
playerRotation.y = -mTheta;
// Restrict the angle mPhi.
mPhi = MathHelper::Clamp(mPhi, 0.1f, MathHelper::Pi-0.1f);
if( (btnState & MK_RBUTTON) != 0 )
{
// Make each pixel correspond to 0.2 unit in the scene.
float dx = 0.05f*static_cast<float>(x - mLastMousePos.x);
float dy = 0.05f*static_cast<float>(y - mLastMousePos.y);
// Update the camera radius based on input.
mRadius += dx - dy;
// Restrict the radius.
mRadius = MathHelper::Clamp(mRadius, 5.0f, 50.0f);
}
mLastMousePos.x = x;
mLastMousePos.y = y;
}