Jump to content
  • Advertisement
Sign in to follow this  
Anddos

using coldet collison library on d3d9 3d models

This topic is 1428 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

}
Edited by Anddos

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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

Edited by Anddos

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

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.

Edited by Buckeye

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!