Exemplo n.º 1
0
Wall::Wall() : Mesh ( Engine::PrimitiveManager->request ( P_Cube ) )
{
    _motionState = new btDefaultMotionState;
    _shape = Engine::BoxShapeManager->request ( glm::vec3 ( 1, 1, 1 ) );
    btRigidBody::btRigidBodyConstructionInfo bodyCI ( 0, _motionState, _shape, btVector3 ( 0, 0, 0 ) );
    bodyCI.m_friction = 0.5f;
    bodyCI.m_restitution = 0.2f;
    _body = new btRigidBody ( bodyCI );

    setColor ( glm::vec4 ( 0.3, 0.3, 0.3, 1 ) );
}
Exemplo n.º 2
0
World::World(const char* path_to_script) {
	script = new Script(path_to_script);
	btTriangleIndexVertexArray* tiva;
	mesh = new Mesh(script->GetString("mesh"), tiva);
	texture = new Texture(script->GetString("texture"));

	//btCollisionShape* collisionShape = new btBvhTriangleMeshShape(tiva, false);
	btCollisionShape* collisionShape = new btStaticPlaneShape(btVector3(0, 0, 0), 1);
	btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -1, 0)));
	btScalar mass = 0;
	btVector3 inertia(0, 0, 0);
	collisionShape->calculateLocalInertia(mass, inertia);
	btRigidBody::btRigidBodyConstructionInfo bodyCI(mass, motionState, collisionShape, inertia);
	body = new btRigidBody(bodyCI);
}
Exemplo n.º 3
0
btRigidBody * const Physics::newActor(Actor * const actor)
{

		btVector3 vel = actor->initialVel;
		Physics::MotionState * actorMotion = new Physics::MotionState( btTransform( actor->orientation, actor->pos ), actor);
		motionStates.push_back( actorMotion );
		
		PhysObject const & physObject = actor->physObject;	//grabs physical info about the actor
		
		if(physObject.mass != 0)
			physObject.shape->calculateLocalInertia(physObject.mass, *(physObject.fallInertia) );	//dynamic object so calculate local inertia

		btRigidBody::btRigidBodyConstructionInfo bodyCI(physObject.mass, actorMotion, physObject.shape, *(physObject.fallInertia) );	//TODO this can be shared so stop recreating
		btRigidBody * body = new btRigidBody(bodyCI);
		dynamicsWorld.addRigidBody(body);
		
		body->setLinearVelocity(btVector3(vel.x(),vel.y(), vel.z() ));
		rigidBodies.push_back(body);
		
		return body;
}
Exemplo n.º 4
0
void Physics::newActors(ActorList const & newActors)
{
	for(ActorList::const_iterator itr = newActors.begin(); itr != newActors.end(); ++itr)
	{
		btVector3 vel = (*itr)->initialVel;
		Physics::MotionState * actorMotion = new Physics::MotionState( btTransform( btQuaternion(0,0,0,1), (*itr)->pos ), *itr);
		motionStates.push_back( actorMotion );
		
		PhysObject const & physObject = (*itr)->physObject;	//grabs physical info about the actor
		
		if(physObject.mass != 0)
			physObject.shape->calculateLocalInertia(physObject.mass, *(physObject.fallInertia) );	//dynamic object so calculate local inertia

		btRigidBody::btRigidBodyConstructionInfo bodyCI(physObject.mass, actorMotion, physObject.shape, *(physObject.fallInertia) );	//TODO this can be shared so stop recreating
		btRigidBody * body = new btRigidBody(bodyCI);
		dynamicsWorld.addRigidBody(body);
		
		body->setLinearVelocity(btVector3(vel.getX(),vel.getY(), vel.getZ()));
		rigidBodies.push_back(body);
		
	}
}