Page 1 of 1
convexTest with rotation
Posted: Thu Jan 10, 2008 11:18 pm
by lsgmasa
Hello
I am developing a game which has a user level creation, and I started using convexTest(...) function to find out the intersection point between placeable objects and static background.
It worked good at the beginning, but I realized I have to rotate the object. Is there any way to use btCollisionWorld::convexTest(...) with rotated shapes?
Thanks
Re: convexTest with rotation
Posted: Fri Jan 11, 2008 12:58 am
by lsgmasa
Hello again. I looked at convexTest(...) function and created my version of it
it takes extra parameter rotation, and the rotation value is used to calculate convexFromTrans, convexToTrans, and value "I".
I tested this function by casting box shape with rotation value, and it seems working good.
However, I wonder if what I am doing is correct thing, and if you guys give me any opinion, that would be great.
Thanks in advance.
Code: Select all
void convexTestWithRotation(
const btConvexShape* castShape,
const btVector3& convexFromWorld,
const btVector3& convexToWorld,
const btQuaternion& rotation, //added
btCollisionWorld::ConvexResultCallback& resultCallback,
short int collisionFilterMask )
{
btTransform convexFromTrans,convexToTrans;
convexFromTrans.setIdentity();
convexFromTrans.setOrigin(convexFromWorld); //<-added
convexFromTrans.setRotation( rotation );
convexToTrans.setIdentity();
convexToTrans.setOrigin(convexToWorld);
convexToTrans.setRotation( rotation ); //<-added
btVector3 castShapeAabbMin, castShapeAabbMax;
btTransform I;
I.setIdentity();
I.setRotation( rotation );//<-added
castShape->getAabb (I, castShapeAabbMin, castShapeAabbMax);
btCollisionObjectArray& collisionObjects = g_bullet.m_pWorld->getCollisionObjectArray();
/// go over all objects, and if the ray intersects their aabb + cast shape aabb,
// do a ray-shape query using convexCaster (CCD)
int i;
for (i=0;i<collisionObjects.size();i++)
{
btCollisionObject* collisionObject= collisionObjects[i];
//only perform raycast if filterMask matches
if(collisionObject->getBroadphaseHandle()->m_collisionFilterGroup & collisionFilterMask) {
//RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
btVector3 collisionObjectAabbMin,collisionObjectAabbMax;
collisionObject->getCollisionShape()->getAabb(collisionObject->getWorldTransform(),collisionObjectAabbMin,collisionObjectAabbMax);
AabbExpand (collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
btScalar hitLambda = btScalar(1.); //could use resultCallback.m_closestHitFraction, but needs testing
btVector3 hitNormal;
if (btRayAabb(convexFromWorld,convexToWorld,collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
{
g_bullet.m_pWorld->objectQuerySingle(castShape, convexFromTrans,convexToTrans,
collisionObject,
collisionObject->getCollisionShape(),
collisionObject->getWorldTransform(),
resultCallback);
}
}
}
}
Re: convexTest with rotation
Posted: Fri Jan 11, 2008 1:49 am
by reltham
I would guess that you should not need to apply the rotation to both the shape and from/to transforms. Probably just one or the other would accomplish what you want.
Re: convexTest with rotation
Posted: Fri Jan 11, 2008 2:40 am
by lsgmasa
I removed the rotation from the shape, and now it doesn't work anymore.
it seems that I need to apply the rotation to the both
Reltham Thanks you for your feedback though
Re: convexTest with rotation
Posted: Fri Jan 11, 2008 7:45 am
by John McCutchan
I will post the fix that will be in the next version of Bullet tomorrow. I finished it earlier today but I didn't have time to post it. It's essentially the same as the one you posted but it will allow for the from and to rotations to be different.
Re: convexTest with rotation
Posted: Fri Jan 11, 2008 6:03 pm
by lsgmasa
great thanks!
Re: convexTest with rotation
Posted: Fri Jan 11, 2008 8:28 pm
by John McCutchan
The new convexSweepTest has been committed to SVN. Can you please test it to verify that it functions properly? Instead of a btVector3 from and to the function now takes a from and to transformation.
Thanks,
John
Re: convexTest with rotation
Posted: Tue Jan 15, 2008 7:18 pm
by lsgmasa
OK I finally got time to test the new code, but it didn't work as it is in the SVN depot.
the things I did:
1. get the latest btCollisinWorld.{h,cpp}
2. build bullet 2..66 using these files.
3. run my game.
the result returned by convexSweepTest(...) was wrong.
I compared the new function with my version of function, and I realized the btTransform passed into calculateTemporalAabb(...) has translation since the new function uses "convexFromWorld" directly.
I changed the btCollisionWorld::convexSweepTest(...) as the following and it seems working again.
Code: Select all
void btCollisionWorld::convexSweepTest(const btConvexShape* castShape, const btTransform& convexFromWorld, const btTransform& convexToWorld, ConvexResultCallback& resultCallback,short int collisionFilterMask)
{
btTransform convexFromTrans,convexToTrans;
convexFromTrans = convexFromWorld;
convexToTrans = convexToWorld;
btVector3 castShapeAabbMin, castShapeAabbMax;
/* Compute AABB that encompasses movement */
{
btVector3 linVel, angVel;
btTransformUtil::calculateVelocity (convexFromTrans, convexToTrans, 1.0, linVel, angVel);
btConvexShape* pTest = (btConvexShape*)castShape; //<-added I needed to cast the pointer from const btConvexShape* to btConvexShape*... I don't know why...
btTransform I;//<-added
I.setIdentity();//<-added
I.setRotation( convexFromWorld.getRotation() );//<-added
pTest->calculateTemporalAabb (I, linVel, angVel, 1.0, castShapeAabbMin, castShapeAabbMax);
}
/// go over all objects, and if the ray intersects their aabb + cast shape aabb,
// do a ray-shape query using convexCaster (CCD)
int i;
for (i=0;i<m_collisionObjects.size();i++)
{
btCollisionObject* collisionObject= m_collisionObjects[i];
//only perform raycast if filterMask matches
if(collisionObject->getBroadphaseHandle()->m_collisionFilterGroup & collisionFilterMask) {
//RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
btVector3 collisionObjectAabbMin,collisionObjectAabbMax;
collisionObject->getCollisionShape()->getAabb(collisionObject->getWorldTransform(),collisionObjectAabbMin,collisionObjectAabbMax);
AabbExpand (collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
btScalar hitLambda = btScalar(1.); //could use resultCallback.m_closestHitFraction, but needs testing
btVector3 hitNormal;
if (btRayAabb(convexFromWorld.getOrigin(),convexToWorld.getOrigin(),collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
{
objectQuerySingle(castShape, convexFromTrans,convexToTrans,
collisionObject,
collisionObject->getCollisionShape(),
collisionObject->getWorldTransform(),
resultCallback);
}
}
}
}
Re: convexTest with rotation
Posted: Tue Jan 15, 2008 8:35 pm
by reltham
I think the reason you had to cast away the const was that you didn't get the new version of btCollisionShape.cpp/h.
Re: convexTest with rotation
Posted: Wed Jan 16, 2008 12:22 am
by lsgmasa
Thanks reltham
yes, that must be it.
Re: convexTest with rotation
Posted: Wed Jan 16, 2008 3:25 am
by John McCutchan
You're right there is a bug in the SVN version. A proper fix has been developed and will be committed soon. In the meantime you can continue to use the version you have developed.
Thanks for your feedback,
John
Re: convexTest with rotation
Posted: Fri Feb 08, 2008 8:01 pm
by John McCutchan
Hey,
A fix based on your code was committed this morning. Please let us know if your issue persists.
Thanks,
John