Ejemplo n.º 1
0
Geometry::Geometry()
	: mTerrainGroup(0)
	, mTerrainPaging(0)
	, mPageManager(0)
	, mPagedWorld(0)
	, mTerrainPagedWorldSection(0)
	, mTerrainPos(0, 0, 0) {
		
		setupView();
		m_TrayMgr = InputHandler::getSingleton()->getSdkTrayMgr();
		mInfoLabel = m_TrayMgr->createLabel(OgreBites::TL_TOP, "TInfo", "", 350);

		mTerrainGlobals = OGRE_NEW TerrainGlobalOptions();

		//setDragLook(true);

		MaterialManager::getSingleton().setDefaultTextureFiltering(TFO_ANISOTROPIC);
		MaterialManager::getSingleton().setDefaultAnisotropy(7);

		//OgreTrip::getSceneMgr()->setFog(FOG_LINEAR, ColourValue(0.7, 0.7, 0.8), 0, 4000, 10000);

		LogManager::getSingleton().setLogDetail(LL_BOREME);

		Vector3 lightdir(0.55, -0.3, 0.75);
		lightdir.normalise();

		Light * l = OgreTrip::getSceneMgr()->createLight("tstLight");
		l->setType(Light::LT_DIRECTIONAL);
		l->setDirection(lightdir);
		l->setDiffuseColour(ColourValue::White);
		l->setSpecularColour(ColourValue(0.4, 0.4, 0.4));

		OgreTrip::getSceneMgr()->setAmbientLight(ColourValue(0.5f, 0.5f, 0.5f));

		mTerrainGroup = OGRE_NEW TerrainGroup(OgreTrip::getSceneMgr(), Terrain::ALIGN_X_Z, TERRAIN_SIZE, TERRAIN_WORLD_SIZE);
		mTerrainGroup->setFilenameConvention(ENDLESS_TERRAIN_FILE_PREFIX, ENDLESS_TERRAIN_FILE_SUFFIX);
		mTerrainGroup->setOrigin(mTerrainPos);
		mTerrainGroup->setAutoUpdateLod( TerrainAutoUpdateLodFactory::getAutoUpdateLod(BY_DISTANCE) );

		configureTerrainDefaults(l);

		// Paging setup
		mPageManager = OGRE_NEW PageManager();
		// Since we're not loading any pages from .page files, we need a way just
		// to say we've loaded them without them actually being loaded
		mPageManager->setPageProvider( & mDummyPageProvider);
		mPageManager->addCamera(OgreTrip::getCamera());
		mPageManager->setDebugDisplayLevel(0);
		mTerrainPaging = OGRE_NEW TerrainPaging(mPageManager);
		mPagedWorld = mPageManager->createWorld();
		mTerrainPagedWorldSection = mTerrainPaging->createWorldSection(mPagedWorld, mTerrainGroup, 400, 500,
			ENDLESS_PAGE_MIN_X, ENDLESS_PAGE_MIN_Y,
			ENDLESS_PAGE_MAX_X, ENDLESS_PAGE_MAX_Y);

		//      mPerlinNoiseTerrainGenerator = OGRE_NEW PerlinNoiseTerrainGenerator;
		//      mTerrainPagedWorldSection->setDefiner( mPerlinNoiseTerrainGenerator );
		mTerrainPagedWorldSection->setDefiner( OGRE_NEW SimpleTerrainDefiner );
		TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
		while(ti.hasMoreElements())
		{
			Terrain* t = ti.getNext()->instance;
			initBlendMaps(t);
		}
		mTerrainGroup->freeTemporaryResources();

		OgreTrip::getSceneMgr()->setSkyBox(true, "Examples/CloudyNoonSkyBox");
		


}
Ejemplo n.º 2
0
void begin_terrain(BATB& batb)
{
// http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Basic+Tutorial+3
// http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Ogre+Terrain+System
// libs/ogre/Samples/EndlessWorld/include/EndlessWorld.h

#ifdef USE_SAMPLE_TERRAIN
    if (!Ogre::ResourceGroupManager::getSingleton().resourceGroupExists("Terrain"))
        Ogre::ResourceGroupManager::getSingleton().createResourceGroup("Terrain");
#endif

    // create object, which becomes a singleton
    // Terrain::setResourceGroup overrides this (??)
    terrain_globals = OGRE_NEW TerrainGlobalOptions();


    MaterialManager::getSingleton().setDefaultTextureFiltering(TFO_ANISOTROPIC);
    MaterialManager::getSingleton().setDefaultAnisotropy(7);

#ifdef USE_SAMPLE_ENDLESSWORLD
    scenemgr->setFog(FOG_LINEAR, ColourValue(0.7, 0.7, 0.8), 0, 4000, 10000);
#endif
#ifdef USE_SAMPLE_TERRAIN
    scenemgr->setFog(FOG_LINEAR, ColourValue(0.7, 0.7, 0.8), 0, 10000, 25000); // Terrain
#endif


    //LogManager::getSingleton().setLogDetail(LL_BOREME); // ??

    Vector3 lightdir(0.55, -0.3, 0.75);
    lightdir.normalise();

    Light* l = scenemgr->createLight("tstLight");
    l->setType(Light::LT_DIRECTIONAL);
    l->setDirection(lightdir);
    l->setDiffuseColour(ColourValue::White);
#ifdef USE_SAMPLE_ENDLESSWORLD
    l->setSpecularColour(ColourValue(0.1, 0.1, 0.1));
#endif
#ifdef USE_SAMPLE_TERRAIN
    l->setSpecularColour(ColourValue(0.4, 0.4, 0.4));
#endif

    scenemgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

    terrain_group = OGRE_NEW TerrainGroup(scenemgr, Terrain::ALIGN_X_Z, TERRAIN_SIZE, TERRAIN_WORLD_SIZE);
#ifdef USE_SAMPLE_ENDLESSWORLD
    terrain_group->setFilenameConvention(ENDLESS_TERRAIN_FILE_PREFIX, ENDLESS_TERRAIN_FILE_SUFFIX);
    terrain_group->setAutoUpdateLod( TerrainAutoUpdateLodFactory::getAutoUpdateLod(BY_DISTANCE) );
#endif
#ifdef USE_SAMPLE_TERRAIN
    terrain_group->setFilenameConvention(TERRAIN_FILE_PREFIX, TERRAIN_FILE_SUFFIX);
    terrain_group->setResourceGroup("Terrain");
#endif


////////////////////////////////////////////////////////////////////////////////
// configureTerrainDefaults
//
    // Configure global
    terrain_globals->setMaxPixelError(8);
    // testing composite map
    terrain_globals->setCompositeMapDistance(3000);
    //terrain_globals->setUseRayBoxDistanceCalculation(true);
    terrain_globals->getDefaultMaterialGenerator()->setLightmapEnabled(false);

    terrain_globals->setCompositeMapAmbient(scenemgr->getAmbientLight());
    terrain_globals->setCompositeMapDiffuse(l->getDiffuseColour());    terrain_globals->setLightMapDirection(l->getDerivedDirection());

    // Configure default import settings for if we use imported image
    Terrain::ImportData& defaultimp = terrain_group->getDefaultImportSettings();
    defaultimp.terrainSize = TERRAIN_SIZE;
    defaultimp.worldSize = TERRAIN_WORLD_SIZE;
    defaultimp.inputScale = 600;
    defaultimp.minBatchSize = 33;
    defaultimp.maxBatchSize = 65;
    // textures
    // see 'initBlendMaps' below 
    defaultimp.layerList.resize(3);
    defaultimp.layerList[0].worldSize = 100; // scale layer
    defaultimp.layerList[0].textureNames.push_back("dirt_grayrocky_diffusespecular.dds");
    defaultimp.layerList[0].textureNames.push_back("dirt_grayrocky_normalheight.dds");
    defaultimp.layerList[1].worldSize = 30; // scale layer
    defaultimp.layerList[1].textureNames.push_back("grass_green-01_diffusespecular.dds");
    defaultimp.layerList[1].textureNames.push_back("grass_green-01_normalheight.dds");
    defaultimp.layerList[2].worldSize = 200; // scale layer
    defaultimp.layerList[2].textureNames.push_back("growth_weirdfungus-03_diffusespecular.dds");
    defaultimp.layerList[2].textureNames.push_back("growth_weirdfungus-03_normalheight.dds");
////////////////////////////////////////////////////////////////////////////////

    // Paging setup
#ifndef USE_SAMPLE_TERRAIN
    page_manager = OGRE_NEW PageManager();
    // Since we're not loading any pages from .page files, we need a way just 
    // to say we've loaded them without them actually being loaded
    page_manager->setPageProvider(&dummy_page_provider);
    page_manager->addCamera(camera);
    page_manager->setDebugDisplayLevel(0);
    terrain_paging = OGRE_NEW TerrainPaging(page_manager);
    paged_world = page_manager->createWorld();
    paged_world_section = terrain_paging->createWorldSection(paged_world, terrain_group, 
#ifdef USE_SAMPLE_ENDLESSWORLD
            400, 500, 
            ENDLESS_PAGE_MIN_X, ENDLESS_PAGE_MIN_Y, 
            ENDLESS_PAGE_MAX_X, ENDLESS_PAGE_MAX_Y);
#endif
#ifdef USE_SAMPLE_TERRAIN
            400, 500, 
            ENDLESS_PAGE_MIN_X, ENDLESS_PAGE_MIN_Y, 
            ENDLESS_PAGE_MAX_X, ENDLESS_PAGE_MAX_Y);
            //2000, 3000,
            //TERRAIN_PAGE_MIN_X, TERRAIN_PAGE_MIN_Y,
            //TERRAIN_PAGE_MAX_X, TERRAIN_PAGE_MAX_Y);
#endif
#endif

#ifdef USE_SAMPLE_ENDLESSWORLD
    perlin_noise = OGRE_NEW PerlinNoiseTerrainGenerator( 3.3, 2.2, 10, 128, 0.4 );
    paged_world_section->setDefiner( perlin_noise );
//		paged_world_section->setDefiner( OGRE_NEW SimpleTerrainDefiner );

        TerrainGroup::TerrainIterator ti = terrain_group->getTerrainIterator();
        while(ti.hasMoreElements())
        {
            Terrain* t = ti.getNext()->instance;
            initBlendMaps(t);
        }

#endif
#ifdef USE_SAMPLE_TERRAIN
    bool blankTerrain = false;
    for (long x = TERRAIN_PAGE_MIN_X; x <= TERRAIN_PAGE_MAX_X; ++x)
        for (long y = TERRAIN_PAGE_MIN_Y; y <= TERRAIN_PAGE_MAX_Y; ++y)
            defineTerrain(x, y, blankTerrain);
    // sync load since we want everything in place when we start
    terrain_group->loadAllTerrains(true);
    // ^FIXME:
    //  loadAllTerrains does something to our GL context/state, causing wrong output until
    //  OGRE::output called. the error is caused in OgreTerrainGroup::loadTerrainImpl when
    //  a work request is added to Ogre. The request handler is OgreTerrainGroup, but I 
    //  have not tracked the error there and further down.

    if (terrains_imported)
    {
        TerrainGroup::TerrainIterator ti = terrain_group->getTerrainIterator();
        while(ti.hasMoreElements())
        {
            Terrain* t = ti.getNext()->instance;
            initBlendMaps(t);
        }
    }
#endif

    terrain_group->freeTemporaryResources();

    scenemgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");

#ifdef USE_SAMPLE_TERRAIN
    camera->setPosition(terrain_pos + Vector3(1683, 50, 2116));
    camera->lookAt(Vector3(1963, 50, 1660));
    camera->setNearClipDistance(0.1);
    camera->setFarClipDistance(50000);
#endif
#ifdef USE_SAMPLE_ENDLESSWORLD
    // view
    Vector3 worldCenter(
            (ENDLESS_PAGE_MAX_X+ENDLESS_PAGE_MIN_X) / 2 * TERRAIN_WORLD_SIZE,
            0,
            -(ENDLESS_PAGE_MAX_Y+ENDLESS_PAGE_MIN_Y) / 2 * TERRAIN_WORLD_SIZE
            );
    camera->setPosition(terrain_pos +worldCenter);
    camera->lookAt(terrain_pos);
    camera->setNearClipDistance(0.1);
    camera->setFarClipDistance(50000);

#endif

    if (batb.ogre.ogre_root->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
    {
        camera->setFarClipDistance(0);   // enable infinite far clip distance if we can
    }
               
}