小弟学到鼠标的拾取了,做了一个小东东,可它的拾取结果总是不正确的!搞了四五天了还搞它不定!下面是程序中的拾取片断,大版主帮我看看哪出了问题?
\ND3DXMATRIX m_ManTranslate;
char buffer[256];
HRESULT hr;
DIMOUSESTATE2 dims2; // DirectInput mouse state structure
POINT *pt=NULL; //用于获取鼠标位置
D3DXMATRIX m_ProjMatrix; //投影矩阵
D3DXMATRIX m_ViewMatrix; //观察矩阵
pt=new POINT;
\Ng_pd3dDevice->GetTransform (D3DTS_PROJECTION,&m_ProjMatrix); //获取投影矩阵;
\NGetCursorPos(pt);
ScreenToClient(hWnd,pt); //把相对于全屏幕的鼠标坐标转换成相对于本视窗的坐标
\ND3DXVECTOR3 m_viewPt;
D3DXVECTOR3 m_world;
D3DXVECTOR3 m_OriginWorld;
\Nm_viewPt.x=(2 * pt->x/m_d3dsdBackBuffer.Width -1)/m_ProjMatrix._11;
m_viewPt.y= -(2 * pt->y/m_d3dsdBackBuffer.Height -1)/m_ProjMatrix._22;
\Nm_viewPt.z=1;
g_pd3dDevice->GetTransform(D3DTS_VIEW,&m_ViewMatrix);
D3DXMatrixInverse(&m_ViewMatrix,NULL,&m_ViewMatrix);
m_world.x=m_viewPt.x * m_ViewMatrix._11 + m_viewPt.y * m_ViewMatrix._21 + m_viewPt.z * m_ViewMatrix._31;
m_world.y=m_viewPt.y * m_ViewMatrix._12 + m_viewPt.y * m_ViewMatrix._22 + m_viewPt.z * m_ViewMatrix._32;
m_world.z=m_viewPt.z * m_ViewMatrix._13 + m_viewPt.y * m_ViewMatrix._23 + m_viewPt.z * m_ViewMatrix._33;
// m_world.z=1.0f;
m_OriginWorld.x=m_ViewMatrix._41;
m_OriginWorld.y=m_ViewMatrix._42;
m_OriginWorld.z=m_ViewMatrix._43;
\NBOOL *pHit=NULL;
float *pU=NULL,*pV=NULL,*pDist=NULL;
LPD3DXBUFFER *ppAllHits=NULL;
DWORD *pCountofHits=0,*pFaceIndex=0;
pHit=new BOOL;
pU=new float;
pV=new float;
pDist=new float;
ppAllHits=new LPD3DXBUFFER;
\Nhr=D3DXIntersect(g_pTheMap->m_pMesh ,&m_OriginWorld,&m_world,pHit,pFaceIndex,pU,pV,pDist,ppAllHits,pCountofHits);
\N[align=right][color=#000066][此贴子已经被作者于2005-8-8 11:53:17编辑过][/color][/align]