Can RayTest be ignored for particular collision object?

Post Reply
John1789
Posts: 15
Joined: Fri Sep 02, 2011 11:54 am

Can RayTest be ignored for particular collision object?

Post by John1789 »

I am using a raycast car in which all four wheel cast a ray to detect the ground.
I want to know is it possible that raytest ignored for particular collision objects ?
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Can RayTest be ignored for particular collision object?

Post by mi076 »

for example like here, look for #ifdef USE_GHOST_OBJ_WITH_VEHICLE.. (BTW, word "ghost" doesn't mean Bullet ghost object, it can be any collision object).

Code: Select all

struct  MyVehicleRayResultCallback : public btCollisionWorld::ClosestRayResultCallback
{
    const btCollisionShape * m_hitTriangleShape;
    int                      m_hitTriangleIndex;
    int                      m_hitShapePart;


    MyVehicleRayResultCallback (const btVector3 & rayFrom,const btVector3 & rayTo)
        : btCollisionWorld::ClosestRayResultCallback(rayFrom, rayTo),
          m_hitTriangleShape(NULL),
          m_hitTriangleIndex(0),
          m_hitShapePart(0)
    {
    }

    ~MyVehicleRayResultCallback()
    {
    }

    bool needsCollision(btBroadphaseProxy* proxy0) const
    {
        bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
        collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask);

#ifdef USE_GHOST_OBJ_WITH_VEHICLE
        //modify 'collides'
        btCollisionObject * b = 0;
        b = static_cast<btCollisionObject *>(proxy0->m_clientObject);
        if (b)
        {
            if ( static_cast<int*>(b->getUserPointer()))
            {
                if ( static_cast<int*>(b->getUserPointer())[1] == 2 )
                {
                    return false;
                }
            }
        }
#endif

        return collides;
    }

    btScalar addSingleResult(btCollisionWorld::LocalRayResult & rayResult, bool normalInWorldSpace)
    {
        return ClosestRayResultCallback::addSingleResult(rayResult,normalInWorldSpace);
    }
};
John1789
Posts: 15
Joined: Fri Sep 02, 2011 11:54 am

Re: Can RayTest be ignored for particular collision object?

Post by John1789 »

mi076 wrote:for example like here, look for #ifdef USE_GHOST_OBJ_WITH_VEHICLE.. (BTW, word "ghost" doesn't mean Bullet ghost object, it can be any collision object).

Code: Select all

struct  MyVehicleRayResultCallback : public btCollisionWorld::ClosestRayResultCallback
{
    const btCollisionShape * m_hitTriangleShape;
    int                      m_hitTriangleIndex;
    int                      m_hitShapePart;


    MyVehicleRayResultCallback (const btVector3 & rayFrom,const btVector3 & rayTo)
        : btCollisionWorld::ClosestRayResultCallback(rayFrom, rayTo),
          m_hitTriangleShape(NULL),
          m_hitTriangleIndex(0),
          m_hitShapePart(0)
    {
    }

    ~MyVehicleRayResultCallback()
    {
    }

    bool needsCollision(btBroadphaseProxy* proxy0) const
    {
        bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
        collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask);

#ifdef USE_GHOST_OBJ_WITH_VEHICLE
        //modify 'collides'
        btCollisionObject * b = 0;
        b = static_cast<btCollisionObject *>(proxy0->m_clientObject);
        if (b)
        {
            if ( static_cast<int*>(b->getUserPointer()))
            {
                if ( static_cast<int*>(b->getUserPointer())[1] == 2 )
                {
                    return false;
                }
            }
        }
#endif

        return collides;
    }

    btScalar addSingleResult(btCollisionWorld::LocalRayResult & rayResult, bool normalInWorldSpace)
    {
        return ClosestRayResultCallback::addSingleResult(rayResult,normalInWorldSpace);
    }
};

Ok, i tried that so i am using needcollision fun like given below

Code: Select all

 bool needsCollision(btBroadphaseProxy* proxy0) const
    {
        bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
        collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask);

        btCollisionObject * b = 0;
        b = static_cast<btCollisionObject *>(proxy0->m_clientObject);
        if (b)
        {
            if ( static_cast<int*>(b->getUserPointer()))
            {
                if ( static_cast<int*>(b->getUserPointer())[2] == 1010 )
                {
                    cout<<"COLLISION IGNORED";
                    return false;
                }
            }
        }


        return collides;
    }
i put pointer[2] = 1010 for a specific object but i am getting "COLLISION IGNORED" even when its not in range of that object.
am i doing something wrong??
John1789
Posts: 15
Joined: Fri Sep 02, 2011 11:54 am

Re: Can RayTest be ignored for particular collision object?

Post by John1789 »

Ok got it..... its checking for all collider objects ...
Post Reply