CollisionShape for mesh help (Irrlicht)

Post Reply
Dragoon
Posts: 1
Joined: Wed Apr 02, 2014 3:51 pm

CollisionShape for mesh help (Irrlicht)

Post by Dragoon »

Hi, I'm new to Bullet and Irrlicht, I'm trying to set the collision for a mesh I have loaded as a scene node. What is the best way to do this? I have some kind of collision at the moment but it's wrong obviously. The mesh itself is of a maze, it looks like this
Image

Heres my code that loads it, I just modified the Bullet/Irrlicht tutorial so it's probably wrong

Code: Select all

void createMaze(const btVector3& position, const vector3df& scale, float mass)
{
	IMesh* maze = game.getDevice()->getSceneManager()->getMesh("maze.obj");
	IMeshSceneNode* node = game.getDevice()->getSceneManager()->addMeshSceneNode(maze);
	node->setScale(irr::core::vector3df(0.2f, 0.2f, 0.2f));
	node->setMaterialFlag(EMF_LIGHTING, false);
	node->setMaterialTexture(0, game.getDevice()->getVideoDriver()->getTexture("cube.jpg"));

	btTransform transform;
	transform.setIdentity();
	transform.setOrigin(position);

	btDefaultMotionState* motionState = new btDefaultMotionState(transform);

	btVector3 halfExtents(scale.X * 0.5f, scale.Y * 0.5f, scale.Z * 0.5f);
	btCollisionShape* shape = new btBoxShape(halfExtents);

	btVector3 localInertia;
	shape->calculateLocalInertia(mass, localInertia);

	btRigidBody* rigidBody = new btRigidBody(mass, motionState, shape, localInertia);

	PhysicsEntity* physicsEntity = new PhysicsEntity(node);
	physicsEntity->setRigidBody(rigidBody);

	world->addRigidBody(rigidBody);
}
Post Reply