Original Post
Hi Because im working with DirectX 8, I have to write my own equivilant to the D3DXIntersectSubset method:
if(scene->terrain->checkIntersect(playerPosition->x,playerPosition->y,playerPosition->z,
playerforwardAxis->x,playerforwardAxis->y,playerforwardAxis->z,&collisionDist,&faceId))
{
D3DXATTRIBUTERANGE temp;
DWORD numFaces = scene->terrain->getMesh()->getParentMesh()->m_Mesh->GetNumFaces();
scene->terrain->getMesh()->getParentMesh()->m_Mesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT,NULL,NULL,NULL,NULL);
scene->terrain->getMesh()->getParentMesh()->m_Mesh->GetAttributeTable(&temp,&numFaces);
for(DWORD i = 0; i < temp.FaceCount; i ++)
{
if(i == faceId)
{
DWORD p = temp.AttribId;
sprintf(base->buffer,"FaceId: %ld",p);
base->messageBox(NULL,base->buffer,"BOOM");
}
}
}
The steps it should take are: 1. If the ray cast from the player forward intersects with the terrain (using D3DXIntersect) get the FaceIndex. 2. Optimise the terrain mesh to get the attribute table. 3. Use the attribute table to find the attributeId of the intersectd face - this should be the same as the material number of the intersected face (?). I dont think im getting the attribtue table properly? or even accessing it properly? can anoyone help? Thanks