Physics not Toppling / Rotating

Post Reply
KarimIO
Posts: 1
Joined: Thu Jul 02, 2015 11:47 am

Physics not Toppling / Rotating

Post by KarimIO »

Hi, I'm working on my first game engine, and I'm new to Bullet, and 3D physics in general. No matter what angle my entities are at, though, they won't rotate normally.

Here's an example. Normally, the object in the image should topple over, but it just stays like that.
http://i.imgur.com/0idqQTH.png?1

Aside from this angle issue, everything is working fine, so I think I may have done something wrong. Here is some of my code; obviously using a components system:

PhysicsSystem.cpp

Code: Select all

PhysicsSystem::PhysicsSystem() {
	broadphase = new btDbvtBroadphase();
	collisionConfiguration = new btDefaultCollisionConfiguration();
	dispatcher = new btCollisionDispatcher(collisionConfiguration);
	solver = new btSequentialImpulseConstraintSolver;
	dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

	dynamicsWorld->setGravity(btVector3(0, -80, 0));
}

void PhysicsSystem::Update(float deltaTime) {
	dynamicsWorld->stepSimulation(deltaTime, 10);
	btTransform trans;
	components[0].rigidBody->getMotionState()->getWorldTransform(trans);
	
	for (size_t i = 0; i < components.size(); i++) {
		components[i].Update();
	}
}
PhysicsComponent.cpp

Code: Select all

void PhysicsComponent::Spawn() {
	btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(parent->angles.x, parent->angles.y, parent->angles.z), btVector3(parent->position.x, parent->position.y, parent->position.z)));
	
	btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(Mass, groundMotionState, shape, Inertia);
	rigidBody = new btRigidBody(fallRigidBodyCI);
	physicsSystem->dynamicsWorld->addRigidBody(rigidBody);
}

void PhysicsComponent::Update() {
	btTransform trans;
	rigidBody->getMotionState()->getWorldTransform(trans);
	parent->position = vec3(trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ());
	parent->angles = vec3(trans.getRotation().getX(), trans.getRotation().getY(), trans.getRotation().getZ());
}
And finally, the creation of the object in my Import.cpp:

Code: Select all

scene->physicsSystem.components.push_back(PhysicsComponent(entity));
physObject = &scene->physicsSystem.components[scene->physicsSystem.components.size() - 1];
physObject->shape = new btBoxShape(btVector3(1, 1, 1));
btScalar mass = 1;
btVector3 fallInertia(0, 0, 0);
physObject->Mass = 1;
physObject->shape->calculateLocalInertia(mass, fallInertia);
physObject->physicsSystem = &scene->physicsSystem;
physObject->Spawn();
If anyone could tell me any solutions, as well as notify me of anything I did wrong in general, that would be great! Thanks in Advance. :D
Post Reply