Correct Initialization.

User avatar
shotgunnutter
Posts: 17
Joined: Thu Nov 01, 2007 2:13 am

Correct Initialization.

Post by shotgunnutter »

I'm getting crash bugs when I try to make my first application using Bullet. Here is the class header:

Code: Select all

class phy_demo
{
private:
	//calculation objects: used to compare physics entities.
	btBroadphaseInterface * m_overlappingPairCache;
	btCollisionDispatcher * m_dispatcher;
	btConstraintSolver * m_solver;

	//entities in world
	btCollisionShape * phy_level;	//a flat surface to begin with, perhaps upgrading to a trimesh.
	btDynamicsWorld * m_dynamicsWorld;	
	btAlignedObjectArray<btCollisionShape*>	m_collisionShapes;
	btRigidBody* localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape);
public:
	phy_demo();
	~phy_demo();
	void build();
	void update();
	//calculates its own timestep so no FPS parameter
	void draw(renderer * r);
};
Is this everything I need? What should I do to initialize it?
I'm using gcc 4.0.2, on OS X 10.4, compiling with Xcode.
Thanks.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Correct Initialization.

Post by Erwin Coumans »

Do the Bullet demos work fine?

Only a callstack will help locating a crash.

Can you double-check and compare with some of the Bullet demos, to see what is going wrong?

Thanks,
Erwin
User avatar
shotgunnutter
Posts: 17
Joined: Thu Nov 01, 2007 2:13 am

Re: Correct Initialization.

Post by shotgunnutter »

Hi, thanks for replying.

I've got something compiling and executing now. I already have a working graphics engine and I simply want to use BULLET to add physics to the game. Here is the initialization code I'm currently using, taken from the basicdemo and compacted:

Code: Select all

        //configure bullet
	btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();

	//create algorithm classes
	btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
	m_solver = sol;
	m_dispatcher = new	btCollisionDispatcher(collisionConfiguration);
	m_overlappingPairCache = new btAxisSweep3(
		btVector3(-10000,-10000,-10000),	
		btVector3(10000,10000,10000
	);
	//create BulletDynamicsWorld
	m_dynamicsWorld = new btSimpleDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver);
	m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
	m_dynamicsWorld->setGravity(btVector3(0,-10,0));

	//create ground shape
	btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.)));
	m_collisionShapes.push_back(groundShape);
	btTransform groundTransform;
	groundTransform.setIdentity();
	groundTransform.setOrigin(btVector3(0,-56,0));
	localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
	
	//create ball
	btCollisionShape* colShape = new btSphereShape(btScalar(1.));
	m_collisionShapes.push_back(colShape);
	btTransform startTransform;
	startTransform.setIdentity();
	localCreateRigidBody(1, startTransform,colShape);


Questions:

Did I do everything properly? I've compacted the basicDemo classes into a single class because I found the large number of preprocessor directives confusing and didn't like looking back and forth between 4 code files.

How do I plug my renderer in? I believe this involves a btDebugDraw object.

How do I clean up properly? Do I have to scan through the btAlignedObjectArray container and delete each object that way?

How do I simplify this further? I just want to have a ball bouncing off of a box.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Correct Initialization.

Post by Erwin Coumans »

shotgunnutter wrote:How do I plug my renderer in? I believe this involves a btDebugDraw object.
Just take the world matrix for each rigid body and copy it into your graphics object. You can use
rigidbody->getWorldTransform().getOpenGLMatrix(m);
How do I clean up properly? Do I have to scan through the btAlignedObjectArray container and delete each object that way?
You can see an example of cleanup in BasicDemo.
How do I simplify this further? I just want to have a ball bouncing off of a box.
BasicDemo create balls bouncing on a box.

Which parts of BasicDemo are difficult to use? Perhaps we should cleanup the demos?

Hope this helps,
Erwin
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Re: Correct Initialization.

Post by AlexSilverman »

Hello,

Just to weigh in on the issue of complicated demos, I used CcdDemo to get my bearings when starting, and the problem I had was just making sense of the flow with all the #ifdef branches in there. I ended up copying the contents and deleting the branches I didn't need, just so it was clearer. It wasn't a huge problem, but it just affected readability for me.

- Alex