WrongResut convexSweepTest collision detection of two box

Post Reply
niluzhou1984
Posts: 2
Joined: Thu Jul 23, 2015 2:58 pm

WrongResut convexSweepTest collision detection of two box

Post by niluzhou1984 »

I have modified the HelloWorld example ,It is expected the m_closestHitFraction will be 0.6
but is gets 0.661333 here.
if I change colShape from btBoxShape to btSphereShape it will be 0.6.
Is it a bug ,or I have some mistake in my code?

My bullet version is 2.8.3, OS is windows 7. My code file is attached.

Code: Select all

///create a few basic rigid bodies
	btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(100.),btScalar(10.),btScalar(100)));

	//keep track of the shapes, we release memory at exit.
	//make sure to re-use collision shapes among rigid bodies whenever possible!
	btAlignedObjectArray<btCollisionShape*> collisionShapes;

	collisionShapes.push_back(groundShape);

	btTransform groundTransform;
	groundTransform.setIdentity();
	groundTransform.setOrigin(btVector3(0,0,0));

	{
		btScalar mass(0.);

		//rigidbody is dynamic if and only if mass is non zero, otherwise static
		bool isDynamic = (mass != 0.f);

		btVector3 localInertia(0,0,0);
		if (isDynamic)
			groundShape->calculateLocalInertia(mass,localInertia);

		//using motionstate is optional, it provides interpolation capabilities, and only synchronizes 'active' objects
		btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
		btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
		btRigidBody* body = new btRigidBody(rbInfo);

		//add the body to the dynamics world
		dynamicsWorld->addCollisionObject(body);
		
		
	}

	//const btSphereShape* colShape = new btSphereShape(1);

	const btBoxShape* colShape = new btBoxShape(btVector3(1, 1, 1));
	btTransform from;
	from.setOrigin(btVector3(0.0, 20.0, 0.0));
	btTransform to;
	to.setOrigin(btVector3(0.0,5.0,0.0));
	CustomizedConvexResultCallback callback;
	
	dynamicsWorld->convexSweepTest(colShape, from, to, callback);
	printf("%f\n", callback.m_closestHitFraction);
Attachments
HelloWorld.cpp
(5.08 KiB) Downloaded 117 times
niluzhou1984
Posts: 2
Joined: Thu Jul 23, 2015 2:58 pm

Re: WrongResut convexSweepTest collision detection of two b

Post by niluzhou1984 »

I have found the problem .

btTransform from and to is not setIdentity before use
Post Reply