Hmmm.
Need some help with my intersection checking code. At the mo it sort of works, in that I''m printing the hit/miss value to the screen and it does alternate between 1 and 0, but it''s all just a bit out (like object is in a slightly different postion/rotated a bit. My intersection code is as follows
int MeshInterSectionCheck(LPD3DXMESH pMesh)
{
D3DXVECTOR3 vecRay, vecDir;
D3DXVECTOR3 v;
D3DXMATRIX matProj, matView;
D3DXMATRIX m;
g_pd3dDevice->GetTransform(D3DTS_PROJECTION, &matProj);
g_pd3dDevice->GetTransform(D3DTS_VIEW, &matView);
D3DXMatrixInverse(&m, NULL, &matView);
v.x = ((( 2.0f * g_Mouse_pos_x) / g_Screen_width ) - 1) / matProj._11;
v.y = -((( 2.0f * g_Mouse_pos_y) / g_Screen_height) - 1) / matProj._22;
v.z = 1.0f;
vecRay.x = m._41;
vecRay.y = m._42;
vecRay.z = m._43;
vecDir.x = (v.x*m._11) + (v.y*m._21) + (v.z*m._31);
vecDir.y = (v.x*m._12) + (v.y*m._22) + (v.z*m._32);
vecDir.z = (v.x*m._13) + (v.y*m._23) + (v.z*m._33);
BOOL Hit;
DWORD Face;
float texU, texV, Dist;
D3DXIntersect(pMesh, &vecRay, &vecDir, &Hit, &Face, &texU, &texV, &Dist);
return Hit;
}
This is mostly from Programming RPGs with DirectX, so Jim Adams, If your about, some help would be gratefuly received.
btw. the mesh is defined as...
LPD3DXMESH g_pMesh = NULL;
and created like this...
if( FAILED( D3DXLoadMeshFromX( "firstplane.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL,
&pD3DXMtrlBuffer, &g_dwNumMaterials,
&g_pMesh ) ) )
I don''t really understand the maths around creating the ray so having trouble debugging.
The screen width height value are 800/600 and the mouse values range from 0 to these values (that seems a bit obvious now i''ve typed it but there you go)
Help