Posts

Showing posts from June, 2008

C++ - Direct X 9.0 - Overlap Tests (Mesh)

This is a code snippet, that I put together to handle mesh-overlapping, so if the view of a player's model is obstructed by something such as a tree, this will cause that tree to have an applied transparency. The code snippet can be used however you want, and broken up/restructured to be more organized -- however, please give me credit if you use it. Thanks. D3DXVECTOR3 vCenter; // Lock the Vertex Buffer if(SUCCEEDED(pMesh->LockVertexBuffer(D3DLOCK_READONLY, (BYTE**)&Ptr))) { // Computer Bounding Sphere Radius D3DXComputeBoundingSphere((void*)Ptr, pMesh->GetNumVertices(), pMesh->GetNumBytesPerVertex(), &vCenter, &fObjectRadius); fObjectRadius = D3DXVec3Length(&vCenter) + fObjectRadius; // Unlock the Vertex Buffer pMesh->UnlockVertexBuffer(); } This calculates the Radius, for use in the below Overlap test, your radius will never change, since this mesh isn't adjusting in size. D3DXVECTOR3 vObjectPosVS, vPla