|
|

楼主 |
发表于 2007-3-26 20:01:00
|
显示全部楼层
Re:如何将3D场景中鼠标位置转换为世界三维坐标 ?
POINT screenPt;
GetCursorPos(&screenPt);
ScreenToClient(m_App->GethWnd(),&screenPt);
D3DXVECTOR3 vecMouse=D3DXVECTOR3((float)screenPt.x,(float)screenPt.y,0.0f);
D3DXVECTOR3 dir=D3DXVECTOR3(0,0,1);
D3DXMATRIX matProj,matView,matWorld;
D3DXVECTOR3 mouseInworld,dirInworld;
m_App->m_Graphics.GetDeviceCOM()->GetTransform(D3DTS_VIEW,&matView);
m_App->m_Graphics.GetDeviceCOM()->GetTransform(D3DTS_WORLD,&matWorld);
m_App->m_Graphics.GetDeviceCOM()->GetTransform(D3DTS_PROJECTION,&matProj);
D3DXMATRIX m1,m2;
m1=matWorld*matView*matProj;
D3DXMatrixInverse(&m2,NULL,&m1);
D3DXVec3TransformCoord(&mouseInworld, &vecMouse, &m2);
D3DXVec3TransformNormal(&dirInworld, &dir, &m2); |
|