void HeightfieldTerrainApp::addBox()
{
	// This is just a simple function to add some box shapes to our world. We're not
	// creating a corresponding visual object so you'll only be able to see them if
	// you have debug draw working.
	auto box = bt::createBoxShape( vec3( 1.0f ) );
	mRigidBodies.push_back( bt::RigidBody::create( bt::RigidBody::Format()
												  .collisionShape( box )
												  .initialPosition( vec3( randFloat(-5, 5), 10, randFloat(-5, 5) ) )
												  .mass( 1.0f ) ) );
	mContext->addRigidBody( mRigidBodies.back() );
}
void HeightfieldTerrainApp::setupHeightfield()
{
//	mHeightfieldMap = Channel32f( loadImage( loadAsset( "heightfield.jpg" ) ) );
	Perlin perlin( 4, 12 );
	mHeightfieldMap = Channel32f( Width, Depth );
	
	auto minHeight = 0.0f;
	auto maxHeight = 0.0f;
	
	// Now we'll give our Map some Height values.
	for( int y = 0; y < Depth; ++y ) {
		for( int x = 0; x < Width; ++x ) {
			// Now create our heightfield, which is just a two-dimensional array that has
			// a value, height. Instead of this you could easily use Perline to get smoother
			// values or create a black and white image.
			auto val = 25.0f * perlin.fBm( x/float(Depth), y/float(Width) );
			if( val > maxHeight ) maxHeight = val;
			else if ( val < minHeight ) minHeight = val;
			mHeightfieldMap.setValue( ivec2( x, y ), val );
		}
	}
	
	// Create our heightfieldShape with our heightfieldMap and maxHeight and minHeight
	auto heightField = bt::createHeightfieldShape( &mHeightfieldMap, maxHeight, minHeight, vec3( 10 ) );
	heightField->setLocalScaling( bt::toBullet( vec3( 100 ) ) );
	
	// Make our rigidbody out of this collision shape.
	mHeightfieldTerrain = bt::RigidBody::create( bt::RigidBody::Format().collisionShape( heightField ) );
	ci::AxisAlignedBox3f box;
	mHeightfieldTerrain->getAabb( box );
	
	cout << box.getCenter() << endl;
	
	// Collect it in my vector
	mRigidBodies.push_back( mHeightfieldTerrain );
	// And add that rigidbody to the world.
	mContext->addRigidBody( mHeightfieldTerrain );
	
	// Now we can create a batch using the draw helper from bullet which passes back a vboMesh based on our map.
	mBatch = gl::Batch::create( bt::drawableHelpers::getDrawableHeightfield( &mHeightfieldMap ), mPhongShader );
}