How to use ghost object?

Post Reply
Chaz
Posts: 44
Joined: Mon Jan 12, 2015 1:36 pm

How to use ghost object?

Post by Chaz »

Hello. Explain me please how to use ghost object. I have read this page http://www.bulletphysics.org/mediawiki- ... d_Triggers and start to understand that ghost object allows to check collision between some selected two objects. After that I rewrite the code into Java

Code: Select all

 GhostObject ghostObject = new GhostObject();
        ObjectArrayList<PersistentManifold> manifoldArray = new ObjectArrayList<PersistentManifold>();
        ObjectArrayList<BroadphasePair> pairArray = broadphase.getOverlappingPairCache().getOverlappingPairArray();

        int numPairs = pairArray.size();

        for(int i =0; i<numPairs; i++)
        {
            BroadphasePair pair = pairArray.get(i);
            BroadphasePair collisionPair = dynamicsWorld.getPairCache().findPair(pair.pProxy0,pair.pProxy1);
            if(collisionPair==null)
                continue;

            if(collisionPair.algorithm!=null)
                collisionPair.algorithm.getAllContactManifolds(manifoldArray);

            for(int j=0; j<manifoldArray.size(); j++)
            {
                PersistentManifold manifold = manifoldArray.get(j);
                float directionSign = manifold.getBody0()==ghostObject ? -1.0f : 1.0f;
                for(int p=0; p<manifold.getNumContacts(); p++)
                {
                    ManifoldPoint pt= manifold.getContactPoint(p);
                    if(pt.getDistance()<0.f)
                    {
                        Vector3f ptA=new Vector3f();
                        Vector3f ptB=new Vector3f();
                        pt.getPositionWorldOnA(ptA);
                        pt.getPositionWorldOnB(ptB);
                        Vector3f normalOnB = pt.normalWorldOnB;
                    }
                }
            }
        }
I thought that after rewriting I'll understand it, but I still don't understand how to use this code.
Please, explain me deeply, what is ghost object in abstract meaning and then explain how to use it.
Post Reply