void OBTutorial2::createBoxShape(Ogre::Entity* entity, Ogre::Vector3 position, bool bStatic)
{

   Ogre::SceneNode *node = entity->getParentSceneNode();
   Vector3 size = node->_getDerivedScale()*entity->getBoundingBox().getHalfSize();
   float mass =  bStatic ? 0.0f : 1.0f;
   srand( (unsigned)time( NULL ) );

   node->setPosition(position);
   node->setOrientation(Quaternion(Degree(Ogre::Math::RangeRandom(0.0,60.0)), Vector3::UNIT_Y));

   btBoxShape *sceneBoxShape = new btBoxShape(toBulletVector(size)); // konvertovat vektor size

   // and the Bullet rigid body
   MyMotionState * defaultMotionState = new MyMotionState(btTransform(btQuaternion(btScalar(0),btScalar(0),btScalar(0),btScalar(1))), node);
   btRigidBody *defaultBody = new btRigidBody(btScalar(1), defaultMotionState, sceneBoxShape);
  /* defaultBody->setShape(node, 
						sceneBoxShape, 
						0.6f,                             // dynamic body restitution
		                0.6f,                             // dynamic body friction
		                mass,                             // dynamic bodymass
		                node->_getDerivedPosition(),      // starting position of the box
		                node->_getDerivedOrientation());  // orientation of the box**/
	mShapes.push_back(sceneBoxShape);
	mBodies.push_back(defaultBody);
	mNumEntitiesInstanced++;				
}
	void PhysicsCharacterController::create( const PhysicsShape& shape, const Vector3& position, float gravity )
	{
		btConvexShape* pShape = static_cast< btConvexShape* >( shape.getNativeShape() );

		btTransform transform;
		transform.setIdentity();
		transform.setOrigin( toBulletVector( position ) );
		
		m_ghostObject.setWorldTransform( transform );
		m_ghostObject.setCollisionShape( pShape );
		m_ghostObject.setCollisionFlags( btCollisionObject::CF_CHARACTER_OBJECT );

		m_controller = btKinematicCharacterController( &m_ghostObject, pShape, 0.35f );
		m_controller.setGravity( gravity );
	}
	void PhysicsCharacterController::move( const Vector3& direction )
	{
		m_controller.setWalkDirection( toBulletVector( direction ) );
	}
//-------------------------------------------------------------------------------------
void OBTutorial2::createScene(void)
{

    mCamera->setPosition(Vector3(0,18,70));
    mCamera->lookAt(Vector3(0,0,-300));
    mCamera->setNearClipDistance(5);

    mSceneMgr->setAmbientLight(Ogre::ColourValue(0.9, 0.9, 0.9));


    // Start Bullet
    mWorld = new btDiscreteDynamicsWorld(mDispatcher,  // gravity vector for Bullet
                                mBroadphase, mSolver, mCollisionConfiguration );
 
    // add Debug info display tool
 	//debugDrawer = new OgreBulletCollisions::DebugDrawer();
 	//debugDrawer->setDrawWireframe(true);	// we want to see the Bullet containers
 
 	//mWorld->setDebugDrawer(debugDrawer);
 	//mWorld->setShowDebugShapes(true);		// enable it if you want to see the Bullet containers
 	//SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("debugDrawer", Ogre::Vector3::ZERO);
 	//node->attachObject(static_cast <SimpleRenderable *> (debugDrawer));
 
    // Define a floor plane mesh
 	Entity *ent;
    Plane p;
    p.normal = Vector3(0,1,0); p.d = 0;
    MeshManager::getSingleton().createPlane("FloorPlane", 
                          ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
                          p, 200000, 200000, 20, 20, true, 1, 9000, 9000, 
                          Vector3::UNIT_Z);
    // Create an entity (the floor)
    ent = mSceneMgr->createEntity("floor", "FloorPlane");
 	ent->setMaterialName("Examples/BumpyMetal");
    mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
 
 	// add collision detection to it
 	btCollisionShape *Shape;
 	Shape = new btStaticPlaneShape(toBulletVector(Ogre::Vector3(0,1,0)), 0); // (normal vector, distance)
 	// a body is needed for the shape
        MyMotionState * defaultMotionState = new MyMotionState(btTransform(btQuaternion(btScalar(0),btScalar(0),btScalar(0),btScalar(1))), ent->getParentSceneNode());
        btRigidBody *defaultBody = new btRigidBody(btScalar(1), defaultMotionState, Shape);
 	btRigidBody *defaultPlaneBody = new btRigidBody(btScalar(0), defaultMotionState, Shape);
 	//defaultPlaneBody->setStaticShape(Shape, 0.1, 0.8);// (shape, restitution, friction)
 	// push the created objects to the deques
 	mShapes.push_back(Shape);
 	mBodies.push_back(defaultPlaneBody);


 	// create an cube mesh
 	Entity *entity = mSceneMgr->createEntity(
 					"Box" + StringConverter::toString(mNumEntitiesInstanced),
 					"cube.mesh");			    
 	entity->setMaterialName("Examples/BumpyMetal");
       Ogre::SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
 	node->attachObject(entity);
 	node->scale(0.05f, 0.05f, 0.05f);	// the cube is too big for us
	createBoxShape(entity, Ogre::Vector3(0.0,0.0,0.0), false);


}