Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Author Message
 Posted: Tue Apr 17, 2012 10:06 pm

Joined: Fri May 07, 2010 2:20 pm
Posts: 11
dear group,

I am trying to implement a ray cast based collision detection.
The case study is quite simple:
it is a rectangular shape falling over a cylinder.
It works fine if I use btGjkConvexCast,
but it doesn't work using collisionWorld::rayTestSingle.
It seems that collisionWorld::rayTestSingle misses a lot of collisions,
even if the rays are the same for both the methods.
Can you explain me why?
What can I do if I want detect collisions against non convex shapes?

Regards,
Francesco

Code:
void ClothSimulator::solveCollision(REAL dt)
{
BT_PROFILE("solveCollision");
//TODO: Handle multiple rigid objects

//.. find rigid object
btCollisionObject* cyl_obj = m_world->getCollisionObjectArray()[1];
btTransform t = cyl_obj->getWorldTransform();
btConvexShape* cyl_shape = (btConvexShape*) cyl_obj->getCollisionShape();

btVector3 aabbMin, aabbMax;
cyl_shape->getAabb(t,aabbMin,aabbMax);

btVoronoiSimplexSolver   simplexSolver;

const unsigned npoints = m_particle.m_p.size();
for ( size_t i=0; i<npoints; i++)
{
bool hasHit = false;
btScalar closestHitResults = 1.f;
btConvexCast::CastResult rayResult;
btSphereShape pointShape(0.0f);

vec3 from =......
vec3 to = .......

btTransform rayFromTrans;
btTransform rayToTrans;

rayFromTrans.setIdentity();
rayFromTrans.setOrigin( btVector3(from.x,from.y,from.z) );

rayToTrans.setIdentity();
rayToTrans.setOrigin(btVector3(to.x,to.y,to.z));

btScalar hitLambda = 1.f;
btVector3 hitNormal;

btVector3 rayFrom = btVector3(from.x,from.y,from.z);
btVector3 rayTo = btVector3(to.x,to.y,to.z);

this is the the code for simple ray test:
btCollisionWorld::ClosestRayResultCallback cb(rayFrom, rayTo);
m_world->rayTestSingle(rayFromTrans,rayToTrans, cyl_obj, cyl_obj->getCollisionShape(), t, cb);
//m_world->rayTest(rayFrom, rayTo, cb );

if (cb.hasHit())
{
..............
}

this is the code for convex cast ray test:
if (btRayAabb(rayFrom, rayTo, aabbMin, aabbMax, hitLambda, hitNormal))
{
btTransform transform;
//btSubsimplexConvexCast convexCaster(&pointShape, cyl_shape,&simplexSolver);
btGjkConvexCast convexCaster(&pointShape, cyl_shape,&simplexSolver);
if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,t,t,rayResult))
{
if (rayResult.m_fraction < closestHitResults)
{
closestHitResults = rayResult.m_fraction;

hasHit = true;
if (hasHit)
{
.................
}
}
}
}

//-- try to discover difference between convex caster and simple ray test
if (cb.hasHit() && hasHit)
{
btVector3 delta = cb.m_hitPointWorld - rayResult.m_hitPoint;
printf("delta=(%f,%f,%f)\n",delta.getX(),delta.getY(),delta.getZ());

}
if (hasHit && !cb.hasHit())
{
printf("missing detection by simple ray cast\n");
}
if (cb.hasHit() && !hasHit)
{
printf("missing detection by convex ray cast\n");
}
}
}

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 1 post ]

 All times are UTC

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities