Skip to main content
gamedev.net
🔒 Locked

My IntersectSubset

Started by treeway Aug 3, 2006 at 9:58 AM 0 replies 550+ views
Original Post
treeway
treeway
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
DXnut
DXnut
Actually, what you want to do is lock the attribute buffer (not get the table). The face index returned by the D3DXIntersect function can be used as an index into the attribute buffer (an array of DWORDs, one for each face), to get the attribute ID of the subset of the hit face.

--------------------------Most of what I know came from Frank D. Luna's DirectX books

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.