Page 1 of 1

edge collition triangle mesh

Posted: Tue Jun 26, 2012 6:37 am
by astrolabio
I've an scene with a trimesh physics static object and a capsule that simulates a human body walking over it. The capsule bounces or deviates when it passes over an edge of the mesh. I'm trying to resolve it with the InternalEdgeInfo, but withot success.

Static ground definition

Code: Select all

static bool CustomMaterialCombinerCallback(btManifoldPoint& cp,	const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
{
		btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1);
		float friction0 = colObj0->getFriction();
	float friction1 = colObj1->getFriction();
	float restitution0 = colObj0->getRestitution();
	float restitution1 = colObj1->getRestitution();

	if (colObj0->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)
	{
		friction0 = 1.0;//partId0,index0
		restitution0 = 0.f;
	}
	if (colObj1->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)
	{
		if (index1&1)
		{
			friction1 = 1.0f;//partId1,index1
		} else
		{
			friction1 = 0.f;
		}
		restitution1 = 0.f;
	}

	cp.m_combinedFriction = calculateCombinedFriction(friction0,friction1);
	cp.m_combinedRestitution = calculateCombinedRestitution(restitution0,restitution1);
		return true;
}  
extern ContactAddedCallback		gContactAddedCallback;

bool Vm3dphysics::SetupPhysics(...)
{
	Ogre::Entity *mStaticEntity = sc_mgr->getEntity(entity);
	Ogre::SceneNode *StaticNode = mStaticEntity->getParentSceneNode();
	Ogre::SceneNode *newNode = sc_mgr->getRootSceneNode()->createChildSceneNode();
	newNode->setPosition(StaticNode->convertWorldToLocalPosition(Ogre::Vector3::ZERO));
	newNode->setOrientation(StaticNode->convertLocalToWorldOrientation(Ogre::Quaternion::IDENTITY));
	BtOgre::StaticMeshToShapeConverter converter2(mStaticEntity);
	btBvhTriangleMeshShape *mStaticShape = converter2.createTrimesh();
	btTriangleInfoMap* triangleInfoMap=new btTriangleInfoMap();
	mStaticShape->setUserPointer(triangleInfoMap);
	btGenerateInternalEdgeInfo(mStaticShape,triangleInfoMap); //para que no bote con edges
	BtOgre::RigidBodyState *StaticState = new BtOgre::RigidBodyState(StaticNode);
	btRigidBody *mStaticBody = new btRigidBody(0, StaticState, mStaticShape, btVector3(0,0,0));
	mStaticBody->setCollisionFlags(mStaticBody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
	phyWorld->addRigidBody(mStaticBody,interaccion,1);
	gContactAddedCallback = CustomMaterialCombinerCallback;
	return true;
}
Movable human definition

Code: Select all

	btScalar mass1 = 60;
	btVector3 inertia1;

	BtOgre::RigidBodyState *cylState = new BtOgre::RigidBodyState(cylNode);
	btCollisionShape* cylshape = new btCapsuleShape(ancho/2,alto-ancho);

	    //Create the Body.
	cylshape->calculateLocalInertia(mass1, inertia1);

	cylBody = new btRigidBody(mass1, cylState, cylshape, inertia1);
	phyWorld->addRigidBody(cylBody,1,3);
	
	btTransform frameInA = btTransform::getIdentity();
	frameInA.setOrigin(btVector3(0., 0., 0.));

	hinge=new btGeneric6DofConstraint(*cylBody,frameInA,true);
	hinge->setLinearLowerLimit(btVector3(-10000,-10000,-10000));
	hinge->setLinearUpperLimit(btVector3(10000,10000,10000));
	hinge->setAngularLowerLimit(btVector3(0,-SIMD_PI,0));
	hinge->setAngularUpperLimit(btVector3(0,SIMD_PI,0));
	phyWorld->addConstraint(hinge);

	cylBody->setFriction(.99);
	cylBody->setDamping(.7,.999);
	cylBody->setRestitution(0.3);
	cylBody->setAngularFactor(btVector3(0,1,0));
	cylBody->setActivationState(DISABLE_DEACTIVATION);