btColllisionObject wobbling left and right plus in and out

Post Reply
lucky7456969
Posts: 26
Joined: Thu Sep 11, 2014 5:40 am

btColllisionObject wobbling left and right plus in and out

Post by lucky7456969 »

I am in a situation that an object of mass 1.0f at btVector3(2,10,0)
dropping with a gravity of (0,-10,0), it is very unstable in the x-axis and z-axis
it does reach the ground at btVector3(0,-56,0)
but ever since it starts to wobble/bounce back and forth in x and z
I have a restitution of 0
and did not setup the rest of the parameters.
I'd like to see a behavior that as the agent is massive, I don't want to bounce in anyways
Any ideas Why?

Code: Select all

CB00001 0.994062 -56.000000 -0.987768
CB00001 1.004779 -56.000000 1.012203
CB00001 3.004750 -56.000000 1.001486
CB00001 2.994034 -56.000000 -0.998485
CB00001 0.994062 -56.000000 -0.987763
CB00001 1.004779 -56.000000 1.012209
CB00001 3.004750 -56.000000 1.001492
CB00001 2.994034 -56.000000 -0.998480
CB00001 0.994062 -56.000000 -0.987758
CB00001 1.004779 -56.000000 1.012213
CB00001 3.004750 -56.000000 1.001496
CB00001 2.994033 -56.000000 -0.998475
CB00001 0.994062 -56.000000 -0.987753
CB00001 1.004779 -56.000000 1.012219
CB00001 3.004750 -56.000000 1.001502
CB00001 2.994033 -56.000000 -0.998470
CB00001 0.994062 -56.000000 -0.987747
CB00001 1.004779 -56.000000 1.012224
CB00001 3.004750 -56.000000 1.001507
CB00001 2.994033 -56.000000 -0.998464
CB00001 0.994062 -56.000000 -0.987742
CB00001 1.004779 -56.000000 1.012229
CB00001 3.004750 -56.000000 1.001512
CB00001 2.994033 -56.000000 -0.998459
Thanks
Jack
papaonn
Posts: 41
Joined: Wed Nov 20, 2013 4:14 pm

Re: btColllisionObject wobbling left and right plus in and o

Post by papaonn »

Hi could you illustrate the situation more in detail?

Because there can be many factors such as the shape of your object, the collision surface angle, collision surface friction, the collision target type (non-movable / movable), object's DISABLED_DEACTIVATION flag etc, all of these can affect the collision restitution problem.

Usually bullet will auto trim off the wobbling effect (put object at rest) automatically without user worrying.
lucky7456969
Posts: 26
Joined: Thu Sep 11, 2014 5:40 am

Re: btColllisionObject wobbling left and right plus in and o

Post by lucky7456969 »

Code: Select all


 



struct YourContext {
};
 


struct ContactSensorCallback : public btCollisionWorld::ContactResultCallback {

    //! Constructor, pass whatever context you want to have available when processing contacts
    /*! You may also want to set m_collisionFilterGroup and m_collisionFilterMask
     *  (supplied by the superclass) for needsCollision() */
    ContactSensorCallback(btRigidBody& tgtBody , YourContext& context /*, ... */)
        : btCollisionWorld::ContactResultCallback(), body(tgtBody), ctxt(context) { }

    btRigidBody& body; //!< The body the sensor is monitoring
    YourContext& ctxt; //!< External information for contact processing

    //! If you don't want to consider collisions where the bodies are joined by a constraint, override needsCollision:
    /*! However, if you use a btCollisionObject for #body instead of a btRigidBody,
     *  then this is unnecessary—checkCollideWithOverride isn't available */
    virtual bool needsCollision(btBroadphaseProxy* proxy) const {
        // superclass will check m_collisionFilterGroup and m_collisionFilterMask
        if(!btCollisionWorld::ContactResultCallback::needsCollision(proxy))
            return false;
        // if passed filters, may also want to avoid contacts between constraints
        return body.checkCollideWithOverride(static_cast<btCollisionObject*>(proxy->m_clientObject));
    }

    //! Called with each contact for your own processing (e.g. test if contacts fall in within sensor parameters)
    virtual btScalar addSingleResult(btManifoldPoint& cp,
        const btCollisionObjectWrapper* colObj0,int partId0,int index0,
        const btCollisionObjectWrapper* colObj1,int partId1,int index1)
    {
        btVector3 pt; // will be set to point of collision relative to body
        if(colObj0->m_collisionObject==&body) {
			pt = cp.getPositionWorldOnA();
			cprintf ("%f %f %f\n", pt.getX(), pt.getY(), pt.getZ());
        } else {
            assert(colObj1->m_collisionObject==&body && "body does not match either collision object");
            pt = cp.m_localPointB;
        }
        // do stuff with the collision point
		
        return 0; // not actually sure if return value is used for anything...?
    }
};

//-------------------------------------------------------------------------------------
Cooperative_Pathfinding_Test::Cooperative_Pathfinding_Test(void) 
{
	 
	initPhysics(); 
	
}
//-------------------------------------------------------------------------------------
Cooperative_Pathfinding_Test::~Cooperative_Pathfinding_Test(void)
{
}

//-------------------------------------------------------------------------------------
 
void Cooperative_Pathfinding_Test::initPhysics() {
	
 
	///-----includes_end-----


	int i;
	///-----initialization_start-----

	///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
	btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();

	///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
	btCollisionDispatcher* dispatcher = new	btCollisionDispatcher(collisionConfiguration);

	///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep.
	btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();

	///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
	btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;

	m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration);

	m_dynamicsWorld->setGravity(btVector3(0,-10,0));


	 

	///-----initialization_end-----

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

	//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,-56,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 recommended, 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
		m_dynamicsWorld->addRigidBody(body);
	}


	{
		//create a dynamic rigidbody

		btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
		//btCollisionShape* colShape = new btSphereShape(btScalar(1.));
		collisionShapes.push_back(colShape);

		/// Create Dynamic Objects
		btTransform startTransform;
		startTransform.setIdentity();

		btScalar	mass(1.f);

		//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)
			colShape->calculateLocalInertia(mass,localInertia);

		startTransform.setOrigin(btVector3(2,10,0));
		
		//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
		btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
		btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
		btRigidBody* body = new btRigidBody(rbInfo);
	 
	 
		btRigidBody::btRigidBodyConstructionInfo cInfo(1.0, myMotionState, colShape);
		tgtBody = new btRigidBody(cInfo);


		m_dynamicsWorld->addRigidBody(tgtBody);
		

		
	}
}


bool Cooperative_Pathfinding_Test::frameRenderingQueued(const Ogre::FrameEvent& evt) {
	 
 
	m_dynamicsWorld->stepSimulation(1.f/60.f,10);

	YourContext foo;
	ContactSensorCallback callback(*tgtBody, foo);
	
	m_dynamicsWorld->contactTest(tgtBody,callback);		 
  
	return FrameListener::frameRenderingQueued(evt);
} 
It seems like a sphere shape is far more stable than a box shape, didn't understand why?
Thanks
Jack
Post Reply