Posted on 2010-12-15 15:29
点点滴滴 阅读(314)
评论(0) 编辑 收藏 引用 所属分类:
08 游戏SDK
1.当窗口最小化后,单击只有按下无弹起事件
void MouseDeviceOgreOIS::poll()
{
if (mMouse)
{
mMouse->capture();
OIS::MouseState& state = mMouse->getMouseState();
//设置鼠标无法改变OIS底层GetDeviceData的数据,造成bug,需要解决。
POINT point;
GetCursorPos(&point);
ScreenToClient((HWND)mWhd, &point);
Vector3 pos(point.x * 1.0f, point.y * 1.0f, 0.0f);
mPosition.x = state.X.abs * 1.0f;
mPosition.y = state.Y.abs * 1.0f;
mPosition.z = state.Z.abs * 1.0f;
if ((mPosition.x != pos.x) || (mPosition.y != pos.y))
{
mPosition.x = pos.x;
mPosition.y = pos.y;
}
if (!mActualClip.contains(mPosition))//修改OISBug,当在最小化后,单击只有按下无弹起事件。
{
if(mButtons[MBT_LEFT])
mButtons[MBT_LEFT] = state.buttonDown(OIS::MB_Left);
else
state.buttons &= ~(1 << OIS::MB_Left); //turn the bit flag off
if(mButtons[MBT_RIGHT])
mButtons[MBT_RIGHT] = state.buttonDown(OIS::MB_Right);
else
state.buttons &= ~(1 << OIS::MB_Right); //turn the bit flag off
if(mButtons[MBT_MIDDLE])
mButtons[MBT_MIDDLE] = state.buttonDown(OIS::MB_Middle);
else
state.buttons &= ~(1 << OIS::MB_Middle); //turn the bit flag off
return;
}
mButtons[MBT_LEFT] = state.buttonDown(OIS::MB_Left);
mButtons[MBT_RIGHT] = state.buttonDown(OIS::MB_Right);
mButtons[MBT_MIDDLE] = state.buttonDown(OIS::MB_Middle);
}
}
2.使用SetCursorPos后,无移动鼠标,OIS无法取得鼠标移动信息
void Win32Mouse::capture()
{
//Clear old relative values
mState.X.rel = mState.Y.rel = mState.Z.rel = 0;
DIDEVICEOBJECTDATA diBuff[MOUSE_DX_BUFFERSIZE];
DWORD entries = MOUSE_DX_BUFFERSIZE;
HRESULT hr = mMouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 );
if( hr != DI_OK )
{
hr = mMouse->Acquire();
while( hr == DIERR_INPUTLOST )
hr = mMouse->Acquire();
hr = mMouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 );
//Perhaps the user just tabbed away, and coop settings
//are nonexclusive..so just ignore
if( FAILED(hr) )
return;
}
bool axesMoved = false;
//Accumulate all axis movements for one axesMove message..
//Buttons are fired off as they are found
for(unsigned int i = 0; i < entries; ++i )
{
switch( diBuff[i].dwOfs )
{
case DIMOFS_BUTTON0:
if(!_doMouseClick(0, diBuff[i])) return;
break;
case DIMOFS_BUTTON1:
if(!_doMouseClick(1, diBuff[i])) return;
break;
case DIMOFS_BUTTON2:
if(!_doMouseClick(2, diBuff[i])) return;
break;
case DIMOFS_BUTTON3:
if(!_doMouseClick(3, diBuff[i])) return;
break;
case DIMOFS_BUTTON4:
if(!_doMouseClick(4, diBuff[i])) return;
break;
case DIMOFS_BUTTON5:
if(!_doMouseClick(5, diBuff[i])) return;
break;
case DIMOFS_BUTTON6:
if(!_doMouseClick(6, diBuff[i])) return;
break;
case DIMOFS_BUTTON7:
if(!_doMouseClick(7, diBuff[i])) return;
break;
case DIMOFS_X:
mState.X.rel += diBuff[i].dwData;
axesMoved = true;
break;
case DIMOFS_Y:
mState.Y.rel += diBuff[i].dwData;
axesMoved = true;
break;
case DIMOFS_Z:
mState.Z.rel += diBuff[i].dwData;
axesMoved = true;
break;
default: break;
} //end switch
}//end for
if( axesMoved )// 有偏移信息才会设置鼠标位置
{
if( coopSetting & DISCL_NONEXCLUSIVE )
{
//DirectInput provides us with meaningless values, so correct that
POINT point;
GetCursorPos(&point);
ScreenToClient(mHwnd, &point);
mState.X.abs = point.x;
mState.Y.abs = point.y;
}
else
{
mState.X.abs += mState.X.rel;
mState.Y.abs += mState.Y.rel;
}
mState.Z.abs += mState.Z.rel;
//Clip values to window
if( mState.X.abs < 0 )
mState.X.abs = 0;
else if( mState.X.abs > mState.width )
mState.X.abs = mState.width;
if( mState.Y.abs < 0 )
mState.Y.abs = 0;
else if( mState.Y.abs > mState.height )
mState.Y.abs = mState.height;
//Do the move
if( mListener && mBuffered )
mListener->mouseMoved( MouseEvent( this, mState ) );
}
}