Also falls jemand im code gerade einen fehler erkennt:
D3DXMATRIXA16 matProj;
m_pd3dDevice->GetTransform( D3DTS_PROJECTION, &matProj );
// Get mouse position in screen coordinates [0... Width/Height]
POINT ptCursor;
GetCursorPos( &ptCursor );
ScreenToClient( m_hWnd, &ptCursor );
RECT rect;
GetClientRect(this->m_hWnd, &rect);
// Transform to normalized coordinates [-1....1]
D3DXVECTOR3 v;
//v.x = ( ( ( 2.0f * ptCursor.x ) / m_d3dsdBackBuffer.Width ) - 1 ) / matProj._11;
//v.y = -( ( ( 2.0f * ptCursor.y ) / m_d3dsdBackBuffer.Height ) - 1 ) / matProj._22;
v.x = ( ( ( 2.0f * ptCursor.x ) / (rect.right-rect.left) ) - 1 ) / matProj._11;
v.y = -( ( ( 2.0f * ptCursor.y ) / (rect.bottom - rect.top) ) - 1 ) / matProj._22;
v.z = 1.0f;
// Get the inverse view matrix
D3DXMATRIXA16 matView, m;
m_pd3dDevice->GetTransform( D3DTS_VIEW, &matView );
D3DXMatrixInverse( &m, NULL, &matView );
// Transform the screen space pick ray into 3D space
vPickRayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31;
vPickRayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32;
vPickRayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33;
//D3DXVec3Normalize(&vPickRayDir,&vPickRayDir);
vPickRayOrig.x = m._41;
vPickRayOrig.y = m._42;
vPickRayOrig.z = m._43;
/*
* Determine intersection of the ray with the mesh
*/
D3DXMATRIX worldMatrix;
m_pd3dDevice->GetTransform(D3DTS_WORLD, &worldMatrix );
D3DXVECTOR3 vNear,vDir;
D3DXMATRIX invMat;
D3DXMatrixInverse(&invMat,NULL,&worldMatrix);
D3DXVec3TransformCoord(&vNear,&vPickRayOrig,&invMat);
D3DXVec3TransformNormal(&vDir,&vPickRayDir,&invMat);
// Get the picked triangle
LPD3DXBASEMESH pMesh = m_MeshModel.GetMesh();//m_pObject->GetLocalMesh();
LPDIRECT3DVERTEXBUFFER9 pVB;
LPDIRECT3DINDEXBUFFER9 pIB;
pMesh->GetVertexBuffer( &pVB );
pMesh->GetIndexBuffer( &pIB );
WORD* pIndices;
CUSTOMVERTEX* pVertices;
pIB->Lock( 0, 0, (void**)&pIndices, 0 );
pVB->Lock( 0, 0, (void**)&pVertices, 0 );
DWORD dwFace;
FLOAT fBary1, fBary2, fDist;
bool hit = false;
int error = D3DXIntersect(pMesh, &vPickRayOrig, &vPickRayDir, (int*)&hit, &dwFace, &fBary1, &fBary2, &fDist, NULL, NULL);
i