Original Post
whew, i am not sure i'll ever be done with my collision detection problem. right now i am in a state where i extracted the vertices of the mesh i collide with from the vertex buffer,transformed them from object space to world space,made a loop to check 3 vertices at a time using D3DXIntersectTri and yet i seem to get odd results, sometimes even when i am not going in a direction into the collision object, the D3DXIntersectTri function still tells me that there is collision(heck, in some angles it even tells me distance is infinite,that's very wrong). i mean here is what i do : extracting vertex data from vertex buffer : creating variables for the intersction function : i am sorry that i didnt manage to solve this myself and i had to come asking for more help, but hours on hours on hours of debugging can kill one's ability to think. can anyone spot what might be the problem here?
VerticesNum = new D3DXVECTOR3[Mesh->GetNumFaces()*3];//vector3 array containing vertices
DWORD stride = Mesh->GetNumBytesPerVertex();
BYTE* vbptr = NULL;
Mesh->LockVertexBuffer(0, (LPVOID*)&vbptr);
D3DXVECTOR3 *pos = VerticesNum;
for (DWORD i = 0; i < Mesh->GetNumFaces()*3; i++)
{
memcpy(pos, vbptr, 12);
vbptr += stride;
pos++;
}
Mesh->UnlockVertexBuffer();
D3DXVECTOR3 dir(xfps,yfps,zfps);//fps independant velocity
D3DXVECTOR3 origin(MainPlayer->x,MainPlayer->y,MainPlayer->z);
float distance = 0,v=0,u=0;
turning vertex data into world space once, and checking for intersection :
for(int i=0;i<rock->Mesh->GetNumFaces();++i)
{
if(datatransformed == false){
D3DXVec3TransformCoord(&rock->VerticesNum[i*3],&rock->VerticesNum[i*3],&(rock->general));
D3DXVec3TransformCoord(&rock->VerticesNum[i*3+1],&rock->VerticesNum[i*3+1],&(rock->general));
D3DXVec3TransformCoord(&rock->VerticesNum[i*3+2],&rock->VerticesNum[i*3+2],&(rock->general));
}
bool col = D3DXIntersectTri(&rock->VerticesNum[i*3],
&rock->VerticesNum[i*3+1],
&rock->VerticesNum[i*3+2],
&origin,
&dir,
&u, &v,
&distance);
if (col == true )
{
//unneccery data to show here
}
}
datatransformed=true;