need help

markbaker
Posts: 7
Joined: Mon Dec 01, 2008 3:37 am

need help

Post by markbaker »

I'm following the technique described here: http://www.bulletphysics.com/Bullet/php ... hape#p1660

Basically, i took the main Bullet tutorial from the wiki and added my new btConcaveShape-derived object to the scene.

The problem is, the object's processAllTriangles method isn't being called, even though the sphere & plane in the tutorial work fine & are contained inside my btConcaveShape object's AABB.

Can anyone spot anything wrong with my code?

Code: Select all

        
        btVector3 worldAabbMin(-10000,-10000,-10000);
        btVector3 worldAabbMax(10000,10000,10000);
        int maxProxies = 1024;
        btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);

        btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
        btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);

        btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
		
        dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
	
        dynamicsWorld->setGravity(btVector3(0,0,-10));


        btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,0,1),1);

	btCollisionShape* customShape = new btCustomShape();

        btCollisionShape* fallShape = new btSphereShape(20);

        btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,500)));
        btRigidBody::btRigidBodyConstructionInfo
                groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
        groundRigidBody = new btRigidBody(groundRigidBodyCI);
        dynamicsWorld->addRigidBody(groundRigidBody);

        btDefaultMotionState* customMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(512,512,512)));
        btRigidBody::btRigidBodyConstructionInfo customRigidBodyCI(0,customMotionState,customShape,btVector3(0,0,0));
        customRigidBody = new btRigidBody(customRigidBodyCI);
        dynamicsWorld->addRigidBody(customRigidBody);

		btDefaultMotionState* fallMotionState;

	loopv(os.set)
        {
			fallMotionState =
				new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(os.set[i]->ent->o.x, os.set[i]->ent->o.y, os.set[i]->ent->o.z)));
	}
         
		btScalar mass = 1;
        btVector3 fallInertia(0,0,0);
        fallShape->calculateLocalInertia(mass,fallInertia);
        btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
        fallRigidBody = new btRigidBody(fallRigidBodyCI);
        dynamicsWorld->addRigidBody(fallRigidBody);

Code: Select all

class btCustomShape : public btConcaveShape
{
protected:
	btVector3	m_localAabbMin;
	btVector3	m_localAabbMax;
	btVector3	m_scaling;

public:

	btCustomShape();
	virtual ~btCustomShape();

	virtual btVector3 localGetSupportingVertex(const btVector3& vec) const;

	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec)const
	{
		assert(0);
		return localGetSupportingVertex(vec);
	}

	virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;

	virtual void	processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;

	virtual void	calculateLocalInertia(btScalar mass,btVector3& inertia) const;

	virtual void	setLocalScaling(const btVector3& scaling);

	virtual const btVector3& getLocalScaling() const;
	
	const btVector3& getLocalAabbMin() const
	{
		return m_localAabbMin;
	}
	const btVector3& getLocalAabbMax() const
	{
		return m_localAabbMax;
	}

	//debugging
	virtual const char*	getName()const {return "CUSTOMMESH";}
};

Code: Select all

btCustomShape::btCustomShape() : btConcaveShape ()
{
	m_shapeType = CUSTOM_SHAPE;

	m_localAabbMin = btVector3(-1024,-1024,-1024);
    m_localAabbMax = btVector3(1024,1024,1024);
}

btCustomShape::~btCustomShape()
{
		
}

btVector3 btCustomShape::localGetSupportingVertex(const btVector3& vec) const
{
	return vec;
}

void btCustomShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
{

	btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
	localHalfExtents += btVector3(getMargin(),getMargin(),getMargin());
	btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
	
	btMatrix3x3 abs_b = trans.getBasis().absolute();  

	btPoint3 center = trans(localCenter);

	btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
		   abs_b[1].dot(localHalfExtents),
		  abs_b[2].dot(localHalfExtents));
	aabbMin = center - extent;
	aabbMax = center + extent;
}

//#define DEBUG_TRIANGLE_MESH



void btCustomShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
{
	
}

void btCustomShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
	(void)mass;
	//moving concave objects not supported
	btAssert(0);
	inertia.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
}

	
void btCustomShape::setLocalScaling(const btVector3& scaling)
{

}

const btVector3& btCustomShape::getLocalScaling() const
{
	return m_scaling;
}