Original Post
Hi!
Well, I´m trying things out with Jim´s code and have run into another problem. I´m using the 3D-in-2D example and wanted to add a "picking the monster" task (with the mouse).
You should be able to click the monster-thing and something like a messagebox should tell the user that you´ve picked it (just for testing).
I just pushed everything in the "cApp::Frame()" part, just for testing.
When I click on monster-thing nothing happens; only a few inches in front of it (beeing towards the user) seems to work.
Well, I hope you can help me.
Michael
D3DXVECTOR3 vecRay, vecDir, vecTemp;
D3DXMATRIX matProj, matView, m;
float u,v;
BOOL Hit;
DWORD Face;
...
m_Graphics.GetDeviceCOM()->GetTransform(D3DTS_PROJECTION, &matProj);
m_Graphics.GetDeviceCOM()->GetTransform(D3DTS_VIEW, &matView);
D3DXMatrixInverse(&m, NULL, &matView);
m_Mouse.Read();
if (m_Mouse.GetButtonState(MOUSE_LBUTTON) == TRUE) {
vecTemp.x = (((2.0f * m_Mouse.GetXPos()) / m_Graphics.GetWidth())-1.0f) / matProj._11;
vecTemp.y = (((2.0f * m_Mouse.GetYPos()) / m_Graphics.GetHeight())-1.0f) / matProj._22;
vecTemp.z = 1.0f;
vecRay.x = m._41;
vecRay.y = m._42;
vecRay.z = m._43;
vecDir.x = vecTemp.x * m._11 +
vecTemp.y * m._21 +
vecTemp.z * m._31;
vecDir.y = vecTemp.x * m._12 +
vecTemp.y * m._22 +
vecTemp.z * m._32;
vecDir.z = vecTemp.x * m._13 +
vecTemp.y * m._23 +
vecTemp.z * m._33;
D3DXIntersect(m_Meshes.GetParentMesh()->m_Mesh, &vecRay, &vecDir, &Hit, &Face, &u, &v, &Dist,NULL,NULL);
if (Hit)
MessageBox(GethWnd(), "test", "Yes", MB_OK);
}