using coldet collison library on d3d9 3d models

Started by
7 comments, last by Mona2000 9 years, 5 months ago

so i would like create collison on my fps camera, i want to put a sphere at the cameras positon and do face to face collison with other 3d models rendering, i have decided to use this library

http://sourceforge.net/projects/coldet/?source=typ_redirect

this is what i am doing in code

CollisionModel3D* model; //private member of the camera class

//intialization in the camera constructor

D3DXCreateSphere(gd3dDevice, 2.0f, 8, 8, &Sphere, NULL);
model = newCollisionModel3D(); //coldet object
LockMesh();

i am not sure why its crashing, the locking mesh function works fine without the coldet stuff because ive written the vertices to a .txt file before, something is going wrong with the coldet object its self i think


void Camera::LockMesh()
{

    BYTE* lpbVb;
    int numIndices;
    BYTE *lpIB;
    DWORD idxVbVert0, idxVbVert1, idxVbVert2;
    D3DINDEXBUFFER_DESC ibdesc;
    LPDIRECT3DINDEXBUFFER9 lpIndexBuffer = NULL;
    Sphere->LockVertexBuffer(D3DLOCK_READONLY, (VOID**)&lpbVb);
    Sphere->LockIndexBuffer(D3DLOCK_READONLY, (VOID**)&lpIB);
    Sphere->GetIndexBuffer(&lpIndexBuffer);
    lpIndexBuffer->GetDesc(&ibdesc);
    if (ibdesc.Format == D3DFMT_INDEX32)
    {
        //MessageBox(NULL, "ibdesc.Format 32", "", 0);
        numIndices = ibdesc.Size / sizeof(DWORD);
    }
    else
    {
        //MessageBox(NULL,"ibdesc.Format 16","",0);
        numIndices = ibdesc.Size / sizeof(WORD);
    }


    DWORD numBytesPerVertex = Sphere->GetNumBytesPerVertex();


    for (int i = 0; i < numIndices; i += 3)
    {
        idxVbVert0 = ((WORD*)lpIB)[i];
        idxVbVert1 = ((WORD*)lpIB)[i + 1];
        idxVbVert2 = ((WORD*)lpIB)[i + 2];

        
            D3DXVECTOR3 v0 = *(D3DXVECTOR3*)&lpbVb[idxVbVert0 * numBytesPerVertex];
            D3DXVECTOR3 v1 = *(D3DXVECTOR3*)&lpbVb[idxVbVert1 * numBytesPerVertex];
            D3DXVECTOR3 v2 = *(D3DXVECTOR3*)&lpbVb[idxVbVert2 * numBytesPerVertex];
            model->addTriangle(v0, v1, v2); //coldet
            //Verts1.push_back(v0);
            //Verts2.push_back(v1);
            //Verts3.push_back(v2);
        
    }

    Sphere->UnlockIndexBuffer();
    Sphere->UnlockVertexBuffer();
    model->finalize(); //coldet

}
:)
Advertisement

What do you mean by "crash?" At which line of code does the error occur?

Have you stepped through your code to verify that you extract the D3D3XVECTOR3's correctly?

You check for the index size D3DFMT_INDEX32, but you assume that if it's not 32, it's 16. Have you verified that assumption?

Although you check for the index size, but you don't use that information. That is, you cast the index buffer pointer to (WORD*), (apparently) assuming the format is D3DFMT_INDEX16, which, as mentioned, you don't explicitly check for.


the locking mesh function works fine without the coldet stuff

So.. assuming you have the source code for "coldet stuff," have you debugged the code? Where do problems occur?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

yeh ive compiled the colder library in debug now and debugged the application it seems its crashing on the mesh locking vertexbuffer and i dont know why, i am using this function in another class to retrieve the vertices of the weapon without any issues,

LoadXFile("ak47.x", &mMesh, mMtrl, mTex);
LockMesh();

i am also checking if the mesh object is not null

if (Sphere != NULL)
{
MessageBox(NULL, "Sphere", "", 0); //this shows
}

i am baffeled at this point

screenshot of where debugging stops

http://i.imgur.com/UEC4EJa.png?1

:)

You check for the index size D3DFMT_INDEX32, but you assume that if it's not 32, it's 16. Have you verified that assumption?

There are no index formats other than INDEX16 and INDEX32.

Nevermind i have it working, it was something todo with the way i was creating the sphere, a quick test in a new application

http://i.imgur.com/tcOct06.png?1

:)

You check for the index size D3DFMT_INDEX32, but you assume that if it's not 32, it's 16. Have you verified that assumption?

There are no index formats other than INDEX16 and INDEX32.

Those are the only values that should occur. Different programming philosophies. I recommend checking for errors before they can disrupt execution, particularly in code as posted above, where no error checking is done, and a specific check is made for a value that's then ignored.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Assuming your D3D runtime might be bugged (because that's the only way you can find a different value) sounds like a terrible "programming philosophy".

Do you also check if the pointer returned by CreateIndexBuffer is in your process' address space, in case the return value is garbage due to a bug?

Assuming your D3D runtime might be bugged (because that's the only way you can find a different value) sounds like a terrible "programming philosophy".

Do you also check if the pointer returned by CreateIndexBuffer is in your process' address space, in case the return value is garbage due to a bug?

Certainly not. Admittedly the case in point is different and my reaction was a bit stiff. However, the posted code did no error checking whatsoever, assumed the locking was successful, and assumed the index buffer was always 16 bits. So, as I said..


I recommend checking for errors before they can disrupt execution

I don't consider checking for errors to avoid crashes a terrible programming philosophy.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I don't agree with checking for bugs, but I definitely agree with checking for errors. Those LockVertexBuffer, LockIndexBuffer and GetIndexBuffer calls all have a HRESULT return value for a reason.

This topic is closed to new replies.

Advertisement