problem after reading from .bullet file

Post Reply
xxh12321
Posts: 7
Joined: Wed Jan 25, 2012 2:27 pm

problem after reading from .bullet file

Post by xxh12321 »

I use blender export my scene. After I imported my .bullet file, I found that the ball didn't collide with the slope.
run the program you will find only z of the ball is changing.

Code: Select all

#include <iostream>

#include <btBulletDynamicsCommon.h>
#include "btBulletWorldImporter.h"
#include "OpenGL/GLDebugDrawer.h"

GLDebugDrawer* debugDrawer = new GLDebugDrawer();

int main (void)
{

	btBroadphaseInterface* broadphase = new btDbvtBroadphase();

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

	btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;

	btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);

	btBulletWorldImporter* fileLoader = new btBulletWorldImporter(dynamicsWorld);

	bool suc = fileLoader->loadFile("test.bullet");

	dynamicsWorld->setGravity(btVector3(0,0,-10));//in blender z axis is up, but in bullet y axis is up

	debugDrawer->setDebugMode(1);
	dynamicsWorld->setDebugDrawer(debugDrawer);
	dynamicsWorld->debugDrawWorld();

	int total = dynamicsWorld->getNumCollisionObjects();
	
	btVector3 g = dynamicsWorld->getGravity();
	printf("g:%f %f %f\n", g.getX(),g.getY(), g.getZ());
	btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[0];
	btRigidBody* body = btRigidBody::upcast(obj);

	btCollisionObject* obj2 = dynamicsWorld->getCollisionObjectArray()[1];
	btRigidBody* xp = btRigidBody::upcast(obj2);
	
	while (true){
		dynamicsWorld->stepSimulation(1/60.f,10);
		std::cout << "position x: " << body->getWorldTransform().getOrigin().getX() << std::endl;
		std::cout << "position y: " << body->getWorldTransform().getOrigin().getY() << std::endl;
		std::cout << "position z: " << body->getWorldTransform().getOrigin().getZ() << std::endl;
		system("PAUSE");
	}

	delete dynamicsWorld;
	delete solver;
	delete collisionConfiguration;
	delete dispatcher;
	delete broadphase;

	return 0;
}
Attachments
test.rar
my test file
(54.25 KiB) Downloaded 284 times
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: problem after reading from .bullet file

Post by Erwin Coumans »

Your attached .bullet file just works fine but Blender is using a different up axis.

Just rotate the world in Blender before exporting, or change the gravity/UP axis in the Bullet demo.
Random#9001
Posts: 10
Joined: Mon Mar 16, 2015 12:59 pm

Re: problem after reading from .bullet file

Post by Random#9001 »

Erwin Coumans wrote:Your attached .bullet file just works fine but Blender is using a different up axis.

Just rotate the world in Blender before exporting, or change the gravity/UP axis in the Bullet demo.
How would one change bullets Up axis in the exporter? Or is it possible to do that in the code itself?
Post Reply