void TerrainManager::createTerrain(Ogre::Light* light) { mTerrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions(); mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(mSceneMgr, Ogre::Terrain::ALIGN_X_Z, 513, 12000.0f); mTerrainGroup->setFilenameConvention(Ogre::String("BasicTutorial3Terrain"), Ogre::String("dat")); mTerrainGroup->setOrigin(mTerrainPos); mTerrainGroup->setTerrainWorldSize(8000); mTerrainGroup->setTerrainSize(513); configureTerrainDefaults(light); for (long x = 0; x <= 0; ++x) for (long y = 0; y <= 0; ++y) defineTerrain(x, y); // sync load since we want everything in place when we start mTerrainGroup->loadAllTerrains(true); if (mTerrainsImported) { Ogre::TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; initBlendMaps(t); } } mTerrainGroup->freeTemporaryResources(); }
CTerrain::CTerrain(Ogre::SceneManager* sceneMgr, std::list<Logic::CTerrainTile*>* terrainList, Logic::CGridMap* terrainMap) { _sceneMgr = sceneMgr; _terrainMap = terrainMap; _worldSize = _terrainMap->getMapSize(); _mapSize = 129.0f; _terrainsImported = false; _nTerrains = terrainList->size(); _terrainList = new Logic::CTerrainTile*[_nTerrains]; int i = 0; std::list<Logic::CTerrainTile*>::iterator terrain_tile = terrainList->begin(); for (int i = 0; i < _nTerrains; ++i) { _terrainList[i] = (*terrain_tile); ++terrain_tile; } Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC); Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(7); // TerrainSystem initialization.. printf("Terrain: Creating new terrain.\n"); _terrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions(); _terrainGroup = OGRE_NEW Ogre::TerrainGroup(_sceneMgr, Ogre::Terrain::ALIGN_X_Z, _mapSize, _worldSize); _terrainGroup->setFilenameConvention(Ogre::String("DamnedSunsetTerrain"), Ogre::String("dat")); _terrainGroup->setOrigin(Ogre::Vector3::ZERO); configureTerrainDefaults(); for (long x = 0; x <= 0; ++x) for (long y = 0; y <= 0; ++y) defineTerrain(x, y); // sync load since we want everything in place when we start _terrainGroup->loadAllTerrains(true); if (_terrainsImported) { printf("Terrain: terrain imported, blending it.\n"); Ogre::TerrainGroup::TerrainIterator ti = _terrainGroup->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; initBlendMaps(t); } } _terrainGroup->freeTemporaryResources(); while (_terrainGroup->isDerivedDataUpdateInProgress()); _terrainGroup->saveAllTerrains(true); configureShadows(); } // CTerrain
//------------------------------------------------------------------------------------- void BasicTutorial3::createScene(void) { mCamera->setPosition(Ogre::Vector3(1683, 50, 2116)); mCamera->lookAt(Ogre::Vector3(1963, 50, 1660)); mCamera->setNearClipDistance(0.1); mCamera->setFarClipDistance(50000); if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(Ogre::RSC_INFINITE_FAR_PLANE)) { mCamera->setFarClipDistance(0); // enable infinite far clip distance if we can } Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC); Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(7); Ogre::Vector3 lightdir(0.55, -0.3, 0.75); lightdir.normalise(); Ogre::Light* light = mSceneMgr->createLight("tstLight"); light->setType(Ogre::Light::LT_DIRECTIONAL); light->setDirection(lightdir); light->setDiffuseColour(Ogre::ColourValue::White); light->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4)); mSceneMgr->setAmbientLight(Ogre::ColourValue(0.2, 0.2, 0.2)); mTerrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions(); mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(mSceneMgr, Ogre::Terrain::ALIGN_X_Z, 513, 12000.0f); mTerrainGroup->setFilenameConvention(Ogre::String("BasicTutorial3Terrain"), Ogre::String("dat")); mTerrainGroup->setOrigin(Ogre::Vector3::ZERO); configureTerrainDefaults(light); for (long x = 0; x <= 0; ++x) for (long y = 0; y <= 0; ++y) defineTerrain(x, y); // sync load since we want everything in place when we start mTerrainGroup->loadAllTerrains(true); if (mTerrainsImported) { Ogre::TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; initBlendMaps(t); } } mTerrainGroup->freeTemporaryResources(); }
TerrainGenerator::TerrainGenerator(Ogre::SceneManager *scene) : terrains_imported_(false), scene_manager_(scene) { /*mCamera->setPosition(Ogre::Vector3(1683, 50, 2116)); mCamera->lookAt(Ogre::Vector3(1963, 50, 1660)); mCamera->setNearClipDistance(0.1); mCamera->setFarClipDistance(50000);*/ Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC); Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(7); Ogre::Light* light = scene_manager_->createLight("tstLight"); light->setDiffuseColour(Ogre::ColourValue::White); light->setSpecularColour(Ogre::ColourValue(1, 1, 1)); scene_manager_->setAmbientLight(Ogre::ColourValue(0.9, 0.9, 0.9)); light->setAttenuation(100000, 1, 1, 1); terrain_globals_ = OGRE_NEW Ogre::TerrainGlobalOptions(); terrain_group_ = OGRE_NEW Ogre::TerrainGroup(scene_manager_, Ogre::Terrain::ALIGN_X_Z, 513, 12000.0f); terrain_group_->setFilenameConvention(Ogre::String("BasicTutorial3Terrain"), Ogre::String("dat")); terrain_group_->setOrigin(Ogre::Vector3::ZERO); configureTerrainDefaults(light); for (long x = 0; x <= 0; ++x) for (long y = 0; y <= 0; ++y) defineTerrain(x, y); // sync load since we want everything in place when we start terrain_group_->loadAllTerrains(true); if (terrains_imported_) { Ogre::TerrainGroup::TerrainIterator ti = terrain_group_->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; t->setPosition(Ogre::Vector3(0, -315, 0)); initBlendMaps(t); } } terrain_group_->freeTemporaryResources(); scene_manager_->setSkyDome(true, "Examples/CloudySky", 5, 8); //Optional skybox //Graphics::instance()->getSceneManager()->setSkyDome(true, "Examples/CloudySky", 5, 8); }
//------------------------------------------------------------------------------------- void TutorialApplication::createScene(void) { /*Setting up the Camera*/ mCamera->setPosition(Ogre::Vector3(1683,50,2116)); mCamera->lookAt(Ogre::Vector3(1963,50,1660)); mCamera->setNearClipDistance(0.1); bool infiniteClip = mRoot->getRenderSystem()->getCapabilities()->hasCapability(Ogre::RSC_INFINITE_FAR_PLANE); if(infiniteClip) mCamera->setFarClipDistance(0); else mCamera->setFarClipDistance(50000); /*Setting up a Light*/ mSceneMgr->setAmbientLight(Ogre::ColourValue(0.2,0.2,0.2)); Ogre::Vector3 lightdir(0.55,-0.3,0.75); lightdir.normalise(); Ogre::Light* light = mSceneMgr->createLight("TestLight"); light->setType(Ogre::Light::LT_DIRECTIONAL); light->setDirection(lightdir); light->setDiffuseColour(Ogre::ColourValue::White); light->setSpecularColour(Ogre::ColourValue(0.4,0.4,0.4)); /*Configuring the Terrain*/ mTerrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions(); mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(mSceneMgr,Ogre::Terrain::ALIGN_X_Z,513,12000.0); mTerrainGroup->setFilenameConvention(Ogre::String("terrain"),Ogre::String("dat")); mTerrainGroup->setOrigin(Ogre::Vector3::ZERO); configureTerrainDefaults(light); for(long x=0; x<=0; ++x) for(long y=0; y<=0; ++y) defineTerrain(x,y); mTerrainGroup->loadAllTerrains(true); if(mTerrainsImported) { Ogre::TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; initBlendMaps(t); } } mTerrainGroup->freeTemporaryResources(); /*Writing configureTerrainDefaults*/ /*Writing defineTerrain*/ /*Writing getTerrainImage*/ /*Writing initBlendMaps*/ //LE TEST MARCHE PAS :D // /*Terrain Loading Label*/ /*Cleaning Up*/ /*TODO SkyBoxes*/ }
void Scene::setup(Sim* sim) { mSim = sim; mSim->scene = this; // Lighting and sky mSceneMgr->setAmbientLight(Ogre::ColourValue(0.4, 0.4, 0.4)); Ogre::Vector3 lightDir(0.55, -0.3f, 0.75); lightDir.normalise(); sun = mSceneMgr->createLight("SunLight"); sun->setType(Ogre::Light::LT_DIRECTIONAL); sun->setDirection(lightDir); sun->setDiffuseColour(Ogre::ColourValue::White); sun->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4)); mSceneMgr->setSkyDome(true, "CloudySky"); // Terrain mTerrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions(); mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(mSceneMgr, Ogre::Terrain::ALIGN_X_Z, terrSize, worldSize); configureTerrainDefaults(); defineTerrain(); mTerrainGroup->loadAllTerrains(true); Ogre::TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator(); while (ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; t->setVisibilityFlags(RV_Terrain); } mTerrainGroup->freeTemporaryResources(); createBulletTerrain(); // Road // setupRoad(); // Objects setupObjects(); }
void CSceneEditorView::EngineSetup(void) { Ogre::Root *Root = ((CSceneEditorApp*)AfxGetApp())->m_Engine->GetRoot(); m_SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "SceneEditor"); // // Create a render window // This window should be the current ChildView window using the externalWindowHandle // value pair option. // Ogre::NameValuePairList parms; parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd); parms["vsync"] = "true"; CRect rect; GetClientRect(&rect); Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("SceneEditor"); if (RenderWindow == NULL) { try { m_RenderWindow = Root->createRenderWindow("SceneEditor", rect.Width(), rect.Height(), false, &parms); } catch(...) { MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP); exit(EXIT_SUCCESS); } } // Load resources Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // Create the camera m_Camera = m_SceneManager->createCamera("Camera"); m_Camera->setPosition(Ogre::Vector3(1683, 50, 2116)); m_Camera->lookAt(Ogre::Vector3(0, 0, 0)); m_Camera->setNearClipDistance(0.1); m_Camera->setFarClipDistance(50000); if (m_Root->getRenderSystem()->getCapabilities()->hasCapability(Ogre::RSC_INFINITE_FAR_PLANE)) { m_Camera->setFarClipDistance(0); // enable infinite far clip distance if we can } m_Camera->setAutoTracking(false); m_Camera->setFixedYawAxis(true); m_Camera->yaw(Ogre::Radian(0)); m_Camera->pitch(Ogre::Radian(0)); Ogre::SceneNode *CameraNode = NULL; CameraNode = m_SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode"); m_SceneManager->setAmbientLight(Ogre::ColourValue(0.2, 0.2, 0.2)); //Create viewport Ogre::Viewport* Viewport = NULL; if (0 == m_RenderWindow->getNumViewports()) { Viewport = m_RenderWindow->addViewport(m_Camera); Viewport->setBackgroundColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f)); } // Alter the camera aspect ratio to match the viewport m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height())); m_SceneManager->setSkyDome(true, "Examples/CloudySky", 5, 8); Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC); Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(7); Ogre::Vector3 lightdir(0.55, -0.3, 0.75); lightdir.normalise(); Ogre::Light* light = m_SceneManager->createLight("tstLight"); light->setType(Ogre::Light::LT_DIRECTIONAL); light->setDirection(lightdir); light->setDiffuseColour(Ogre::ColourValue::White); light->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4)); m_SceneManager->setAmbientLight(Ogre::ColourValue(0.2, 0.2, 0.2)); mTerrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions(); mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(m_SceneManager, Ogre::Terrain::ALIGN_X_Z, 513, 12000.0f); mTerrainGroup->setFilenameConvention(Ogre::String("Terrain"), Ogre::String("dat")); mTerrainGroup->setOrigin(Ogre::Vector3::ZERO); configureTerrainDefaults(light); for (long x = 0; x <= 0; ++x) for (long y = 0; y <= 0; ++y) defineTerrain(x, y); // sync load since we want everything in place when we start mTerrainGroup->loadAllTerrains(true); if (mTerrainsImported) { Ogre::TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; initBlendMaps(t); } } mTerrainGroup->freeTemporaryResources(); }
//------------------------------------------------------------------------------------- void SnowTerrain::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); } }
void OgreWidget::setupTerrain() { // bool blankTerrain = false; mTerrainPos = Ogre::Vector3(1.0, -75.1, 1.0); // mEditMarker = ogreSceneManager->createEntity("editMarker", "sphere.mesh"); // mEditNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode(); // mEditNode->attachObject(mEditMarker); // mEditNode->setScale(0.05, 0.05, 0.05); // These two lines makes the terrain textures look nicer: Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(Ogre::TFO_ANISOTROPIC); Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(7); //mSceneManager->setFog(Ogre::FOG_EXP, Ogre::ColourValue(0.1, 0.1, 0.1), 0.01, 500, 1000); Ogre::LogManager::getSingleton().setLogDetail(Ogre::LL_BOREME); // Set up directional and ambient lights // THis first light is used for terrain shadows Ogre::Vector3 lightdir(-0.55, -0.3, 0.75); lightdir.normalise(); Ogre::Light* light = mSceneManager->createLight("tstLight"); light->setType(Ogre::Light::LT_DIRECTIONAL); light->setDirection(lightdir); light->setDiffuseColour(Ogre::ColourValue(1.0, 1.0, 1.0)); light->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4)); mSceneManager->setAmbientLight(Ogre::ColourValue(0.3, 0.3, 0.3)); Ogre::Vector3 lightdir2(-0.55, -0.3, -0.75); lightdir2.normalise(); Ogre::Light* light2 = mSceneManager->createLight("tstLight2"); light2->setType(Ogre::Light::LT_DIRECTIONAL); light2->setDirection(lightdir2); light2->setDiffuseColour(Ogre::ColourValue(0.4, 0.4, 0.4)); light2->setSpecularColour(Ogre::ColourValue(0.2, 0.2, 0.2)); Ogre::Vector3 lightdir3(0.55, -0.2, -0.75); lightdir3.normalise(); Ogre::Light* light3 = mSceneManager->createLight("tstLight3"); light3->setType(Ogre::Light::LT_DIRECTIONAL); light3->setDirection(lightdir3); light3->setDiffuseColour(Ogre::ColourValue(0.5, 0.5, 0.5)); light3->setSpecularColour(Ogre::ColourValue(0.1, 0.1, 0.1)); Ogre::Vector3 lightdir4(-0.55, -0.2, 0.75); lightdir4.normalise(); Ogre::Light* light4 = mSceneManager->createLight("tstLight4"); light4->setType(Ogre::Light::LT_DIRECTIONAL); light4->setDirection(lightdir4); light4->setDiffuseColour(Ogre::ColourValue(0.3, 0.3, 0.3)); light4->setSpecularColour(Ogre::ColourValue(0.2, 0.2, 0.2)); mTerrainGroup = new Ogre::TerrainGroup(mSceneManager, Ogre::Terrain::ALIGN_X_Z, TERRAIN_SIZE, TERRAIN_WORLD_SIZE); mTerrainGroup->setFilenameConvention(Ogre::String("cachedterrain"), Ogre::String("dat")); mTerrainGroup->setOrigin(mTerrainPos); mTerrainGlobals = new Ogre::TerrainGlobalOptions(); configureTerrainDefaults(light); 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); // sync load since we NEED everything in place when we start mTerrainGroup->loadAllTerrains(true); // calculate the blend maps of all terrains if(mTerrainsImported) { Ogre::TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; initBlendMaps(t); } } mTerrainGroup->freeTemporaryResources(); // create a few entities on the terrain placeObjectOnTerrain("tudorhouse.mesh", Ogre::Vector3(10, 6.4, -10), 0, Ogre::Vector3(0.012, 0.012, 0.012)); placeObjectOnTerrain("church.mesh", Ogre::Vector3(-7, 0, 22), 90); placeObjectOnTerrain("house1.mesh", Ogre::Vector3(-23, 0, -10), 20); placeObjectOnTerrain("house2.mesh", Ogre::Vector3(22, 3, 20), -120); placeObjectOnTerrain("windmill.mesh", Ogre::Vector3(-35, -0.2, 20), 120); // palmtree placeObjectOnTerrain("tree1.mesh", Ogre::Vector3(0, 0, 10), 00, Ogre::Vector3(0.002, 0.002, 0.002)); placeObjectOnTerrain("tree2.mesh", Ogre::Vector3(0, 0, -30), 10, Ogre::Vector3(0.01, 0.01, 0.01)); // big wind-skewed guy placeObjectOnTerrain("tree3.mesh", Ogre::Vector3(10, 0, 35), 20, Ogre::Vector3(0.01, 0.01, 0.01)); // ??? placeObjectOnTerrain("tree4.mesh", Ogre::Vector3(33, 0, -15), 30, Ogre::Vector3(0.01, 0.01, 0.01)); // ??? placeObjectOnTerrain("tree5.mesh", Ogre::Vector3(-40, 0, -25), 40, Ogre::Vector3(0.01, 0.01, 0.01)); // the bald tree goes into the center placeObjectOnTerrain("tree6.mesh", Ogre::Vector3(-3, 0, -2), 50, Ogre::Vector3(0.008, 0.008, 0.008)); // tanne placeObjectOnTerrain("tree7.mesh", Ogre::Vector3(-22, 0, 28), 60, Ogre::Vector3(0.003, 0.003, 0.003)); mSceneManager->setSkyBox(true, "Examples/CloudyNoonSkyBox"); }
void MyGame::createScene(void) { //tutorial 3 mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8); // um coubo em volta da camera com textura mCamera->setPosition(Ogre::Vector3(100, 400, 100)); mCamera->lookAt(Ogre::Vector3(10, 400, 0)); mCamera->setNearClipDistance(0.1); mCamera->setFarClipDistance(50000); if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(Ogre::RSC_INFINITE_FAR_PLANE)) { mCamera->setFarClipDistance(0); // enable infinite far clip distance if we can } Ogre::Vector3 lightdir(0.55, -0.3, 0.75); lightdir.normalise(); Ogre::Light* light = mSceneMgr->createLight("tstLight"); light->setType(Ogre::Light::LT_DIRECTIONAL); light->setDirection(lightdir); light->setDiffuseColour(Ogre::ColourValue::White); light->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4)); mSceneMgr->setAmbientLight(Ogre::ColourValue(0.2, 0.2, 0.2)); mTerrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions(); mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(mSceneMgr, Ogre::Terrain::ALIGN_X_Z, 513, 12000.0f); mTerrainGroup->setFilenameConvention(Ogre::String("BasicTutorial3Terrain"), Ogre::String("dat")); mTerrainGroup->setOrigin(Ogre::Vector3::ZERO); configureTerrainDefaults(light); for (long x = 0; x <= 0; ++x) for (long y = 0; y <= 0; ++y) defineTerrain(x, y); // sync load since we want everything in place when we start mTerrainGroup->loadAllTerrains(true); if (mTerrainsImported) { Ogre::TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; initBlendMaps(t); } } mTerrainGroup->freeTemporaryResources(); //ate o tutorial 2 // //== faz o chao ================================================= // Ogre::Plane plane(Ogre::Vector3::UNIT_Y, -10); // Ogre::MeshManager::getSingleton().createPlane("plane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, //1500,1500,20,20,true,1,5,5,Ogre::Vector3::UNIT_Z);// até aqui é como se eu criasse a .mesh do plano // Ogre::Entity* floor = mSceneMgr->createEntity("floor", "plane"); // mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(floor); // floor->setMaterialName("Examples/BeachStones"); //põe uma textura no plano/chão // /* //== coloca um boneco na cena ================================== Ogre::Entity* someGuy = mSceneMgr->createEntity("someGuy","Sinbad.mesh"); Ogre::SceneNode* node_someGuy = mSceneMgr->createSceneNode("node_someGuy"); //criei um nó para o someGuy mSceneMgr->getRootSceneNode()->addChild(node_someGuy);// colocoquei o nó do someGuy no nó raiz node_someGuy->attachObject(someGuy); //coloquei o someGuy (entidade) no nó correspondente node_someGuy->setPosition(10,450,0); node_someGuy->scale(8,8,8); */ Ogre::Entity *sphere = mSceneMgr->createEntity("sphere", "Sinbad.mesh"); Ogre::SceneNode* node_sphere = mSceneMgr->createSceneNode("node_sphere"); //criei um nó para o someGuy mSceneMgr->getRootSceneNode()->addChild(node_sphere);// colocoquei o nó do someGuy no nó raiz node_sphere->attachObject(sphere); //coloquei o someGuy (entidade) no nó correspondente node_sphere->setPosition(-10,450,0); node_sphere->scale(5,5,5); physicsManager.createGround(); physicsManager.createSphere(); // Ogre::SceneNode* node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode(name); // btRigidBody &body = mPhysics.createBody(btTransform(btQuaternion::getIdentity(), btVector3(pos.x, pos.y, pos.z)), mass, shape); // mObjects.push_back(new SceneObject(*node1, body)); // Ogre::Entity *entity = mSceneMgr->createEntity(name, "Prefab_Cube"); // node1->attachObject(entity); // node1->setScale(size.x / 100.0f, size.y / 100.0f, size.z / 100.0f); // //== outro boneco na cena ======================================= // Ogre::Entity* anotherGuy = mSceneMgr->createEntity("anotherGuy","ninja.mesh"); // Ogre::SceneNode* node_anotherGuy = mSceneMgr->createSceneNode("node_anotherGuy"); //criei um nó para o anotherGuy // mSceneMgr->getRootSceneNode()->addChild(node_anotherGuy);// colocoquei o nó do anotherGuy no nó raiz // node_anotherGuy->attachObject(anotherGuy); //coloquei o anotherGuy (entidade) no nó correspondente // node_anotherGuy->setPosition(10,-10,20); // node_anotherGuy->scale(0.15,0.15,0.15); // // //== luz ========================================================= // Ogre::SceneNode* node_light = mSceneMgr->createSceneNode("node_light"); // mSceneMgr->getRootSceneNode()->addChild(node_light); // Ogre::Light* light1 = mSceneMgr->createLight("light1"); // light1->setType(Ogre::Light::LT_DIRECTIONAL);// // //light1->setPosition(0,20,0); // light1->setDiffuseColour(1.0f,1.0f,1.0f);// cor em RGB de 0 a 1 // light1->setDirection(Ogre::Vector3(1,-1,0)); // mSceneMgr->setAmbientLight(Ogre::ColourValue(0.7, 0.7, 0.7)); // alterea aqui pra clarear ou escurecer a tela // mSceneMgr->setShadowTechnique(Ogre:: SHADOWTYPE_STENCIL_ADDITIVE);// ativa sombra dos 3d no plano //btBroadphaseInterface* broadphase = new btDbvtBroadphase(); }
void Game::initialize(Ogre::Camera *camera, EventManager *handler) { _handler = handler; _camera = camera; gSceneManager->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); gSceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_MODULATIVE); Ogre::Vector3 lightdir(0.55, -0.3, 0.75); lightdir.normalise(); Ogre::Light* light = gSceneManager->createLight("tstLight"); light->setType(Ogre::Light::LT_DIRECTIONAL); light->setDirection(lightdir); light->setDiffuseColour(Ogre::ColourValue::White); light->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4)); mTerrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions(); mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(gSceneManager, Ogre::Terrain::ALIGN_X_Z, 513, 12000.0f); mTerrainGroup->setFilenameConvention(Ogre::String("BasicTutorial3Terrain"), Ogre::String("dat")); mTerrainGroup->setOrigin(Ogre::Vector3::ZERO); configureTerrainDefaults(light); for (long x = 0; x <= 0; ++x) for (long y = 0; y <= 0; ++y) defineTerrain(x, y); // sync load since we want everything in place when we start mTerrainGroup->loadAllTerrains(true); if (mTerrainsImported) { Ogre::TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator(); while(ti.hasMoreElements()) { Ogre::Terrain* t = ti.getNext()->instance; initBlendMaps(t); } } mTerrainGroup->freeTemporaryResources(); _werewolf.create("Werewolf"); _werewolf.setMesh("Werewolf", "WereVixen.mesh"); _werewolf.setPosition(Ogre::Vector3(1693, 20, 2090)); _werewolf.setScale(Ogre::Vector3(5, 5, 5)); _werewolf.rotate(Ogre::Radian(1.57), Ogre::Radian(3.14), Ogre::Radian(0)); _monster.create("Mobbie"); _monster.setMesh("Mobbie", "Spider.mesh", Action::ACT_IDLE | Action::ACT_WALK); _monster.setPosition(Ogre::Vector3(1708, 20, 2005)); _monster.setScale(Ogre::Vector3(2, 2, 2)); _monster.rotate(Ogre::Radian(0), Ogre::Radian(3.14), Ogre::Radian(0)); _streetLamp.create("StreetLamp"); _streetLamp.setMesh("StreetLamp", "StreetLamp1.mesh"); _streetLamp.setPosition(Ogre::Vector3(1703, mTerrainGroup->getHeightAtWorldPosition(Ogre::Vector3(1703, 0, 1110)), 1110)); _streetLamp.setScale(Ogre::Vector3(2.5, 2.5, 2.5)); _streetLamp.setRotation(Ogre::Radian(0), Ogre::Radian(1.57), Ogre::Radian(0)); _sellingHouse.create("SellingHouse"); _sellingHouse.setMesh("SellingHouse", "SellingHouse.mesh"); _sellingHouse.setPosition(Ogre::Vector3(1803,mTerrainGroup->getHeightAtWorldPosition(Ogre::Vector3(1903, 0, 1870)), 1570)); _sellingHouse.setScale(Ogre::Vector3(2.0, 2.0, 2.0)); Ogre::Plane skybox; skybox.d = 100; skybox.normal = Ogre::Vector3::NEGATIVE_UNIT_Y; gSceneManager->setSkyPlane(true, skybox, "Examples/CloudySky", 500, 20, true, 0.5, 150, 150); // set camera _camera->setPosition(_werewolf.position()+Ogre::Vector3(0, 10, 100)); _camera->lookAt(_werewolf.position()); _camera->setNearClipDistance(5); _camera->setFarClipDistance(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 } }