Mesh - mesh collision detection in OPCODE

Post Reply
labrap50
Posts: 1
Joined: Tue Jun 24, 2008 9:30 am

Mesh - mesh collision detection in OPCODE

Post by labrap50 »

Hello everybody!!
This is the first time that I am posting a topic in this forum. I am currently using OPCODE for collision detection in virtual reality environment. As you may know that in OPCODE there is a 'collider' which collides with a triangle-mesh object. We can get the triangles (from the mesh surface) which are 'in contact' with the collider (I am using LSS and CapsuleMeshQuery as in CDTestFramework example). But, I wanted to get the contact triangles in the collider itself as well. According to the OPCODE user manual, there is a Mesh-mesh collision query that might fit my need. However, I am having difficulty while trying to understand the step and implement it, as there is no demo for this one.

Has anybody tried to implement mesh-mesh collision query, and retrieve the contact triangles from both the object and the collider? I would appreciate if I get your help on this.

- labrap
fengerfafa
Posts: 1
Joined: Thu Jun 26, 2008 6:14 am

Re: Mesh - mesh collision detection in OPCODE

Post by fengerfafa »

I have the same problem!mesh vs mesh using opcode ,there lost the demo
Hanz
Posts: 14
Joined: Fri Jun 01, 2007 5:36 am

Re: Mesh - mesh collision detection in OPCODE

Post by Hanz »

If I understand your question correctly, for contact between, say obj1 and obj2, you want to get the collision triangles in both objects. Right?
Then it is not that difficult. Here is the main procedure:

Code: Select all


        // suppose you have set up the collision environment for obj1 and obj2
        bool IsOK = Collider.Collide(ColCache, &worldObj1, &worldObj2);

        if (IsOK) {

            // Get collision status => if true, objects overlap
            if ( Collider.GetContactStatus() ) {

                // Number of colliding pairs and list of pairs
                int TriCount = Collider.GetNbPairs();
                const Pair* CollidingPairs = Collider.GetPairs();

                if (TriCount > 0) {

                    int id1, id2;

                    for(int i = 0; i< TriCount; i++){
                        id1 = CollidingPairs[i].id0;
                        id2 = CollidingPairs[i].id1;

                        Opcode::VertexPointers VP;
                        Opcode::ConversionArea VC;

                        // obj1.getMeshData()->m_Mesh returns the mesh you set for collision object
                        obj1.getMeshData()->m_Mesh.GetTriangle(VP, id1, VC);

                        // now you get the [i]i[/i]th triangle vertex information for obj1
                        //                VP.Vertex[j]->x
                        //                VP.Vertex[j]->y
                        //                VP.Vertex[j]->z

                        // same for the other object obj2
                        obj2.getMeshData()->m_Mesh.GetTriangle(VP, id2, VC);

                        // now you get the [i]i[/i]th triangle vertex information for obj2
                        //                VP.Vertex[j]->x
                        //                VP.Vertex[j]->y
                        //                VP.Vertex[j]->z

                    }
                }
            }


And don't forget transform the vertex information to global position if you want to get the contact point in world space. Since, well, the vertex is local to corresponding meshes.

HTH

BTW, this forum is not for this kind of question, try "General Discussion about Collision Detection and Physics R&D" next time please.
zizo
Posts: 1
Joined: Sat Jun 11, 2011 8:01 pm

Re: Mesh - mesh collision detection in OPCODE

Post by zizo »

Hello,

I am just beginner to OpCode and actually I do not have any idea about how to use it even could not configure it with visual studio 2005. I am trying to find a simple collision detection library too detect the collision between mesh and sphere.

please, can any one help me with how to start using opcode or any advice regarding which collision detection library will help me to get my project done.

Thank you,
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Mesh - mesh collision detection in OPCODE

Post by Erwin Coumans »

I am trying to find a simple collision detection library too detect the collision between mesh and sphere.
Bullet collision detection can do that and it is pretty simple. You don't need to use the rigid body or soft body dynamics, they are separate libraries.

Either setup a btCollisionWorld and perform the queries, or go more low-level if needed.
Thanks,
Erwin
Post Reply