Beispiel #1
0
        world::world():
            _world(NULL),
            _accum(0),
            _freq(1.0 / 60.0)
        {
            // default to global gravity
            gravity.enabled = true;

            _world = NewtonCreate();
            const float WORLD_SIZE = 1000;
            const vec3 A(-WORLD_SIZE, -WORLD_SIZE, -WORLD_SIZE), B(-A);
            NewtonSetWorldSize(_world, &A.x, &B.x);

            platform(PLAT_OPTMIZED);
            solver(3);
            friction(FRIC_ADAPTIVE);
            threads(2);
            clearCache();

            int mid = NewtonMaterialGetDefaultGroupID(_world);
            // allow bodies to be swept-tested
            NewtonMaterialSetContinuousCollisionMode(_world, mid, mid, 1);
            NewtonMaterialSetCollisionCallback(_world, mid, mid, NULL,
                &beginContactCB, &processContactCB);
        }
Beispiel #2
0
/*
=============
CMod_PhysicsEndBSPCollisionTree
=============
*/
void CMod_PhysicsEndBSPCollisionTree() {
	dVector worldMin, worldMax;
	
	NewtonTreeCollisionEndBuild (g_collision, 1);
	
	dMatrix worldMatrix (GetIdentityMatrix());
	g_rigidBody = NewtonCreateBody (g_world, g_collision);
	NewtonReleaseCollision (g_world, g_collision);
	
	NewtonBodySetMatrix (g_rigidBody, &worldMatrix[0][0]);
	
	NewtonCollisionCalculateAABB (g_collision, &worldMatrix[0][0], &worldMin[0], &worldMax[0]);
	NewtonSetWorldSize (g_world, &worldMin[0], &worldMax[0]);
}
PhysicMap::PhysicMap()
{
    float min[] = {-2000, -2000, -2000};
    float max[] = {2000, 2000, 2000};
    m_world = NewtonCreate(0, 0);
    NewtonSetWorldSize(m_world, min, max);
    NewtonSetSolverModel(m_world, 0);
    NewtonSetFrictionModel(m_world, 0);

    m_mapID = NewtonMaterialCreateGroupID(m_world);
    m_playerID = NewtonMaterialCreateGroupID(m_world);

    NewtonMaterialSetDefaultSoftness(m_world, m_mapID, m_playerID, 0.0f);
	NewtonMaterialSetDefaultElasticity(m_world, m_mapID, m_playerID, 0.2f);
	NewtonMaterialSetDefaultFriction(m_world, m_mapID, m_playerID, 0.5f, 0.0f);

	NewtonMaterialSetDefaultSoftness(m_world, m_playerID, m_playerID, 0.0f);
	NewtonMaterialSetDefaultElasticity(m_world, m_playerID, m_playerID, 0.2f);
	NewtonMaterialSetDefaultFriction(m_world, m_playerID, m_playerID, 0.5f, 0.0f);
}
void CreateScene (NewtonWorld* world, SceneManager* sceneManager)
{
	Entity* floor;
	NewtonCollision* shape;
	NewtonBody* floorBody;
	void* materialManager;
	SoundManager* sndManager;
	PhysicsMaterialInteration matInterations;
	
	sndManager = sceneManager->GetSoundManager();

	// Create the material for this scene, and attach it to the Newton World
	materialManager = CreateMaterialManager (world, sndManager);

	// add the Material table
	matInterations.m_restitution = 0.6f;
	matInterations.m_staticFriction = 0.6f;
	matInterations.m_kineticFriction = 0.3f;
	matInterations.m_scrapingSound = NULL;

	matInterations.m_impactSound = sndManager->LoadSound ("metalMetal.wav");
	AddMaterilInteraction (materialManager, m_metal, m_metal, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("boxBox.wav");
	AddMaterilInteraction (materialManager, m_wood, m_wood, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("metalBox.wav");
	AddMaterilInteraction (materialManager, m_metal, m_wood, &matInterations);
	
	matInterations.m_impactSound = sndManager->LoadSound ("grass0.wav");
	AddMaterilInteraction (materialManager, m_wood, m_grass, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("boxHit.wav");
	AddMaterilInteraction (materialManager, m_wood, m_bricks, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("grass1.wav");
	AddMaterilInteraction (materialManager, m_metal, m_grass, &matInterations);
	AddMaterilInteraction (materialManager, m_grass, m_bricks, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("metal.wav");
	AddMaterilInteraction (materialManager, m_metal, m_bricks, &matInterations);
	AddMaterilInteraction (materialManager, m_grass, m_grass, &matInterations);
	
	

	// Create a large body to be the floor
	floor = sceneManager->CreateEntity();
	floor->LoadMesh ("LevelMesh.dat");

	// add static floor Physics
	int materialMap[] = {m_bricks, m_grass, m_wood,	m_metal};
	shape = CreateMeshCollision (world, floor, materialMap);
	floorBody = CreateRigidBody (world, floor, shape, 0.0f);
	NewtonReleaseCollision (world, shape);


	// set the Transformation Matrix for this rigid body
	dMatrix matrix (floor->m_curRotation, floor->m_curPosition);
	NewtonBodySetMatrix (floorBody, &matrix[0][0]);

	// now we will use the properties of this body to set a proper world size.
	dVector minBox;
	dVector maxBox;
	NewtonCollisionCalculateAABB (shape, &matrix[0][0], &minBox[0], &maxBox[0]);

	// add some extra padding
	minBox.m_x -=  50.0f;
	minBox.m_y -= 500.0f;
	minBox.m_z -=  50.0f;

	maxBox.m_x +=  50.0f;
	maxBox.m_y += 500.0f;
	maxBox.m_z +=  50.0f;

	// set the new world size
	NewtonSetWorldSize (world, &minBox[0], &maxBox[0]);

	// add some visual entities.
	dFloat y0 = FindFloor (world, 0.0f, 0.0f) + 10.0f;
	for (int i = 0; i < 5; i ++) {
		Entity* smilly;
		NewtonBody* smillyBody;
		smilly = sceneManager->CreateEntity();
		smilly->LoadMesh ("Smilly.dat");
		smilly->m_curPosition.m_y = y0;
		y0 += 2.0f;
		smilly->m_prevPosition = smilly->m_curPosition;

		// add a body with a box shape
		shape = CreateNewtonBox (world, smilly, m_metal);
		smillyBody = CreateRigidBody (world, smilly, shape, 10.0f);
		NewtonReleaseCollision (world, shape);
	}

	// add some visual entities.
	y0 = FindFloor (world, 0.0f, 0.4f) + 10.5f;
	for (int i = 0; i < 5; i ++) {
		Entity* frowny;
		NewtonBody* frownyBody;
		frowny = sceneManager->CreateEntity();
		frowny->LoadMesh ("Frowny.dat");
		frowny->m_curPosition.m_z = 0.4f;
		frowny->m_curPosition.m_y = y0;
		y0 += 2.0f;
		frowny->m_prevPosition = frowny->m_curPosition;

		// add a body with a Convex hull shape
		shape = CreateNewtonConvex (world, frowny, m_wood);
		frownyBody = CreateRigidBody (world, frowny, shape, 10.0f);
		NewtonReleaseCollision (world, shape);
	}

	y0 = FindFloor (world, 0.0f, 2.0f) + 10.5f;
	for (int i = 0; i < 5; i ++) {
		Entity* frowny;
		NewtonBody* frownyBody;

		frowny = sceneManager->CreateEntity();
		frowny->LoadMesh ("dumb.dat");
		frowny->m_curPosition.m_z = 2.0f;
		frowny->m_curPosition.m_y = y0;
		y0 += 2.0f;
		frowny->m_prevPosition = frowny->m_curPosition;

		// add a body with a Convex hull shape
		int materialMap[] = {m_grass, m_wood, m_metal, m_metal};
		shape = CreateNewtonCompoundFromEntitySubmesh (world, frowny, materialMap);
		frownyBody = CreateRigidBody (world, frowny, shape, 10.0f);
		NewtonReleaseCollision (world, shape);
	}


	// set the Camera EyePoint close to the scene action
	InitCamera (dVector (-15.0f, FindFloor (world, -15.0f, 0.0f) + 5.0f, 0.0f), dVector (1.0f, 0.0f, 0.0f));
}
void CreateScene (NewtonWorld* world, SceneManager* sceneManager)
{
	Entity* floor;
	Entity* smilly;
	Entity* frowny;
	NewtonBody* floorBody;
	NewtonBody* smillyBody;
	NewtonBody* frownyBody;
	NewtonCollision* shape;

	// Create the material for this scene
	CreateMateials (world, sceneManager);

	// Create a large body to be the floor
	floor = sceneManager->CreateEntity();

	// add scene collision from a level mesh
	shape = CreateHeightFieldCollision (world, "h2.raw", 0);
	floorBody = CreateRigidBody (world, floor, shape, 0.0f);
	NewtonReleaseCollision (world, shape);

	// make a visual mesh for the collision data
	CreateHeightFieldMesh (shape, floor);

	// set the matrix at the origin
	dVector boxP0; 
	dVector boxP1; 
	dMatrix matrix (floor->m_curRotation, floor->m_curPosition);
	NewtonCollisionCalculateAABB (shape, &matrix[0][0], &boxP0.m_x, &boxP1.m_x); 

	// place the origin of the visual mesh at the center of the height field
	matrix.m_posit = (boxP0 + boxP1).Scale (-0.5f);
	matrix.m_posit.m_w = 1.0f;
	floor->m_curPosition = matrix.m_posit;
	floor->m_prevPosition = matrix.m_posit;

	// relocate the body;
	NewtonBodySetMatrix (floorBody, &matrix[0][0]);

	// now we will use the properties of this body to set a proper world size.
	NewtonCollisionCalculateAABB (shape, &matrix[0][0], &boxP0.m_x, &boxP1.m_x); 

	// add some extra padding
	boxP0.m_x -=  50.0f;
	boxP0.m_y -= 500.0f;
	boxP0.m_z -=  50.0f;

	boxP1.m_x +=  50.0f;
	boxP1.m_y += 500.0f;
	boxP1.m_z +=  50.0f;

	// set the new world size
	NewtonSetWorldSize (world, &boxP0[0], &boxP1[0]);


	// assign an Material ID to this body
	NewtonBodySetMaterialGroupID (floorBody, g_floorMaterial);


	// add some visual entities.
	dFloat y0 = FindFloor (world, 0.0f, 0.0f) + 10.0f;
	for (int i = 0; i < 5; i ++) {
		smilly = sceneManager->CreateEntity();
		smilly->LoadMesh ("Smilly.dat");
		smilly->m_curPosition.m_y = y0;
		y0 += 2.0f;
		smilly->m_prevPosition = smilly->m_curPosition;

		// add a body with a box shape
		shape = CreateNewtonBox (world, smilly, 0);
		smillyBody = CreateRigidBody (world, smilly, shape, 10.0f);
		NewtonReleaseCollision (world, shape);

		// assign an Material ID to this body
		NewtonBodySetMaterialGroupID (smillyBody, g_metalMaterial);
	}


	// add some visual entities.
	y0 = FindFloor (world, 0.0f, 0.4f) + 10.5f;
	for (int i = 0; i < 5; i ++) {
		frowny = sceneManager->CreateEntity();
		frowny->LoadMesh ("Frowny.dat");
		frowny->m_curPosition.m_z = 0.4f;
		frowny->m_curPosition.m_y = y0;
		y0 += 2.0f;
		frowny->m_prevPosition = frowny->m_curPosition;

		// add a body with a Convex hull shape
		shape = CreateNewtonConvex (world, frowny, 0);
		frownyBody = CreateRigidBody (world, frowny, shape, 10.0f);
		NewtonReleaseCollision (world, shape);

		// assign an Material ID to this body
		NewtonBodySetMaterialGroupID (frownyBody, g_woodMaterial);
	}

	// set the Camera EyePoint close to the scene action
	InitCamera (dVector (-15.0f, FindFloor (world, -15.0f, 0.0f) + 5.0f, 0.0f), dVector (1.0f, 0.0f, 0.0f));
}
Beispiel #6
0
void World::setWorldSize( const Ogre::AxisAlignedBox& box )
{
    NewtonSetWorldSize( m_world, (float*)&box.getMinimum(), (float*)&box.getMaximum() );
    m_limits = box;
}
Beispiel #7
0
void World::setWorldSize( const Ogre::Vector3& min, const Ogre::Vector3& max )
{
    NewtonSetWorldSize( m_world, (float*)&min.x, (float*)&max.x );
    m_limits = Ogre::AxisAlignedBox(min, max);
}
Beispiel #8
0
void CreateScene (NewtonWorld* world, SceneManager* sceneManager)
{
	Entity* floor;
	Entity* smilly;
	Entity* frowny;
	NewtonBody* floorBody;
	NewtonBody* smillyBody;
	NewtonBody* frownyBody;
	NewtonCollision* shape;



////////////////////////////////////////////////////////////////////////////////
// STATIC BODY 1 - FLOOR 
////////////////////////////////////////////////////////////////////////////////

	// Create a large body to be the floor
	floor = sceneManager->CreateEntity();
	floor->LoadMesh ("FloorBox.dat");
 
	// add static floor Physics
	shape = CreateNewtonBox (world, floor, 0);
	floorBody = CreateRigidBody (world, floor, shape, 0.0f);
	NewtonReleaseCollision (world, shape);
 
	// set the Transformation Matrix for this rigid body
	dMatrix matrix (floor->m_curRotation, floor->m_curPosition);
	NewtonBodySetMatrix (floorBody, &matrix[0][0]);
 
	// now we will use the properties of this body to set a proper world size.
	dVector minBox;
	dVector maxBox;
	NewtonCollisionCalculateAABB (shape, &matrix[0][0], &minBox[0], &maxBox[0]);
 
	// add some extra padding
	minBox.m_x -=  50.0f;
	minBox.m_y -= 500.0f;
	minBox.m_z -=  50.0f;
 
	maxBox.m_x +=  50.0f;
	maxBox.m_y += 500.0f;
	maxBox.m_z +=  50.0f;
 
	// set the new world size
	NewtonSetWorldSize (world, &minBox[0], &maxBox[0]);


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////




 
////////////////////////////////////////////////////////////////////////////////
// DYNAMIC BODY 1
////////////////////////////////////////////////////////////////////////////////
 
	// add some visual entities.
	smilly = sceneManager->CreateEntity();
	smilly->LoadMesh ("Smilly.dat");
	smilly->m_curPosition.m_y = 10.0f;
	smilly->m_prevPosition = smilly->m_curPosition;
 
	// add a body with a box shape
	shape = CreateNewtonBox (world, smilly, 0);
	smillyBody = CreateRigidBody (world, smilly, shape, 10.0f);
	NewtonReleaseCollision (world, shape);
 
 
////////////////////////////////////////////////////////////////////////////////
// DYNAMIC BODY 2
////////////////////////////////////////////////////////////////////////////////
 
	// add some visual entities.
	frowny = sceneManager->CreateEntity();
	frowny->LoadMesh ("Frowny.dat");
	frowny->m_curPosition.m_z = 0.4f;
	frowny->m_curPosition.m_y = 10.0f + 0.4f;
	frowny->m_prevPosition = frowny->m_curPosition;
 
	// add a body with a Convex hull shape
	shape = CreateNewtonConvex (world, frowny, 0);
	frownyBody = CreateRigidBody (world, frowny, shape, 10.0f);
	NewtonReleaseCollision (world, shape);
}
void CreateScene (NewtonWorld* world, SceneManager* sceneManager)
{
	Entity* floor;
	NewtonBody* floorBody;
	NewtonCollision* shape;
	void* materialManager;
	SoundManager* sndManager;
	PhysicsMaterialInteration matInterations;

	sndManager = sceneManager->GetSoundManager();

	// Create the material for this scene, and attach it to the Newton World
	materialManager = CreateMaterialManager (world, sndManager);

	// add the Material table
	matInterations.m_restitution = 0.6f;
	matInterations.m_staticFriction = 0.6f;
	matInterations.m_kineticFriction = 0.3f;
	matInterations.m_scrapingSound = NULL;

	matInterations.m_impactSound = sndManager->LoadSound ("metalMetal.wav");
	AddMaterilInteraction (materialManager, m_metal, m_metal, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("boxBox.wav");
	AddMaterilInteraction (materialManager, m_wood, m_wood, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("metalBox.wav");
	AddMaterilInteraction (materialManager, m_metal, m_wood, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("grass0.wav");
	AddMaterilInteraction (materialManager, m_wood, m_grass, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("boxHit.wav");
	AddMaterilInteraction (materialManager, m_wood, m_bricks, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("grass1.wav");
	AddMaterilInteraction (materialManager, m_metal, m_grass, &matInterations);

	matInterations.m_impactSound = sndManager->LoadSound ("metal.wav");
	AddMaterilInteraction (materialManager, m_metal, m_bricks, &matInterations);


	// Create a large body to be the floor
	floor = sceneManager->CreateEntity();

	// add scene collision from a level mesh
	int materialMap[] = {m_bricks, m_grass, m_wood,	m_metal};
	shape = CreateHeightFieldCollision (world, "h2.raw", materialMap);
	floorBody = CreateRigidBody (world, floor, shape, 0.0f);
	NewtonDestroyCollision(shape);

	// make a visual mesh for the collision data
	CreateHeightFieldMesh (shape, floor);

	// set the matrix at the origin
	dVector boxP0; 
	dVector boxP1; 
	dMatrix matrix (floor->m_curRotation, floor->m_curPosition);
	NewtonCollisionCalculateAABB (shape, &matrix[0][0], &boxP0.m_x, &boxP1.m_x); 

	// place the origin of the visual mesh at the center of the height field
	matrix.m_posit = (boxP0 + boxP1).Scale (-0.5f);
	matrix.m_posit.m_w = 1.0f;
	floor->m_curPosition = matrix.m_posit;
	floor->m_prevPosition = matrix.m_posit;

	// relocate the body;
	NewtonBodySetMatrix (floorBody, &matrix[0][0]);

	// now we will use the properties of this body to set a proper world size.
	NewtonCollisionCalculateAABB (shape, &matrix[0][0], &boxP0.m_x, &boxP1.m_x); 

	// add some extra padding
	boxP0.m_x -=  50.0f;
	boxP0.m_y -= 500.0f;
	boxP0.m_z -=  50.0f;

	boxP1.m_x +=  50.0f;
	boxP1.m_y += 500.0f;
	boxP1.m_z +=  50.0f;

	// set the new world size
	NewtonSetWorldSize (world, &boxP0[0], &boxP1[0]);


	// add some visual entities.
	dFloat y0 = FindFloor (world, 0.0f, 0.0f) + 2.0f;
	for (int i = 0; i < 1; i ++) {
		Entity* carEnt;
		NewtonBody* carBody;
		NewtonUserJoint* carController;

		carEnt = sceneManager->CreateEntity();
		carEnt->LoadMesh ("porche.dat");
		carEnt->m_curPosition.m_y = y0;
		y0 += 2.0f;
		carEnt->m_prevPosition = carEnt->m_curPosition;

		// add a body with a box shape
		shape = CreateNewtonBox (world, carEnt, m_metal);
		// the mass is the Car weight divide by the Gravity 
		carBody = CreateRigidBody (world, carEnt, shape, CAR_WEIGHT / 10.0f);
		NewtonDestroyCollision(shape);

		// Now create a RayCast Car for to control this body
		carController = CreateRayCastCast (carBody, sceneManager, porcheTirePositions);
	}


	y0 = FindFloor (world, 4.0f, 0.0f) + 2.0f;
	for (int i = 0; i < 1; i ++) {
		Entity* carEnt;
		NewtonBody* carBody;
		NewtonUserJoint* carController;

		carEnt = sceneManager->CreateEntity();
		carEnt->LoadMesh ("cadillac.dat");
		carEnt->m_curPosition.m_z = 4.0f;
		carEnt->m_curPosition.m_y = y0;
		y0 += 2.0f;
		carEnt->m_prevPosition = carEnt->m_curPosition;

		// add a body with a box shape
		shape = CreateNewtonBox (world, carEnt, m_metal);
		// the mass is the Car weight divide by the Gravity 
		carBody = CreateRigidBody (world, carEnt, shape, CAR_WEIGHT / 10.0f);
		NewtonDestroyCollision(shape);

		// Now create a RayCast Car for to control this body
		carController = CreateRayCastCast (carBody, sceneManager, cadillackirePositions);
	}

	// initialize the camera
	InitCamera (dVector (-15.0f, FindFloor (world, -15.0f, 0.0f) + 5.0f, 0.0f), dVector (1.0f, 0.0f, 0.0f));
}
bool Physics::buildStaticGeometry( osg::Group* p_root, const std::string& levelFile )
{
    NewtonCollision* p_collision = NULL;

    // check if a serialization file exists, if so then load it. otherwise build the static geometry on the fly.
    assert( levelFile.length() && "internal error: missing levelFile name!" );
    std::string file = cleanPath( levelFile );
    std::vector< std::string > path;
    explode( file, "/", &path );
    file = yaf3d::Application::get()->getMediaPath() + YAF3DPHYSICS_MEDIA_FOLDER + path[ path.size() - 1 ] + YAF3DPHYSICS_SERIALIZE_POSTFIX;
    std::ifstream serializationfile;
    serializationfile.open( file.c_str(), std::ios_base::binary | std::ios_base::in );
    if ( !serializationfile )
    {
        log_warning << "Physics: no serialization file for physics static geometry exists, building on-the-fly ..." << std::endl;

        p_collision = NewtonCreateTreeCollision( _p_world, levelCollisionCallback );
        NewtonTreeCollisionBeginBuild( p_collision );

        // build the collision faces
        //--------------------------
        // start timer
        osg::Timer_t start_tick = osg::Timer::instance()->tick();
        //! iterate through all geometries and create their collision faces
        PhysicsVisitor physVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN, p_collision );
        p_root->accept( physVisitor );
        // stop timer and give out the time messure
        osg::Timer_t end_tick = osg::Timer::instance()->tick();
        log_debug << "Physics: elapsed time for building physics collision faces = "<< osg::Timer::instance()->delta_s( start_tick, end_tick ) << std::endl;
        log_debug << "Physics:  total num of evaluated primitives: " << physVisitor.getNumPrimitives() << std::endl;
        log_debug << "Physics:  total num of vertices: " << physVisitor.getNumVertices() << std::endl;

        //--------------------------
        // finalize tree building with optimization off ( because the meshes are already optimized by
        //  osg _and_ Newton has currently problems with optimization )
        NewtonTreeCollisionEndBuild( p_collision, 0 /* 1 */);
    }
    else
    {
        log_debug << "Physics: loading serialization file for physics static geometry: '" << file << "' ..." << std::endl;

        // start timer
        osg::Timer_t start_tick = osg::Timer::instance()->tick();

        p_collision = NewtonCreateTreeCollisionFromSerialization( _p_world, NULL, deserializationCallback, &serializationfile );
        assert( p_collision && "internal error, something went wrong during physics deserialization!" );

        // stop timer and give out the time messure
        osg::Timer_t end_tick = osg::Timer::instance()->tick();
        log_debug << "Physics: elapsed time for deserializing physics collision faces = "<< osg::Timer::instance()->delta_s( start_tick, end_tick ) << std::endl;

        serializationfile.close();
    }

    _p_body = NewtonCreateBody( _p_world, p_collision );

    // release collision object
    NewtonReleaseCollision( _p_world, p_collision );

    // set Material Id for this object
    NewtonBodySetMaterialGroupID( _p_body, getMaterialId( "level" ) );

    osg::Matrixf mat;
    mat.identity();
    NewtonBodySetMatrix( _p_body, mat.ptr() );

    // calculate the world bbox and world size
    float  bmin[ 4 ], bmax[ 4 ];
    NewtonCollisionCalculateAABB( p_collision, mat.ptr(), bmin, bmax );
    bmin[ 0 ] -= 10.0f;
    bmin[ 1 ] -= 10.0f;
    bmin[ 2 ] -= 10.0f;
    bmin[ 3 ] = 1.0f;
    bmax[ 0 ] += 10.0f;
    bmax[ 1 ] += 10.0f;
    bmax[ 2 ] += 10.0f;
    bmax[ 3 ] = 1.0f;
    NewtonSetWorldSize( _p_world, bmin, bmax );

    return true;
}
void CreateScene (NewtonWorld* world, SceneManager* sceneManager)
{
    Entity* floor;
    NewtonBody* floorBody;
    NewtonCollision* shape;

    /*
    	void* materialManager;
    	SoundManager* sndManager;
    	PhysicsMaterialInteration matInterations;

    	sndManager = sceneManager->GetSoundManager();

    	// Create the material for this scene, and attach it to the Newton World
    	materialManager = CreateMaterialManager (world, sndManager);

    	// add the Material table
    	matInterations.m_restitution = 0.6f;
    	matInterations.m_staticFriction = 0.6f;
    	matInterations.m_kineticFriction = 0.3f;
    	matInterations.m_scrapingSound = NULL;

    	matInterations.m_impactSound = sndManager->LoadSound ("metalMetal.wav");
    	AddMaterilInteraction (materialManager, m_metal, m_metal, &matInterations);

    	matInterations.m_impactSound = sndManager->LoadSound ("boxBox.wav");
    	AddMaterilInteraction (materialManager, m_wood, m_wood, &matInterations);

    	matInterations.m_impactSound = sndManager->LoadSound ("metalBox.wav");
    	AddMaterilInteraction (materialManager, m_metal, m_wood, &matInterations);

    	matInterations.m_impactSound = sndManager->LoadSound ("grass0.wav");
    	AddMaterilInteraction (materialManager, m_wood, m_grass, &matInterations);

    	matInterations.m_impactSound = sndManager->LoadSound ("boxHit.wav");
    	AddMaterilInteraction (materialManager, m_wood, m_bricks, &matInterations);

    	matInterations.m_impactSound = sndManager->LoadSound ("grass1.wav");
    	AddMaterilInteraction (materialManager, m_metal, m_grass, &matInterations);

    	matInterations.m_impactSound = sndManager->LoadSound ("metal.wav");
    	AddMaterilInteraction (materialManager, m_metal, m_bricks, &matInterations);
    */


    // Create a large body to be the floor
    floor = sceneManager->CreateEntity();
    int materialMap[] = {m_bricks, m_grass, m_wood,	m_metal};

#ifdef USE_HEIGHT_FIELD_LEVEL

    // add scene collision from a level m*esh
    shape = CreateHeightFieldCollision (world, "h2.raw", materialMap);
    floorBody = CreateRigidBody (world, floor, shape, 0.0f);
    NewtonDestroyCollision(shape);

    // make a visual mesh for the collision data
    CreateHeightFieldMesh (shape, floor);

    // set the matrix at the origin
    dVector boxP0;
    dVector boxP1;
    dMatrix matrix (floor->m_curRotation, floor->m_curPosition);
    NewtonCollisionCalculateAABB (shape, &matrix[0][0], &boxP0.m_x, &boxP1.m_x);

    // place the origin of the visual mesh at the center of the height field
    matrix.m_posit = (boxP0 + boxP1).Scale (-0.5f);
    matrix.m_posit.m_w = 1.0f;
    floor->m_curPosition = matrix.m_posit;
    floor->m_prevPosition = matrix.m_posit;

    // relocate the body;
    NewtonBodySetMatrix (floorBody, &matrix[0][0]);

#else

    floor->LoadMesh ("LevelMesh.dat");

    // add static floor Physics

    shape = CreateMeshCollision (world, floor, materialMap);
    floorBody = CreateRigidBody (world, floor, shape, 0.0f);
    NewtonDestroyCollision(shape);

    // set the Transformation Matrix for this rigid body
    dMatrix matrix (floor->m_curRotation, floor->m_curPosition);
    NewtonBodySetMatrix (floorBody, &matrix[0][0]);

#endif

    // now we will use the properties of this body to set a proper world size.
    dVector minBox;
    dVector maxBox;
    NewtonCollisionCalculateAABB (shape, &matrix[0][0], &minBox[0], &maxBox[0]);

    // add some extra padding
    minBox.m_x -=  50.0f;
    minBox.m_y -= 500.0f;
    minBox.m_z -=  50.0f;

    maxBox.m_x +=  50.0f;
    maxBox.m_y += 500.0f;
    maxBox.m_z +=  50.0f;

    // set the new world size
    NewtonSetWorldSize (world, &minBox[0], &maxBox[0]);


    // Create a Body and attach a player controller joint
    {
        dFloat y0;
        Entity* player;
        NewtonBody* playerBody;
        NewtonCollision* shape;

        // find  the a floor to place the player
        y0 = FindFloor (world, 0.0f, 0.0f) + 1.0f;

        // load the player mesh
        player = sceneManager->CreateEntity();
        player->LoadMesh ("gymnast.dat");
        player->m_curPosition.m_y = y0;
        player->m_prevPosition = player->m_curPosition;

        // get the bounding Box of the player to get the collision shape dimensions
        dVector minBox;
        dVector maxBox;
        player->GetBBox (minBox, maxBox);

        // calculate player high and width
        dFloat padding = 1.0f / 64.0f;  // this si the default padding, for teh palye joint, we must subtract it from the shape
        dFloat playerHigh = (maxBox.m_y - minBox.m_y) - padding;
        dFloat playerRadius0 = (maxBox.m_z - minBox.m_z) * 0.5f;
        dFloat playerRadius1 = (maxBox.m_x - minBox.m_x) * 0.5f;
        dFloat playerRadius = (playerRadius0 > playerRadius1 ? playerRadius0 : playerRadius1) - padding;

        // No we make and make a upright capsule for the collision mesh
        dMatrix orientation;
        orientation.m_front = dVector (0.0f, 1.0f, 0.0f, 0.0f);			// this is the player up direction
        orientation.m_up    = dVector (1.0f, 0.0f, 0.0f, 0.0f);			// this is the player front direction
        orientation.m_right = orientation.m_front * orientation.m_up;   // this is the player sideway direction
        orientation.m_posit = dVector (0.0f, 0.0f, 0.0f, 1.0f);

        // add a body with a box shape
        //shape = CreateNewtonCapsule (world, player, playerHigh, playerRadius, m_wood, orientation);
        shape = CreateNewtonCylinder (world, player, playerHigh, playerRadius, m_wood, orientation);
        playerBody = CreateRigidBody (world, player, shape, 10.0f);
        NewtonDestroyCollision(shape);

        // make sure the player does not go to sleep
        NewtonBodySetAutoSleep (playerBody, 0);

        // now we will attach a player controller to the body
        NewtonUserJoint* playerController;
        // the player can take step up to 0.7 units;
        dFloat maxStairStepFactor = 0.7f / playerHigh;
        playerController = CreateCustomPlayerController (&orientation[0][0], playerBody, maxStairStepFactor, padding);

        // set the Max Slope the player can climb to PLAYER_MAX_SLOPE degree
        CustomPlayerControllerSetMaxSlope (playerController, PLAYER_MAX_SLOPE * 3.1416f / 180.0f);


        // now we will append some application data for the application to control the player
        PlayerController* userControl = (PlayerController*) malloc (sizeof (PlayerController));
        userControl->m_isThirdView = 1;
        userControl->m_point = dVector (0.0f, playerHigh, 0.0f,0.0f);

        // set the user data for the application to control the player
        CustomSetUserData (playerController, userControl);

        // set the destruction call back so that the application can destroy local used data
        CustomSetDestructorCallback (playerController, PlayerController::Destroy);

        // set a call back to control the player
        CustomSetSubmitContraintCallback (playerController, PlayerController::ApplyPlayerInput);

        // we also need to set override the transform call back so the we can set the Camera
        userControl->m_setTransformOriginal = NewtonBodyGetTransformCallback(playerBody);
        NewtonBodySetTransformCallback (playerBody, PlayerController::SetTransform);

        // we will need some ID to fin this joint in the transform Callback
        CustomSetJointID (playerController, PLAYER_JOINT_ID);
    }

    /*
    	{
    		// add some visual entities.
    		dFloat y0;
    		y0 = FindFloor (world, 0.0f, 0.4f) + 10.5f;
    		for (int i = 0; i < 5; i ++) {
    			Entity* frowny;
    			NewtonBody* frownyBody;
    			NewtonCollision* shape;

    			frowny = sceneManager->CreateEntity();
    			frowny->LoadMesh ("Frowny.dat");
    			frowny->m_curPosition.m_z = 0.4f;
    			frowny->m_curPosition.m_y = y0;
    			y0 += 2.0f;
    			frowny->m_prevPosition = frowny->m_curPosition;

    			// add a body with a Convex hull shape
    			shape = CreateNewtonConvex (world, frowny, m_wood);
    			frownyBody = CreateRigidBody (world, frowny, shape, 10.0f);
    			NewtonDestroyCollision(shape);
    		}
    	}
    */
    // set the Camera EyePoint close to the scene action
    SetCameraEyePoint (dVector (-15.0f, FindFloor (world, -15.0f, 0.0f) + 5.0f, 0.0f));
}