こんにちは、ウィンドウ フォーカス (alt+tab / Windows キー) を失った後、マウス入力に小さな問題があります。
フォーカスがゲーム ウィンドウに戻った後、マウス (ヨー) の動作が遅くなり、応答しなくなります (ピッチは何らかの理由で正常に機能しています)。動く時もあるし、全く動かない時もある。
コードの一部を次に示します。
bool Game::initDirectInput(HINSTANCE hInstance)
{
hr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&directInput, NULL);
hr = directInput->CreateDevice(GUID_SysKeyboard, &DIKeyboard, NULL);
hr = directInput->CreateDevice(GUID_SysMouse, &DIMouse, NULL);
hr = DIKeyboard->SetDataFormat(&c_dfDIKeyboard);
hr = DIKeyboard->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
hr = DIMouse->SetDataFormat(&c_dfDIMouse2);
hr = DIMouse->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE | DISCL_NOWINKEY);
return true;
}
void Game::detectInput(double delta)
{
DIMOUSESTATE2 mouseCurrState;
BYTE keyboardState[256];
DIKeyboard->Acquire();
DIMouse->Acquire();
DIMouse->GetDeviceState(sizeof(DIMOUSESTATE2), &mouseCurrState);
DIKeyboard->GetDeviceState(sizeof(keyboardState),(LPVOID)&keyboardState);
camera.detectInput(delta, &keyboardState[0], &mouseCurrState);
}
void Camera::detectInput(double delta, BYTE *keyboardState, DIMOUSESTATE2 *mouseCurrState){
float speed = 16.0f * delta;
...
if((mouseCurrState->lX != mouseLastState.lX) || (mouseCurrState->lY != mouseLastState.lY))
{
camYaw += mouseCurrState->lX * 0.002f;
camPitch += mouseCurrState->lY * 0.002f;
if(camPitch > 0.85f)
camPitch = 0.85f;
if(camPitch < -0.85f)
camPitch = -0.85f;
mouseLastState = *mouseCurrState;
}
update();
return;
}
void Camera::update(){
camRotationMatrix = XMMatrixRotationRollPitchYaw(camPitch, camYaw, 0);
camTarget = XMVector3TransformCoord(DefaultForward, camRotationMatrix );
camTarget = XMVector3Normalize(camTarget);
XMMATRIX RotateYTempMatrix;
RotateYTempMatrix = XMMatrixRotationY(camYaw);
camRight = XMVector3TransformCoord(DefaultRight, RotateYTempMatrix);
camForward = XMVector3TransformCoord(DefaultForward, RotateYTempMatrix);
camUp = XMVector3Cross(camForward, camRight);
camPosition += moveLeftRight*camRight;
camPosition += moveBackForward*camForward;
camPosition += moveUpDown*DefaultUp;
moveLeftRight = 0.0f;
moveBackForward = 0.0f;
moveUpDown = 0.0f;
camTarget = camPosition + camTarget;
camView = XMMatrixLookAtLH( camPosition, camTarget, camUp );
}
疑問に思っている人のために、私はこのチュートリアルを使用して c++ と directx の学習を始めたばかりです: http://www.braynzarsoft.net/index.php?p=DX11Lessons (ただし、OpenGL + Java を使用した経験はかなりあります)。