关于Directinput的绝对坐标问题

来源:百度知道 编辑:UC知道 时间:2024/05/24 15:23:14
DX得到的是相对坐标,
g_xPos+=Mousestate.lX;
g_yPos+=Mousestate.lY;
这样转换有时候不灵....
那么,要判断某一帧中,Mouse是否移动到了一个物体上,除了每帧调用:
GetCursorPos,还有没有什么办法?
DX怎么得到准确的绝对坐标?要不然,Mousestate.lX和Mousestate.lY用处都不大了!!
难道就只能用GetCursorPos了???
这样子每帧中Dinput读到的值都没什么用啊???

用这种方式拾取。。

//-----------------------------------------------------------------------------
// Desc: 拾取三角形
//-----------------------------------------------------------------------------
HRESULT Pick_Triangle(IDirect3DDevice9* pd3dDevice, LPD3DXMESH pMesh)
{
HRESULT hr = S_OK;
g_dwNumIntersections = 0L;

if( !GetCapture() )
return hr;

//计算拾取射线相关变量声明
POINT ptCursor; //鼠标位置
D3DXMATRIX matWorld, matView, pmatProj, m;
D3DXVECTOR3 vPickRayOrig, vPickRayDir;
int iWidth, iHeight;

//获取后台缓冲区的宽度和高度
iWidth = DXUTGetBackBufferSurfaceDesc()->Width;
iHeight = DXUTGetBackBufferSurfaceDesc()->Height;

//获取当前鼠标在窗口客户区中的位置
GetCursorPos( &ptCursor );
ScreenToClient( DXUTGetHWND(), &ptCursor );

//获取当前设备的变换矩阵
pd3dDevice->GetTransform( D3DTS_WORLD, &matWorld );
pd3dDevice->GetTransform( D3DTS_VIEW, &matView );