• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Medo Mex

Excluding certain models from ray casting

8 posts in this topic

I need to exclude certain models/meshes from ray casting, this might include bounding box, glasses, certain models, etc...

Any sample code for ray casting with exclude list?

I'm using Bullet ray casting.
0

Share this post


Link to post
Share on other sites
Not sure you can exclude glass from ray casting, it doesn't just let light through, it refracts it. This is negligible if you are looking at an ordinary window model, but if you consider large blocks of glass (or even water) it's probably necessary to trace the ray through multiple bounces, otherwise you'd end up being able to see an enemy which cannot see you (which is impossible).
0

Share this post


Link to post
Share on other sites
@Bacterius: I would appreciate if you could point me to sample source code for excluding certain models, I have been trying to use raycasting "All Hit" callback and go through the hits from 0 to the number of hits but it's not working as expected.
0

Share this post


Link to post
Share on other sites
Sigh ... this is a repost from a previous response about Pathfinding in Bullet.

Pretty much you can just use dynamicWorld->RayTest() for ray to world testing. Here's an example of how to do that and also setup some collision filters (like how to dynamically select one single object to ignore (collision filter) while ray testing against everything else).
[code]
typedef struct _COLLISION_DATA
{
class CCollideeInstance *m_pCollideeInstance;
class CCharacterController *m_pDynamicObj;
class btCollisionObject *m_pRigidBody;
} COLLISION_DATA;
#define GET_GHOST(x) (btGhostObject *)(((COLLISION_DATA *)x->getUserPointer())->m_pRigidBody)
class GhostPairCallback : public btOverlappingPairCallback
{
public:
GhostPairCallback()
{
}
virtual ~GhostPairCallback()
{
}
virtual btBroadphasePair* addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
{
btCollisionObject* colObj0 = (btCollisionObject*) proxy0->m_clientObject;
btCollisionObject* colObj1 = (btCollisionObject*) proxy1->m_clientObject;
btGhostObject* ghost0 = btGhostObject::upcast(colObj0);
btGhostObject* ghost1 = btGhostObject::upcast(colObj1);
if (ghost0 && ghost0 != GET_GHOST(colObj1))
{
ghost0->addOverlappingObjectInternal(proxy1, proxy0);
}
if (ghost1 && ghost1 != GET_GHOST(colObj0))
ghost1->addOverlappingObjectInternal(proxy0, proxy1);
return 0;
}
virtual void* removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1,btDispatcher* dispatcher)
{
btCollisionObject* colObj0 = (btCollisionObject*) proxy0->m_clientObject;
btCollisionObject* colObj1 = (btCollisionObject*) proxy1->m_clientObject;
btGhostObject* ghost0 = btGhostObject::upcast(colObj0);
btGhostObject* ghost1 = btGhostObject::upcast(colObj1);
if (ghost0 && ghost0 != GET_GHOST(colObj1))
ghost0->removeOverlappingObjectInternal(proxy1,dispatcher,proxy0);
if (ghost1 && ghost1 != GET_GHOST(colObj0))
ghost1->removeOverlappingObjectInternal(proxy0,dispatcher,proxy1);
return 0;
}
virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy0,btDispatcher* dispatcher)
{
btAssert(0);
//need to keep track of all ghost objects and call them here
//m_hashPairCache->removeOverlappingPairsContainingProxy(proxy0,dispatcher);
}
};
struct ActorFilterCallback : public btOverlapFilterCallback
{
// return true when pairs need collision
virtual bool needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const
{
bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
//add some additional logic here that modifies 'collides'
btCollisionObject* colObj0 = (btCollisionObject*) proxy0->m_clientObject;
btCollisionObject* colObj1 = (btCollisionObject*) proxy1->m_clientObject;
if (GET_GHOST(colObj0) == colObj1)
{
return false;
}
if (GET_GHOST(colObj1) == colObj0)
{
return false;
}
return collides;
}
};
void ActorNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo)
{
// Do your collision logic here
// Only dispatch the Bullet collision information if you want the physics to continue
btCollisionObject* colObj0 = (btCollisionObject*) collisionPair.m_pProxy0->m_clientObject;
btCollisionObject* colObj1 = (btCollisionObject*) collisionPair.m_pProxy1->m_clientObject;
if (GET_GHOST(colObj0) == colObj1)
{
return;
}
if (GET_GHOST(colObj1) == colObj0)
{
return;
}
dispatcher.defaultNearCallback(collisionPair, dispatcher, dispatchInfo);
}
D3DXVECTOR3 CPhysicsEngine::CastRayToWorld(
const D3DXVECTOR3 &rayOrigin,
const D3DXVECTOR3 &rayDir,
CCollidee **hitObj,
CCollideeInstance **hitInstance,
CCharacterController **hitDynamicObj,
bool skipDynamicObjects,
bool skipBackfaces,
CCharacterController *pSkipObj,
D3DXPLANE *pHitPlane
)
{
btVector3 rayFromW, rayToW, newRay;
short oldGroup1;
short oldGroup2;
if (pSkipObj &&
pSkipObj->getGhostObject() &&
pSkipObj->m_sphereCollider &&
pSkipObj->getGhostObject()->getBroadphaseHandle()
)
{
oldGroup1 = pSkipObj->getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup;
oldGroup2 = pSkipObj->m_sphereCollider->getBroadphaseHandle()->m_collisionFilterGroup;
pSkipObj->getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup = 0x00;
pSkipObj->m_sphereCollider->getBroadphaseHandle()->m_collisionFilterGroup = 0x00;
}
rayFromW = btVector3( rayOrigin.x, rayOrigin.y, rayOrigin.z );
rayToW = btVector3( rayDir.x, rayDir.y, rayDir.z );
btCollisionWorld::ClosestRayResultCallback cb(rayFromW, rayToW);
if (skipBackfaces)
{
cb.m_flags = 1 << 0;
}
*hitObj = NULL;
*hitDynamicObj = NULL;
newRay = rayToW;
m_dynamicsWorld->rayTest( rayFromW, rayToW, cb );
if (cb.hasHit ())
{
btCollisionObject *pObj = cb.m_collisionObject;
if (pObj)
{
COLLISION_DATA *pCD;
pCD = (COLLISION_DATA *)pObj->getUserPointer();
if (pCD && pCD->m_pCollideeInstance)
{
CCollideeInstance *pInstance = pCD->m_pCollideeInstance;
if (pInstance)
{
newRay = cb.m_hitPointWorld;
if (pHitPlane)
{
D3DXPlaneFromPointNormal( pHitPlane,
&D3DXVECTOR3( newRay.getX(), newRay.getY(), newRay.getZ() ),
&D3DXVECTOR3( cb.m_hitNormalWorld.getX(), cb.m_hitNormalWorld.getY(), cb.m_hitNormalWorld.getZ() ) );
}
*hitObj = pInstance->m_pCollidee;
if (hitInstance)
{
*hitInstance = pInstance;
}
}
}
//
// If we still haven't matched, it's likely we hit a ghost
// object.
//
if (*hitObj == NULL)
{
if (pCD && pCD->m_pDynamicObj)
{
if (!skipDynamicObjects)
{
newRay = cb.m_hitPointWorld;
if (pHitPlane)
{
D3DXPlaneFromPointNormal( pHitPlane,
&D3DXVECTOR3( newRay.getX(), newRay.getY(), newRay.getZ() ),
&D3DXVECTOR3( cb.m_hitNormalWorld.getX(), cb.m_hitNormalWorld.getY(), cb.m_hitNormalWorld.getZ() ) );
}
}
*hitObj = NULL;
if (hitInstance)
{
*hitInstance = NULL;
}
*hitDynamicObj = pCD->m_pDynamicObj;
}
}
}
if (pSkipObj &&
pSkipObj->getGhostObject() &&
pSkipObj->m_sphereCollider &&
pSkipObj->getGhostObject()->getBroadphaseHandle()
)
{
pSkipObj->getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup = oldGroup1;
pSkipObj->m_sphereCollider->getBroadphaseHandle()->m_collisionFilterGroup = oldGroup2;
}
return D3DXVECTOR3( newRay.getX(), newRay.getY(), newRay.getZ() );
}
void Example()
{
m_defaultContactProcessingThreshold = BT_LARGE_FLOAT;
m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
m_overlappingPairCache = new btDbvtBroadphase();

m_ghostPairCallback = new GhostPairCallback();
m_overlappingPairCache->getOverlappingPairCache()->setInternalGhostPairCallback(m_ghostPairCallback);
m_constraintSolver = new btSequentialImpulseConstraintSolver();
m_dynamicsWorld = new btDiscreteDynamicsWorld( m_dispatcher,
m_overlappingPairCache,
m_constraintSolver,
m_collisionConfiguration
);
m_filterCallback = new ActorFilterCallback();
m_dynamicsWorld->getPairCache()->setOverlapFilterCallback(m_filterCallback);
m_dispatcher->setNearCallback(ActorNearCallback);
}
[/code]
1

Share this post


Link to post
Share on other sites
Hi Steve,

The other question about Pathfinding was completely different (I was trying to implement Pathfinding which has nothing to do with using raycasting while excluding certain models (like they don't exist).

I believe that the above code is not exactly what I'm looking for, here is the prototype of the method that I'm looking for:

[CODE]void Raycast(btVector3 rayOrigin, btVector3 rayDir, vector<DWORD> excludeModelsIDs);[/CODE]

body->getUserPointer() will point to a number, the number will represent the ID of the model, so excludeModelsIDs should include list of models ID that I want to exclude (at this point ray casting will act like they don't exists). Edited by Medo3337
0

Share this post


Link to post
Share on other sites
Good luck to you! Remember, it's your job to write your code not mine :)

You can scrape out the concept of collision filters from the code snippet I already gave you or use the Bullet documentation and examples to learn more about it. Basically a collision filter is how to exclude a shape from raycasting. The example I gave you above allows you to exclude static and dynamic objects, so that you can use collision ghost objects for dynamic objects (like MOBs) and exclude one of them (like yourself) so that certain kinds of operations are simpler ... the code above was cut from code I used for movement routines.
0

Share this post


Link to post
Share on other sites
Of course it's my job to write my code, I'm asking for the parts that I don't understand yet.

I think collision filter will not work because I ONLY want to exclude certain models from ray casting and still detect collision with them, I could exclude a character/vehicle or anything mesh from ray casting even this mesh is still physical and still need to detect collision with it.
0

Share this post


Link to post
Share on other sites
Yeah sorry, that came off a bit rude - typed text always sounds on a bad note :)

The collision filter could work if you set it right before you do a raycast and then reset it to the original value right after, then you could still collide with it during your StepSimulation part. It works for me at least.
0

Share this post


Link to post
Share on other sites
Okay, thank you, I will take a look over collision filter.

If you have knowledge about Bullet Vehicle, please take a look over this thread:
http://www.gamedev.net/topic/634827-bullet-vehicle-wheels-direction-problem-code-attached/

The vehicle is working except one problem, the wheels are looking at the sides of the vehicle instead of the front direction therefore the wheels are rotating incorrectly.
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0