Esempio n. 1
0
	//-------------------------------------------------------------------------------------
	void OgreSimTerrain::createScene(Ogre::SceneManager* sceneMgr, Light* terrainLight)
	{
		mSceneMgr = sceneMgr;

		mTerrainGroup = OGRE_NEW TerrainGroup(mSceneMgr, Terrain::ALIGN_X_Z, mTerrainSize, mTerrainWorldSize);
		mTerrainGroup->setFilenameConvention(TERRAIN_FILE_PREFIX, TERRAIN_FILE_SUFFIX);
		//mTerrainGroup->setOrigin(mTerrainPos);
		mTerrainGroup->setOrigin(mTerrainPos + Ogre::Vector3(mTerrainWorldSize / 2, 0, mTerrainWorldSize / 2));

		// Configure global
		mTerrainGlobals->setMaxPixelError(20); // set to 1 if using 1 unit/1 metre (ie pagesize of 1024)
		//mTerrainGlobals->setCompositeMapDistance(3000);
		mTerrainGlobals->setCompositeMapDistance(100000);
		//mTerrainGlobals->setUseRayBoxDistanceCalculation(true);
		//mTerrainGlobals->getDefaultMaterialGenerator()->setDebugLevel(1);
		mTerrainGlobals->setLightMapSize(256);

		//matProfile->setLightmapEnabled(false);

		// Important to set these so that the terrain knows what to use for derived (non-realtime) data
		mTerrainGlobals->setLightMapDirection(terrainLight->getDerivedDirection());
		mTerrainGlobals->setCompositeMapAmbient(mSceneMgr->getAmbientLight());
		//mTerrainGlobals->setCompositeMapAmbient(ColourValue::Red);
		mTerrainGlobals->setCompositeMapDiffuse(terrainLight->getDiffuseColour());

		// Configure default import settings for if we use imported image
		Terrain::ImportData& defaultimp = mTerrainGroup->getDefaultImportSettings();
		defaultimp.terrainSize = mSnowConfig->terrainSettings.size;
		defaultimp.worldSize = mTerrainWorldSize;
		defaultimp.inputScale = mSnowConfig->terrainSettings.worldScale;
		defaultimp.inputBias = 0;

		defaultimp.minBatchSize = 33;
		defaultimp.maxBatchSize = 65;

		// textures
		TextureLayerFileList diffSpecList = mSnowConfig->terrainSettings.textureLayerDiffSpecFileList;
		TextureLayerFileList normalHeightList = mSnowConfig->terrainSettings.textureLayerNormalHeightFileList;

		size_t textureLayers = std::max(diffSpecList.size(), normalHeightList.size());

		defaultimp.layerList.resize(std::max((size_t)1,textureLayers));
		for(int i = 0; i < textureLayers; i++)
		{
			defaultimp.layerList[i].worldSize =  mTerrainWorldSize;
			if(diffSpecList.size() >= i)
				defaultimp.layerList[i].textureNames.push_back(diffSpecList[i]);

			if(normalHeightList.size() >= i)
				defaultimp.layerList[i].textureNames.push_back(normalHeightList[i]);
		}

		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, mSnowConfig->terrainSettings.flat);

		// sync load since we want everything in place when we start
		mTerrainGroup->loadAllTerrains(false);

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

		mTerrainGroup->freeTemporaryResources();

		// create/show debug normals
		if(mSnowConfig->terrainSettings.showDebugNormals)
		{
			mDebugNormalsManualObject = createDebugNormals(mSceneMgr);
			mDebugNormalsNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
			mDebugNormalsNode->attachObject(mDebugNormalsManualObject);
		}

	}
Esempio n. 2
0
void PGSampleApp::createScene(void)
{
	bool blankTerrain = false;
	mTerrainGlobals = OGRE_NEW TerrainGlobalOptions();

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


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

	mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));


	mTerrainGroup = OGRE_NEW TerrainGroup(mSceneMgr, Terrain::ALIGN_X_Z, TERRAIN_SIZE, TERRAIN_WORLD_SIZE);
	mTerrainGroup->setFilenameConvention(TERRAIN_FILE_PREFIX, TERRAIN_FILE_SUFFIX);
	mTerrainGroup->setOrigin(mTerrainPos + Vector3(TERRAIN_WORLD_SIZE/2, 0, TERRAIN_WORLD_SIZE/2));

	configureTerrainDefaults(l);
#ifdef PAGING
	// 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(mCamera);
	mTerrainPaging = OGRE_NEW TerrainPaging(mPageManager);
	PagedWorld* world = mPageManager->createWorld();
	mTerrainPaging->createWorldSection(world, mTerrainGroup, 2000, 3000, 
		TERRAIN_PAGE_MIN_X, TERRAIN_PAGE_MIN_Y, 
		TERRAIN_PAGE_MAX_X, TERRAIN_PAGE_MAX_Y);
#else
	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
	mTerrainGroup->loadAllTerrains(true);
#endif

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

	mTerrainGroup->freeTemporaryResources();



	// create a few entities on the terrain
	Entity* e = mSceneMgr->createEntity("tudorhouse.mesh");
	Vector3 entPos(mTerrainPos.x + 2043, 0, mTerrainPos.z + 1715);
	Quaternion rot;
	entPos.y = mTerrainGroup->getHeightAtWorldPosition(entPos) + 65.5 + mTerrainPos.y;
	rot.FromAngleAxis(Degree(Math::RangeRandom(-180, 180)), Vector3::UNIT_Y);
	SceneNode* sn = mSceneMgr->getRootSceneNode()->createChildSceneNode(entPos, rot);
	sn->setScale(Vector3(0.12, 0.12, 0.12));
	sn->attachObject(e);
	mHouseList.push_back(e);

	e = mSceneMgr->createEntity("tudorhouse.mesh");
	entPos = Vector3(mTerrainPos.x + 1850, 0, mTerrainPos.z + 1478);
	entPos.y = mTerrainGroup->getHeightAtWorldPosition(entPos) + 65.5 + mTerrainPos.y;
	rot.FromAngleAxis(Degree(Math::RangeRandom(-180, 180)), Vector3::UNIT_Y);
	sn = mSceneMgr->getRootSceneNode()->createChildSceneNode(entPos, rot);
	sn->setScale(Vector3(0.12, 0.12, 0.12));
	sn->attachObject(e);
	mHouseList.push_back(e);

	e = mSceneMgr->createEntity("tudorhouse.mesh");
	entPos = Vector3(mTerrainPos.x + 1970, 0, mTerrainPos.z + 2180);
	entPos.y = mTerrainGroup->getHeightAtWorldPosition(entPos) + 65.5 + mTerrainPos.y;
	rot.FromAngleAxis(Degree(Math::RangeRandom(-180, 180)), Vector3::UNIT_Y);
	sn = mSceneMgr->getRootSceneNode()->createChildSceneNode(entPos, rot);
	sn->setScale(Vector3(0.12, 0.12, 0.12));
	sn->attachObject(e);
	mHouseList.push_back(e);

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


	configureShadows(true, false);

	mCamera->setPosition(mTerrainPos + Vector3(1683, 50, 2116));
	mCamera->lookAt(Vector3(1963, 50, 1660));
	mCamera->setNearClipDistance(0.1);
	mCamera->setFarClipDistance(50000);

	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
    {
        mCamera->setFarClipDistance(0);   // enable infinite far clip distance if we can
    }

}