void TerrainOgreComponent::init() { OgreComponent::init(); Ogre::SceneManager* sMgr = StateManager::getInstance()->inGameState->getSceneMgr(); // Copy-pasted from the tutorials, need to tweak sMgr->setAmbientLight(Ogre::ColourValue(0.0, 0.0, 0.0)); sMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); /* Ogre::Entity* entNinja = sMgr->createEntity("Ninja", "chassis.mesh"); entNinja->setCastShadows(true); Ogre::SceneNode* ninjaNode = sMgr->getRootSceneNode()->createChildSceneNode(); // ninjaNode->setScale(20, 20, 20); ninjaNode->setPosition(0, 2, 2); ninjaNode->attachObject(entNinja); */ Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0); Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z); Ogre::Entity* entGround = sMgr->createEntity("GroundEntity", "ground"); sMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround); entGround->setMaterialName("Ground/Grid"); entGround->setCastShadows(false); /* Ogre::Light* pointLight = sMgr->createLight("pointLight"); pointLight->setType(Ogre::Light::LT_POINT); pointLight->setPosition(Ogre::Vector3(0, 50, 0)); pointLight->setDiffuseColour(1.0, 1.0, 1.0); pointLight->setSpecularColour(1.0, 1.0, 1.0); */ Ogre::Light* directionalLight = sMgr->createLight("directionalLight"); directionalLight->setType(Ogre::Light::LT_DIRECTIONAL); directionalLight->setDiffuseColour(Ogre::ColourValue(.1, .1, .1)); directionalLight->setSpecularColour(Ogre::ColourValue(.1, .1, .1)); directionalLight->setDirection(Ogre::Vector3( 0, -1, .3)); Ogre::Light* spotLight = sMgr->createLight("spotLight"); spotLight->setType(Ogre::Light::LT_SPOTLIGHT); spotLight->setDiffuseColour(1.0, 1.0, 1.0); spotLight->setSpecularColour(1.0, 1.0, 1.0); spotLight->setDirection(-1, -1, 0); spotLight->setPosition(Ogre::Vector3(30, 30, 0)); spotLight->setSpotlightRange(Ogre::Degree(10), Ogre::Degree(50)); //sMgr->setSkyDome(true, "Sky/Stars", 5, 8); /* Consider: weirnc: Add fog in the future? Can't get the 2nd line to work Ogre::ColourValue fadeColour(0.9, 0.9, 0.9); Application::getInstance()->getWindow()->getViewport(0)->setBackgroundColour(fadeColour); sMgr->setFog(Ogre::FOG_EXP, fadeColour, 0.0, 50, 500); */ }
VBOOL VPointLightElement::_createLight() { assert(VNULL == mLight); VBOOL result = VFALSE; if (mBaseNode != VNULL) { Ogre::SceneManager *sceneMgr = VENGINE.getGfxSystem()->getSceneManager(); mLight = sceneMgr->createLight(mBaseNode->getName()); // ³õʼ»¯¹âÔ´ mLight->setDiffuseColour(mDiffuse); mLight->setSpecularColour(mSpecular); mLight->setAttenuation(mRange, mAttenuationConstant, mAttenuationLinear, mAttenuationQuadric); mLight->setCastShadows(VFALSE); mLight->setVisible(mVisible); mBaseNode->attachObject(mLight); mBaseNode->setPosition(mRelPos); mBaseNode->setOrientation(mRelOrientation); result = VTRUE; } return result; }
//------------------------------------------------------------------------------------------- void MagickWidget::loadMesh(Ogre::MeshPtr pMesh) { QString directory(OgitorsRoot::getSingletonPtr()->GetProjectOptions()->ProjectDir.c_str()); if(directory.isEmpty()) directory = "./"; QDir(directory).mkpath("entitycache"); Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "MeshMagickTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8A8 , Ogre::TU_RENDERTARGET ); Ogre::RenderTexture *rttTex = texture->getBuffer()->getRenderTarget(); Ogre::SceneManager *mSceneMgr = Ogre::Root::getSingletonPtr()->createSceneManager("OctreeSceneManager", "MeshMagickTexMgr"); Ogre::Light *dirl = mSceneMgr->createLight("DisplayLight"); dirl->setDirection(-1,-1,-1); dirl->setDiffuseColour(1,1,1); dirl->setType(Ogre::Light::LT_DIRECTIONAL); Ogre::Camera* RTTCam = mSceneMgr->createCamera("MeshMagickCam"); RTTCam->setNearClipDistance(0.01F); RTTCam->setFarClipDistance(0); RTTCam->setAspectRatio(1); RTTCam->setFOVy(Ogre::Degree(90)); RTTCam->setPosition(0,0,1); RTTCam->lookAt(0,0,0); Ogre::Viewport *v = rttTex->addViewport( RTTCam ); v->setClearEveryFrame( true ); v->setBackgroundColour(Ogre::ColourValue(0,0,0)); Ogre::Entity *mEntity; mEntity = mSceneMgr->createEntity("scbDisplay", pMesh->getName()); mSceneMgr->getRootSceneNode()->attachObject(mEntity); Ogre::Vector3 vSize = mEntity->getBoundingBox().getHalfSize(); Ogre::Vector3 vCenter = mEntity->getBoundingBox().getCenter(); vSize += Ogre::Vector3(vSize.z, vSize.z, vSize.z); float maxsize = std::max(std::max(vSize.x,vSize.y),vSize.z); vSize = Ogre::Vector3(0, 0, maxsize * 1.15f) + vCenter; RTTCam->setPosition(vSize.x,vSize.y,vSize.z); RTTCam->lookAt(vCenter.x,vCenter.y,vCenter.z); rttTex->update(); Ogre::String imagefile = OgitorsUtils::QualifyPath(directory.toStdString() + "/entitycache/meshmagick.png"); rttTex->writeContentsToFile(imagefile); mEntity->detachFromParent(); mSceneMgr->destroyEntity(mEntity); rttTex->removeAllViewports(); Ogre::Root::getSingletonPtr()->destroySceneManager(mSceneMgr); mDisplayWidget->setImage(QString(imagefile.c_str())); }
void DepthVideoApp::SetupScene(void) { Ogre::SceneManager* sceneManager = MagicCore::RenderSystem::Get()->GetSceneManager(); sceneManager->setAmbientLight(Ogre::ColourValue(0.3, 0.3, 0.3)); Ogre::Light* light = sceneManager->createLight("DepthVideoApp_SimpleLight"); light->setPosition(0, 0, 20); light->setDiffuseColour(0.8, 0.8, 0.8); light->setSpecularColour(0.5, 0.5, 0.5); InitViewTool(); }
void PointShopApp::SetupScene(void) { InfoLog << "PointShopApp::SetupScene" << std::endl; Ogre::SceneManager* pSceneMgr = MagicCore::RenderSystem::GetSingleton()->GetSceneManager(); pSceneMgr->setAmbientLight(Ogre::ColourValue(0.1, 0.1, 0.1)); Ogre::Light* sl = pSceneMgr->createLight("SimpleLight"); sl->setPosition(0, 0, 20); sl->setDiffuseColour(0.8, 0.8, 0.8); sl->setSpecularColour(0.5, 0.5, 0.5); }
Ogre::SceneManager *OgreInitializer::createSceneManager(Ogre::SceneType type) { Ogre::SceneManager * mgr = mRoot->createSceneManager(type); mgr->setSkyBox(true,"Examples/CloudyNoonSkyBox"); mgr->setAmbientLight(Ogre::ColourValue::White); mgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); Ogre::Light * l = mgr->createLight(); l->setType(Ogre::Light::LT_DIRECTIONAL); l->setDirection(0.03, -1.0, 0.01); return mgr; }
void EC_OgreEnvironment::CreateSunlight() { if (renderer_.expired()) return; RendererPtr renderer = renderer_.lock(); Ogre::SceneManager* sceneManager = renderer->GetSceneManager(); sunlight_ = sceneManager->createLight(renderer->GetUniqueObjectName()); sunlight_->setType(Ogre::Light::LT_DIRECTIONAL); ///\todo Read parameters from config file? sunlight_->setDiffuseColour(0.93f, 1, 0.13f); sunlight_->setDirection(-1, -1, -1); sunlight_->setCastShadows(true); SetAmbientLightColor(Color(0.5, 0.5, 0.5, 1)); }
MapCameraLightning::MapCameraLightning(Ogre::SceneManager& sceneManager) : mSceneManager(sceneManager) { mLight = sceneManager.createLight("MapFixedSunLight"); mLight->setType(Ogre::Light::LT_DIRECTIONAL); mLight->setPosition(Ogre::Vector3(-500,300,-350)); Ogre::Vector3 dir = -mLight->getPosition(); dir.normalise(); mLight->setDirection(dir); mLight->setDiffuseColour(Ogre::ColourValue(0.8, 0.8, 0.6)); //yellow //mSun->setSpecularColour(1, 1, 0.7); //yellow mLight->setCastShadows(false); mLight->setAttenuation(1000000, 1, 0, 0); mLight->setVisible(false); }
void createScene(){ _sceneManager->setAmbientLight(Ogre::ColourValue(1.0f,1.0f,1.0f)); Ogre::SceneNode* nodeEsfera02; Ogre::Light* light02; Ogre::SceneNode* nM01 = _sceneManager->createSceneNode("nm01"); Ogre::Entity* entMesh01 = _sceneManager->createEntity("Entnm01", "proyectoOgreI.mesh"); _sceneManager->getRootSceneNode()->addChild(nM01); nM01->attachObject(entMesh01); entMesh01->setMaterialName("mat02"); Ogre::SceneNode* nM02 = _sceneManager->createSceneNode("nm02"); Ogre::Entity* entMesh02 = _sceneManager->createEntity("Entnm02", "ejes01.mesh"); _sceneManager->getRootSceneNode()->addChild(nM02); nM02->attachObject(entMesh02); nM02->scale(10.0f,10.0f,10.0f); Ogre::SceneNode* nM03 = _sceneManager->createSceneNode("nm03"); Ogre::Entity* entMesh03 = _sceneManager->createEntity("Entnm03", "ogrehead.mesh"); _sceneManager->getRootSceneNode()->addChild(nM03); nM03->attachObject(entMesh03); nM03->scale(5.0f,5.0f,5.0f); entMesh03->setMaterialName("mat01"); Ogre::Entity* entEsfera02 = _sceneManager->createEntity("EntEsfera02","sphere.mesh"); //Ogre::SceneNode* nodeEsfera02 = mSceneMgr->createSceneNode("NodeEsfera02"); nodeEsfera02 = _sceneManager->createSceneNode("NodeEsfera02"); _sceneManager->getRootSceneNode()->addChild(nodeEsfera02); nodeEsfera02->attachObject(entEsfera02); //NODO LUZ float lightScale = 0.9f; Ogre::SceneNode* nodeLuz02 = _sceneManager->createSceneNode("NodeLuz02"); light02 = _sceneManager->createLight("LuzPoint01"); light02->setType(Ogre::Light::LT_POINT); light02->setDiffuseColour(lightScale*Ogre::ColourValue(2.0f,2.0f,2.0f)); nodeLuz02->attachObject(light02); nodeEsfera02->addChild(nodeLuz02); nodeEsfera02->setScale(0.05f,0.05f,0.05f); nodeEsfera02->setPosition(-500.0f,500.0f,500.0f); }
//--------------------------------------------------------------------------------------------- void TShowTankWoT_test::ShowTanks(int cnt) { Ogre::SceneManager* pSM = TModuleLogic::Get()->GetC()->pGraphicEngine->GetGE()->GetSceneManager(); pSM->setAmbientLight(Ogre::ColourValue(1, 1, 1)); // light Ogre::String nameLight = "mainLight"; Ogre::Light* pLight = NULL; if( pSM->hasLight(nameLight) ) pLight = pSM->getLight(nameLight); else pLight = pSM->createLight(nameLight); pLight->setType(Ogre::Light::LT_SPOTLIGHT); pLight->setCastShadows(false); pLight->setVisible(true); Ogre::Vector3 posLight(0,0,0); pLight->setPosition(posLight); Ogre::Vector3 dirLight(1,0,0); dirLight.normalise(); pLight->setDirection(dirLight); //pLight->setSpotlightRange(Ogre::Degree(20.0f), Ogre::Degree(25.0f), 0.95f); pLight->setDiffuseColour(1.0f, 1.0f, 1.0f); pLight->setDiffuseColour(1.0f, 1.0f, 1.0f); pLight->setSpecularColour(1.0f, 1.0f, 1.0f); //pLight->setAttenuation(1000.0f, 1.0f, 0.0005f, 0.0f); // light Ogre::Vector3 pos; pos.y = 0; pos.z = 0; for( int i = 0 ; i < cnt ; i++ ) { pos.x = i*50; ShowTank(i, pos); } Ogre::Camera* pCamera = TModuleLogic::Get()->GetC()->pGraphicEngine->GetGE()->GetCamera(); pCamera->setPosition(160,160,160); pCamera->lookAt(0,0,0); }
entityx::Entity Factory::createProjectile(entityx::ptr<EntityManager> where, Ogre::Vector3 pos, Ogre::Quaternion ori, Ogre::Real velocity, std::string materialName) { Ogre::Entity *projMesh; Ogre::SceneManager *sceneMgr = RenderManager::getPtr()->getSceneManager(); projMesh = sceneMgr->createEntity("ProjectileMesh.mesh"); projMesh->setMaterialName(materialName); Entity proj = where->create(); Ogre::SceneNode *projNode = sceneMgr->getRootSceneNode()->createChildSceneNode(); projNode->attachObject(projMesh); Ogre::Light *light = sceneMgr->createLight(); if(materialName == "RedLaser") light->setDiffuseColour(Ogre::ColourValue(.8, .2, .2)); else light->setDiffuseColour(Ogre::ColourValue(.2, .2, .8)); light->setType(Ogre::Light::LT_POINT); projNode->attachObject(light); projNode->setPosition(pos); projNode->setOrientation(ori); //projNode->translate(0, 0, -2, Ogre::SceneNode::TS_LOCAL); proj.assign<Position>(projNode->getPosition()); proj.assign<Orientation>(ori); proj.assign<Velocity>(0, 0, velocity); proj.component<Velocity>()->direction.z = -1; proj.assign<Renderable>(projNode); proj.assign<AngularVelocity>(0, 0, 10); proj.assign<Name>("proiettile"); proj.assign<LightComponent>(light); return proj; }
//int GameDirectionalLight::onGameEntityAdded(Ogre::SceneManager * pSceneManager) int GameDirectionalLight::onGameEntityAdded(OGraphics::GraphicsSystem * pGraphicsSystem) { Ogre::SceneManager * pSceneManager = pGraphicsSystem->getSceneManager(); DirectionalLightUpdateBlock * pInitialBlock = &(mpUpdateBlockGroup->mUpdateBlocks[0]); Ogre::Light * pLight = pSceneManager->createLight(); if (mpParentEntity) { mSceneNode = mpParentEntity->mSceneNode->createChildSceneNode(mSceneType); } else { mSceneNode = pGraphicsSystem->getSceneNodeWorld()->createChildSceneNode(mSceneType); } // pLight needs to be attached before setDirection can be called mSceneNode->attachObject(pLight); mSceneNode->setPosition(pInitialBlock->mTransform.vPos); mSceneNode->setOrientation(pInitialBlock->mTransform.qRot); pLight->setRenderQueueGroup(pInitialBlock->renderGroupQueue); pLight->setVisibilityFlags(pInitialBlock->visibilityFlags); pLight->setPowerScale(pInitialBlock->powerScale); pLight->setType(mpLightDefinition->lightType); pLight->setDirection(pInitialBlock->direction); pLight->setCastShadows(pInitialBlock->castShadows); pLight->setSpecularColour(pInitialBlock->specular); pLight->setDiffuseColour(pInitialBlock->diffuse); mpLightDefinition->mMovableObject = pLight; pSceneManager->setAmbientLight( pInitialBlock->ambientLight.upperHemisphere, pInitialBlock->ambientLight.lowerHemisphere, pInitialBlock->ambientLight.hemisphereDir, pInitialBlock->ambientLight.envMapScale); return 0; }
void Homepage::SetupScene() { Ogre::SceneManager* sceneManager = MagicCore::RenderSystem::Get()->GetSceneManager(); sceneManager->setAmbientLight(Ogre::ColourValue(0.3, 0.3, 0.3)); Ogre::Light* light = sceneManager->createLight("Homepage_SimpleLight"); light->setPosition(-5, 5, 20); light->setDiffuseColour(0.8, 0.8, 0.8); light->setSpecularColour(0.5, 0.5, 0.5); if (mpViewTool == NULL) { mpViewTool = new MagicCore::ViewTool; } GPP::TriMesh* triMesh = ModelManager::Get()->GetMesh(); if (triMesh) { mpUI->SetModelInfo(triMesh->GetVertexCount(), triMesh->GetTriangleCount()); } GPP::PointCloud* pointCloud = ModelManager::Get()->GetPointCloud(); if (pointCloud) { mpUI->SetModelInfo(pointCloud->GetPointCount(), 0); } }
void test() { Ogre::Root* pOgre = new Ogre::Root("", ""); pOgre->loadPlugin(RENDER_SYSTEM); pOgre->setRenderSystem(pOgre->getAvailableRenderers().front()); pOgre->initialise(false); Ogre::NameValuePairList lArgs; //lArgs["externalWindowHandle"] = bk::format("%d", (bk::uint)l_window.get_handle()).astr; Ogre::RenderWindow* pWindow = pOgre->createRenderWindow("Heart|Dockyard", 1024, 768, false, &lArgs); Ogre::SceneManager* pSceneManager = pOgre->createSceneManager(Ogre::ST_GENERIC,"SceneManager"); pSceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); pSceneManager->setShadowCameraSetup(Ogre::ShadowCameraSetupPtr(new Ogre::FocusedShadowCameraSetup())); pSceneManager->setAmbientLight(Ogre::ColourValue(0.1f, 0.1f, 0.1f)); Ogre::Camera* pCamera = pSceneManager->createCamera("Camera"); pCamera->setFixedYawAxis(true, Ogre::Vector3::UNIT_Z); pCamera->setPosition(Ogre::Vector3(0.0f, 50.0f, 20.0f)); pCamera->lookAt(Ogre::Vector3(0.0f, 0.0f, 0.0f)); pCamera->setNearClipDistance(0.1f); pCamera->setFarClipDistance(100.0f); Ogre::Viewport* pViewport = pWindow->addViewport(pCamera); pViewport->setBackgroundColour(Ogre::ColourValue(0.0f, 0.0f, 0.0f)); pCamera->setAspectRatio(Ogre::Real(pViewport->getActualWidth()) / Ogre::Real(pViewport->getActualHeight())); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../data/dockyard.zip", "Zip", "Dockyard", true); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); Ogre::MeshManager::getSingleton().createPlane("GroundPlane", "Dockyard", Ogre::Plane(0.0f, 0.0f, 1.0f, 0.0f), 100.0f, 100.0f, 100, 100, true, 1, 3.0f, 3.0f); Ogre::Entity* pGroundEntity = pSceneManager->createEntity("GroundPlane"); pGroundEntity->setMaterialName("Examples/Rockwall"); pGroundEntity->setCastShadows(false); pGroundEntity->getSubEntity(0)->getMaterial()->setShadingMode(Ogre::SO_PHONG); Ogre::SceneNode* pGroundNode = pSceneManager->getRootSceneNode()->createChildSceneNode(); pGroundNode->attachObject(pGroundEntity); Ogre::Entity* pCubeEntity = pSceneManager->createEntity("Cube", Ogre::SceneManager::PT_CUBE); pCubeEntity->setMaterialName("Examples/10PointBlock"); pCubeEntity->setCastShadows(true); Ogre::SceneNode* pCubeNode = pSceneManager->getRootSceneNode()->createChildSceneNode(); pCubeNode->attachObject(pCubeEntity); pCubeNode->setPosition(0.0f, 0.0f, 5.f); pCubeNode->setScale(0.1f, 0.1f, 0.1f); Ogre::ColourValue lColour1(1.0f, 1.0f, 1.0f); Ogre::ColourValue lColour2(1.0f, 1.0f, 1.0f); Ogre::ColourValue lColour3(1.0f, 1.0f, 1.0f); Ogre::Light* pLight1 = pSceneManager->createLight(); pLight1->setType(Ogre::Light::LT_SPOTLIGHT); pLight1->setPosition(30.0f, 30.0f, 30.0f); pLight1->setDirection(-1.0f, -1.0f, -1.0f); pLight1->setSpotlightRange(Ogre::Degree(30), Ogre::Degree(50)); pLight1->setDiffuseColour(lColour1 * 0.5f); Ogre::Light* pLight2 = pSceneManager->createLight(); pLight2->setType(Ogre::Light::LT_SPOTLIGHT); pLight2->setPosition(-30.0f, 30.0f, 30.0f); pLight2->setDirection(1.0f, -1.0f, -1.0f); pLight2->setSpotlightRange(Ogre::Degree(30), Ogre::Degree(50)); pLight2->setDiffuseColour(lColour2 * 0.5f); Ogre::Light* pLight3 = pSceneManager->createLight(); pLight3->setType(Ogre::Light::LT_SPOTLIGHT); pLight3->setPosition(30.0f, -30.0f, 30.0f); pLight3->setDirection(-1.0f, 1.0f, -1.0f); pLight3->setSpotlightRange(Ogre::Degree(30), Ogre::Degree(50)); pLight3->setDiffuseColour(lColour3 * 0.5f); Ogre::Overlay* pMenuOverlay = Ogre::OverlayManager::getSingleton().create("Menu"); Ogre::OverlayElement* pMenu = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "Menu"); pMenu->setMetricsMode(Ogre::GMM_PIXELS); pMenu->setWidth(200); pMenu->setHeight(200); pMenu->setTop(30); pMenu->setLeft(30); pMenu->setMaterialName("Examples/BumpyMetal"); if (pMenu->isContainer()) pMenuOverlay->add2D(static_cast<Ogre::OverlayContainer*>(pMenu)); pMenuOverlay->show(); pOgre->startRendering(); }
void btoBiome::setup() { btBiome::setup(); // Essential objects BulletOgreEngine* btoEngine = world->getBulletOgreEngine(); Ogre::SceneManager* sceneManager = btoEngine->getOgreEngine()->getOgreSceneManager(); // --------- // -- Sky -- // --------- if(data.contains("skyMaterial")) { QString skyMaterial = data["skyMaterial"].toString(); if(skyMaterial.contains("box", Qt::CaseInsensitive)) sceneManager->setSkyBox(true, skyMaterial.toStdString(), 1000); else sceneManager->setSkyDome(true, skyMaterial.toStdString(), 10, 8, 1000); } // ------------- // -- Shadows -- // ------------- sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_NONE); sceneManager->setAmbientLight(Ogre::ColourValue(0.3, 0.3, 0.3, 0.3)); // ------------ // -- Lights -- // ------------ int nbPointLights = 0; // for id int nbDirectionalLights = 0; // for id int nbSpotLights = 0; // for id foreach(QVariant lightData, lightsData) { QVariantMap lightMap = lightData.toMap(); // TODO diffuse and specular !!! dr, dg, db, sr, sg, sb btScalar r = lightMap["r"].toFloat(); btScalar g = lightMap["g"].toFloat(); btScalar b = lightMap["b"].toFloat(); QString type = lightMap["type"].toString(); if(type.compare("ambient") == 0) { sceneManager->setAmbientLight(Ogre::ColourValue(r, g, b)); } else if(type.compare("point") == 0) { nbPointLights++; btScalar x = lightMap["posX"].toFloat(); btScalar y = lightMap["posY"].toFloat(); btScalar z = lightMap["posZ"].toFloat(); Ogre::Light* pointLight = sceneManager->createLight(); pointLight->setType(Ogre::Light::LT_POINT); pointLight->setPosition(Ogre::Vector3(x, y, z)); pointLight->setDiffuseColour(r, g, b); pointLight->setSpecularColour(r, g, b); } else if(type.compare("directional") == 0) { nbDirectionalLights++; btScalar dirX = lightMap["dirX"].toFloat(); btScalar dirY = lightMap["dirY"].toFloat(); btScalar dirZ = lightMap["dirZ"].toFloat(); Ogre::Light* directionalLight = sceneManager->createLight(); directionalLight->setType(Ogre::Light::LT_DIRECTIONAL); directionalLight->setDiffuseColour(Ogre::ColourValue(r, g, b)); directionalLight->setSpecularColour(Ogre::ColourValue(r, g, b)); directionalLight->setDirection(Ogre::Vector3( dirX, dirY, dirZ)); } else if(type.compare("spot") == 0) { nbSpotLights++; btScalar dirX = lightMap["dirX"].toFloat(); btScalar dirY = lightMap["dirY"].toFloat(); btScalar dirZ = lightMap["dirZ"].toFloat(); btScalar posX = lightMap["posX"].toFloat(); btScalar posY = lightMap["posY"].toFloat(); btScalar posZ = lightMap["posZ"].toFloat(); btScalar innerAngle = lightMap["innerAngle"].toFloat(); btScalar outerAngle = lightMap["outerAngle"].toFloat(); //btScalar falloff = lightMap["falloff"].toFloat(); Ogre::Light* spotLight = sceneManager->createLight(); spotLight->setType(Ogre::Light::LT_SPOTLIGHT); spotLight->setDiffuseColour(r,g,b); spotLight->setSpecularColour(r,g,b); spotLight->setDirection(dirX, dirY, dirZ); spotLight->setPosition(posX, posY, posZ); spotLight->setSpotlightRange(Ogre::Radian(innerAngle), Ogre::Radian(outerAngle)); } }
void createScene(){ _sceneManager->setAmbientLight(Ogre::ColourValue(1.0f,1.0f,1.0f)); _sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); _sceneManager->setSkyBox(true, "OMV/SkyBoxUnderwater1"); Ogre::Plane plane(Ogre::Vector3::UNIT_Y , -5000.0); Ogre::MeshManager::getSingleton().createPlane("plane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 60000,100000,200,200,true, 1,10,10, Ogre::Vector3::UNIT_Z); Ogre::SceneNode* nodePlano; Ogre::Entity* entPlano = _sceneManager->createEntity("PlanoEntity","plane"); nodePlano = _sceneManager->createSceneNode("NodePlano"); nodePlano->attachObject(entPlano); _sceneManager->getRootSceneNode()->addChild(nodePlano); entPlano->setMaterialName("plano"); nodePlano->translate(Ogre::Vector3(0.0f,0.0f,45000.0f)); Ogre::SceneNode* nodeEsfera02; Ogre::Light* light02; Ogre::Entity* entEsfera02 = _sceneManager->createEntity("EntEsfera02","sphere.mesh"); //Ogre::SceneNode* nodeEsfera02 = mSceneMgr->createSceneNode("NodeEsfera02"); nodeEsfera02 = _sceneManager->createSceneNode("NodeEsfera02"); _sceneManager->getRootSceneNode()->addChild(nodeEsfera02); nodeEsfera02->attachObject(entEsfera02); //NODO LUZ float lightScale = 0.9f; Ogre::SceneNode* nodeLuz02 = _sceneManager->createSceneNode("NodeLuz02"); light02 = _sceneManager->createLight("LuzPoint01"); light02->setType(Ogre::Light::LT_POINT); light02->setDiffuseColour(lightScale*Ogre::ColourValue(2.0f,2.0f,2.0f)); nodeLuz02->attachObject(light02); nodeEsfera02->addChild(nodeLuz02); nodeEsfera02->setScale(0.05f,0.05f,0.05f); nodeEsfera02->setPosition(0.0f,5000.0f,0.0f); banderin[0] = new Banderin("Inicio",_sceneManager, 5105.0, -2000.0, 0.0); _sceneManager->getRootSceneNode()->addChild(banderin[0]->nodoBanderin); banderin[1] = new Banderin("Fin",_sceneManager, 5105.0, -2000.0, 90000.0); _sceneManager->getRootSceneNode()->addChild(banderin[1]->nodoBanderin); nave = new Nave(_sceneManager, _sceneManager->getCamera("Camera")); for (int i = 0; i < num_monedas; i++) { crearMoneda(i,4000,5000,90000); } for (int i = 0; i < num_aros; i++) { crearAro(i,4000,5000,90000); } for (int i = 0; i < num_obstaculo; i++) { crearObstaculo(i,4000,5000,90000); } }
// funcion donde se coloca lo que se desea desplegar. void createScene(){ _sceneManager->setAmbientLight(Ogre::ColourValue(0.2,0.2,0.2)); _sceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); // LUZ Ogre::Light* LuzPuntual01 = _sceneManager->createLight("Luz01"); LuzPuntual01->setType(Ogre::Light::LT_DIRECTIONAL); LuzPuntual01->setDiffuseColour(1.0,1.0,1.0); LuzPuntual01->setDirection(Ogre::Vector3( 1, -1, -1 )); Ogre::Light* LuzPuntual02 = _sceneManager->createLight("Luz02"); LuzPuntual02->setType(Ogre::Light::LT_DIRECTIONAL); LuzPuntual02->setDiffuseColour(1.0,1.0,1.0); LuzPuntual02->setDirection(Ogre::Vector3( -1, -1, -1 )); //Chasis Carro _nodeChasisCarro = _sceneManager->createSceneNode("ChasisCarro"); _sceneManager->getRootSceneNode()->addChild(_nodeChasisCarro); Ogre::Entity* _entChasisCarro = _sceneManager->createEntity("ChasisCarro", "chasisCarro.mesh"); _nodeChasisCarro->attachObject(_entChasisCarro); /* Ruedas Izquierdas */ _nodeRuedaSimple0 = _sceneManager->createSceneNode("RuedaSimple0"); _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple0); // _nodeRuedaSimple00 = _nodeRuedaSimple0->createChildSceneNode("RuedaSimple00"); // _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple00); Ogre::Entity* _entRuedaSimple0 = _sceneManager->createEntity("RuedaSimple0", "RuedaDetallada.mesh"); _nodeRuedaSimple0->attachObject(_entRuedaSimple0); // _nodeRuedaSimple00->attachObject(_entRuedaSimple0); _nodeRuedaSimple0->translate(9,3,5); _nodeRuedaSimple2 = _sceneManager->createSceneNode("RuedaSimple2"); _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple2); // _nodeRuedaSimple22 = _nodeRuedaSimple2->createChildSceneNode("RuedaSimple22"); // _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple22); Ogre::Entity* _entRuedaSimple2 = _sceneManager->createEntity("RuedaSimple2", "RuedaDetallada.mesh"); _nodeRuedaSimple2->attachObject(_entRuedaSimple2); // _nodeRuedaSimple22->attachObject(_entRuedaSimple2); _nodeRuedaSimple2->translate(9,3,-5); /* Ruedas Derechas */ _nodeRuedaSimple1 = _sceneManager->createSceneNode("RuedaSimple1"); _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple1); // _nodeRuedaSimple11 = _nodeRuedaSimple1->createChildSceneNode("RuedaSimple11"); // _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple11); Ogre::Entity* _entRuedaSimple1 = _sceneManager->createEntity("RuedaSimple1", "RuedaDetallada.mesh"); _nodeRuedaSimple1->attachObject(_entRuedaSimple1); // _nodeRuedaSimple11->attachObject(_entRuedaSimple1); _nodeRuedaSimple1->translate(-7,3,5); _nodeRuedaSimple3 = _sceneManager->createSceneNode("RuedaSimple3"); _sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple3); // _nodeRuedaSimple33 = _nodeRuedaSimple3->createChildSceneNode("RuedaSimple33"); //_sceneManager->getRootSceneNode()->addChild(_nodeRuedaSimple33); Ogre::Entity* _entRuedaSimple3 = _sceneManager->createEntity("RuedaSimple3", "RuedaDetallada.mesh"); _nodeRuedaSimple3->attachObject(_entRuedaSimple3); //_nodeRuedaSimple33->attachObject(_entRuedaSimple3); _nodeRuedaSimple3->translate(-7,3,-5); /* ALA DERECHA INFERIOR Se crea el nodo padre de la nave llamado eje */ eje = _sceneManager->getRootSceneNode()->createChildSceneNode("eje"); padreDI = eje->createChildSceneNode("padreDI"); Ogre::ManualObject* alad = _sceneManager->createManualObject("alad"); alad->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); alad->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0)); alad->position(4.0, -0.5, 0.0); alad->position(15.0, -0.5, 0.0); alad->position(15.0, 0.0, 0.0); alad->position(5.0, 0.0, 0.0); alad->index(0); alad->index(1); alad->index(2); alad->index(3); alad->index(0); alad->end(); padreDI->attachObject(alad); Ogre::ManualObject* alad2 = _sceneManager->createManualObject("alad2"); alad2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); alad2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0)); alad2->position(5.0, 0.0, 0.0); alad2->position(15.0, 0.0, 0.0); alad2->position(14.0, 0.0, -3.0); alad2->position(5.0, 0.0, -4.0); alad2->index(0); alad2->index(1); alad2->index(2); alad2->index(3); alad2->index(0); alad2->end(); padreDI->attachObject(alad2); /* ALA DERECHA SUPERIOR */ padreDS = eje->createChildSceneNode("padreDS"); Ogre::ManualObject* aladS = _sceneManager->createManualObject("aladS"); aladS->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladS->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0)); aladS->position(4.0, 0.0, 0.0); aladS->position(15.0, 0.0, 0.0); aladS->position(15.0, 0.5, 0.0); aladS->position(5.0, 0.5, 0.0); aladS->index(0); aladS->index(1); aladS->index(2); aladS->index(3); aladS->index(0); aladS->end(); padreDS->attachObject(aladS); Ogre::ManualObject* aladS2 = _sceneManager->createManualObject("aladS2"); aladS2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladS2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0)); aladS2->position(5.0, 0.5, 0.0); aladS2->position(15.0, 0.5, 0.0); aladS2->position(14.0, 0.5, -3.0); aladS2->position(5.0, 0.5, -3.0); aladS2->index(0); aladS2->index(1); aladS2->index(2); aladS2->index(3); aladS2->index(0); aladS2->end(); padreDS->attachObject(aladS2); /* ALA IZQUIERDA INFERIOR */ padreII = eje->createChildSceneNode("padreII"); Ogre::ManualObject* aladI = _sceneManager->createManualObject("aladI"); aladI->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladI->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0)); aladI->position(-15.0, -0.5, 0.0); aladI->position(5.0, -0.5, 0.0); aladI->position(-5.0, 0.0, 0.0); aladI->position(-15.0, 0.0, 0.0); aladI->index(0); aladI->index(1); aladI->index(2); aladI->index(3); aladI->index(0); aladI->end(); padreII->attachObject(aladI); Ogre::ManualObject* aladI2 = _sceneManager->createManualObject("aladI2"); aladI2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladI2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0)); aladI2->position(-15.0, 0.0, 0.0); aladI2->position(-5.0, 0.0, 0.0); aladI2->position(-5.0, 0.0, -4.0); aladI2->position(-14.0, 0.0, -3.0); aladI2->index(0); aladI2->index(1); aladI2->index(2); aladI2->index(3); aladI2->index(0); aladI2->end(); padreII->attachObject(aladI2); /* ALA IZQUIERDA SUPERIOR */ padreIS = eje->createChildSceneNode("padreIS"); Ogre::ManualObject* aladIS = _sceneManager->createManualObject("aladIS"); aladIS->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladIS->colour(Ogre::ColourValue(0.0, 0.5, 0.0, 0.0)); aladIS->position(-15.0, 0.0, 0.0); aladIS->position(5.0, 0.0, 0.0); aladIS->position(-5.0, 0.5, 0.0); aladIS->position(-15.0, 0.5, 0.0); aladIS->index(0); aladIS->index(1); aladIS->index(2); aladIS->index(3); aladIS->index(0); aladIS->end(); padreIS->attachObject(aladIS); Ogre::ManualObject* aladIS2 = _sceneManager->createManualObject("aladIS2"); aladIS2->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_FAN); aladIS2->colour(Ogre::ColourValue(0.0, 0.6, 0.0, 0.0)); aladIS2->position(-15.0, 0.5, 0.0); aladIS2->position(-5.0, 0.5, 0.0); aladIS2->position(-5.0, 0.5, -3.0); aladIS2->position(-14.0, 0.5, -2.0); aladIS2->index(0); aladIS2->index(1); aladIS2->index(2); aladIS2->index(3); aladIS2->index(0); aladIS2->end(); padreIS->attachObject(aladIS2); /* Rotaciones de las alas */ eje->scale(2.5,2.5,2.5); eje->translate(0,5,0); eje->yaw(Ogre::Degree(180)); /* Trasladar las alas */ padreIS->translate(4,0,0); padreDS->translate(-4,0,0); padreDI->translate(-4,0,0); padreII->translate(4,0,0); eje->scale(0.1,0.1,0.1); //BordePista Ogre::SceneNode* _nodeBPista = _sceneManager->createSceneNode("BordePista"); _sceneManager->getRootSceneNode()->addChild(_nodeBPista); Ogre::Entity* _entBPista = _sceneManager->createEntity("BordePista", "bordePista02.mesh"); _nodeBPista->attachObject(_entBPista); _entBPista->setMaterialName("Examples/pared"); //PisoObstaculo Ogre::SceneNode* _nodePObstaculo = _sceneManager->createSceneNode("PistaObstaculo"); _sceneManager->getRootSceneNode()->addChild(_nodePObstaculo); Ogre::Entity* _entPObstaculo = _sceneManager->createEntity("PistaObstaculo", "pisoObstaculo02.mesh"); _nodePObstaculo->attachObject(_entPObstaculo); //PisoNOObstaculo Ogre::SceneNode* _nodePNObstaculo = _sceneManager->createSceneNode("PistaNoObstaculo"); _sceneManager->getRootSceneNode()->addChild(_nodePNObstaculo); Ogre::Entity* _entPNOObstaculo = _sceneManager->createEntity("PistaNoObstaculo", "pisoNoObstaculo02.mesh"); _nodePNObstaculo->attachObject(_entPNOObstaculo); _entPNOObstaculo->setMaterialName("Examples/piso"); //PosterInicioFinal Ogre::SceneNode* _nodePoster = _sceneManager->createSceneNode("PosterInicioFinal"); _sceneManager->getRootSceneNode()->addChild(_nodePoster); Ogre::Entity* _entPoster = _sceneManager->createEntity("PosterInicioFinal", "posterInicioFinal02.mesh"); _nodePoster->attachObject(_entPoster); //BanderaInicial Ogre::SceneNode* _nodeBInicial = _sceneManager->createSceneNode("BanderaInicial"); _sceneManager->getRootSceneNode()->addChild(_nodeBInicial); Ogre::Entity* _entBanderaI = _sceneManager->createEntity("BanderaInicial", "banderaInicial02.mesh"); _nodeBInicial->attachObject(_entBanderaI); //BanderaFinal Ogre::SceneNode* _nodeBFinal = _sceneManager->createSceneNode("BanderaFinal"); _sceneManager->getRootSceneNode()->addChild(_nodeBFinal); Ogre::Entity* _entBanderaF = _sceneManager->createEntity("BanderaFinal", "banderaFinal.mesh"); _nodeBFinal->attachObject(_entBanderaF); _sceneManager->setSkyDome(true,"Examples/cielo",5,8); }
void ZoneListWidget::_createImages(ImageMap& retlist) { retlist.clear(); Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "EntityTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 256, 256, 0, Ogre::PF_A8R8G8B8 , Ogre::TU_RENDERTARGET ); Ogre::RenderTexture *rttTex = texture->getBuffer()->getRenderTarget(); Ogre::SceneManager *mSceneMgr = Ogre::Root::getSingletonPtr()->createSceneManager("OctreeSceneManager", "EntityTexMgr"); Ogre::Light *dirl = mSceneMgr->createLight("DisplayLight"); dirl->setDirection(-1,-1,-1); dirl->setDiffuseColour(1,1,1); dirl->setType(Ogre::Light::LT_DIRECTIONAL); Ogre::Camera* RTTCam = mSceneMgr->createCamera("EntityCam"); RTTCam->setNearClipDistance(0.01F); RTTCam->setFarClipDistance(0); RTTCam->setAspectRatio(1); RTTCam->setFOVy(Ogre::Degree(90)); RTTCam->setPosition(0,0,1); RTTCam->lookAt(0,0,0); Ogre::Viewport *v = rttTex->addViewport( RTTCam ); v->setClearEveryFrame( true ); v->setBackgroundColour(Ogre::ColourValue(0,0,0,0)); ModularZoneFactory* factory = dynamic_cast<ModularZoneFactory*>(OgitorsRoot::getSingletonPtr()->GetEditorObjectFactory("Modular Zone Object")); if(!factory)return; factory->loadZoneTemplates(); ZoneInfoMap zoneTemplates = factory->getZoneTemplateMap(); Ogre::Entity *mEntity; unsigned char dataptr[300 * 300 * 6]; unsigned char *dataptr2; Ogre::PixelBox pb(256,256,1,Ogre::PF_A8R8G8B8, dataptr); EntityMap entities; ZoneInfoMap::iterator zi; for(zi=zoneTemplates.begin();zi!=zoneTemplates.end();++zi) { Ogre::String addstr = (*zi).second.mMesh; if(entities.find((*zi).first) == entities.end()) entities.insert(EntityMap::value_type((*zi).first,addstr)); } EntityMap::const_iterator ite = entities.begin(); while(ite != entities.end()) { Ogre::String addstr = ite->second; mEntity = mSceneMgr->createEntity("MZP_Preview", addstr); mSceneMgr->getRootSceneNode()->attachObject(mEntity); //TODO: It would be nice to retrieve a Preview Camera Position from //the .zone file //TODO: also render portal outlines clearly so that the user can see //how the zone is laid out Ogre::Vector3 vSize = mEntity->getBoundingBox().getCorner(Ogre::AxisAlignedBox::NEAR_RIGHT_TOP);//.getHalfSize();//============ Ogre::Vector3 vCenter = mEntity->getBoundingBox().getCenter(); //FIXME ------ NICE PREVIEWS NEEDED - bigger vSize += Ogre::Vector3(vSize.z, vSize.z, vSize.z); float maxsize = std::max(std::max(vSize.x,vSize.y),vSize.z); //vSize = Ogre::Vector3(0, 0, maxsize * 1.1f) + vCenter; vSize = Ogre::Vector3(maxsize * 0.5f, vSize.y, maxsize * 0.5f) + vCenter; //vSize.x +=vSize.x/2;//Maybe test to see which is larger x/2 or z/2 and use that? //vSize.z +=vSize.x/2; //RTTCam->setProjectionType(Ogre::PT_ORTHOGRAPHIC); RTTCam->setPosition(vSize.x,vSize.y,vSize.z); RTTCam->lookAt(vCenter.x,vCenter.y,vCenter.z); rttTex->update(); rttTex->copyContentsToMemory(pb, Ogre::RenderTarget::FB_FRONT); dataptr2 = new unsigned char[96 * 96 * 4]; Ogre::PixelBox pb2(96,96,1,Ogre::PF_A8R8G8B8, dataptr2); Ogre::Image::scale(pb,pb2); addstr.erase(addstr.length() - 5, 5); retlist.insert(ImageMap::value_type((*ite).first, dataptr2)); mEntity->detachFromParent(); mSceneMgr->destroyEntity(mEntity); ite++; } rttTex->removeAllViewports(); Ogre::Root::getSingletonPtr()->destroySceneManager(mSceneMgr); Ogre::TextureManager::getSingletonPtr()->unload(texture->getName()); Ogre::TextureManager::getSingletonPtr()->remove(texture->getName()); }
void GraphicsImpl::createScene() { // Set ambient light sceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); // Create a light Ogre::Light* l = sceneMgr->createLight("MainLight"); l->setPosition(20,80,50); caelumSystem = new Caelum::CaelumSystem(root, sceneMgr, Caelum::CaelumSystem::CAELUM_COMPONENTS_NONE); try { caelumSystem->setSkyDome(new Caelum::SkyDome(sceneMgr, caelumSystem->getCaelumCameraNode())); } catch (Caelum::UnsupportedException& ex) { Dout << ex.getFullDescription(); } try { caelumSystem->setSun(new Caelum::SphereSun(sceneMgr, caelumSystem->getCaelumCameraNode())); } catch (Caelum::UnsupportedException& ex) { Dout << ex.getFullDescription(); } try { caelumSystem->setMoon(new Caelum::Moon(sceneMgr, caelumSystem->getCaelumCameraNode())); } catch (Caelum::UnsupportedException& ex) { Dout << ex.getFullDescription(); } try { caelumSystem->setCloudSystem(new Caelum::CloudSystem(sceneMgr, caelumSystem->getCaelumGroundNode())); } catch (Caelum::UnsupportedException& ex) { Dout << ex.getFullDescription(); } try { caelumSystem->setPointStarfield(new Caelum::PointStarfield(sceneMgr, caelumSystem->getCaelumCameraNode())); } catch (Caelum::UnsupportedException& ex) { Dout << ex.getFullDescription(); } // Register caelum. // Don't make it a frame listener; update it by hand. //Root::getSingletonPtr ()->addFrameListener (caelumSystem.get ()); caelumSystem->attachViewport(viewPort); try { caelumSystem->setPrecipitationController(new Caelum::PrecipitationController(sceneMgr)); } catch (Caelum::UnsupportedException& ex) { Dout << ex.getFullDescription(); } caelumSystem->setSceneFogDensityMultiplier(0.0015); caelumSystem->setManageAmbientLight(true); caelumSystem->setMinimumAmbientLight(Ogre::ColourValue(0.1, 0.1, 0.1)); // Setup sun options if (caelumSystem->getSun()) { // Make the sun very obvious: //caelumSystem->getSun ()->setDiffuseMultiplier (Ogre::ColourValue (1, 10, 1)); caelumSystem->getSun()->setAutoDisableThreshold(0.05); caelumSystem->getSun()->setAutoDisable(false); } if (caelumSystem->getMoon()) { // Make the moon very obvious: //caelumSystem->getMoon ()->setDiffuseMultiplier (Ogre::ColourValue (1, 1, 10)); caelumSystem->getMoon()->setAutoDisableThreshold(0.05); caelumSystem->getMoon()->setAutoDisable(false); } if (caelumSystem->getCloudSystem()) { try { caelumSystem->getCloudSystem()->createLayerAtHeight(2000); caelumSystem->getCloudSystem()->createLayerAtHeight(5000); caelumSystem->getCloudSystem()->getLayer(0)->setCloudSpeed(Ogre::Vector2(0.000005, -0.000009)); caelumSystem->getCloudSystem()->getLayer(1)->setCloudSpeed(Ogre::Vector2(0.0000045, -0.0000085)); } catch (Caelum::UnsupportedException& ex) { Dout << ex.getFullDescription(); } } if (caelumSystem->getPrecipitationController()) { caelumSystem->getPrecipitationController()->setIntensity(0); } // Set time acceleration. //caelumSystem->getUniversalClock ()->setTimeScale (0); // Sunrise with visible moon. caelumSystem->getUniversalClock()->setGregorianDateTime(2007, 4, 9, 9, 33, 0); caelumSystem->getUniversalClock()->setTimeScale(1024); window->addListener(caelumSystem); root->addFrameListener(caelumSystem); }
int main(int argc, char* argv[]) { std::unique_ptr<ExecutionArgs> exArgs(new ExecutionArgs()); if (!processCommandLineArgs(argc, argv, *exArgs)) { return -1; } else if (exArgs->helpPrompt) { std::cout << "Usage: sts [--help] || [--config]" << std::endl; std::cout << "Options:" << std::endl; std::cout << "\t --help - print this message;" << std::endl; std::cout << "\t --config - show config dialog." << std::endl; std::cout << std::endl; return 0; } try { Ogre::String lConfigFileName = "ogre.cfg"; Ogre::String lPluginsFileName = "plugins.cfg"; Ogre::String lLogFileName = "Ogre_STS.log"; std::unique_ptr<Ogre::Root> lRoot(new Ogre::Root(lPluginsFileName, lConfigFileName, lLogFileName)); if (exArgs->showConfigDialog) { if (!lRoot->showConfigDialog()) { return 0; } } Ogre::String lWindowTitle = "STS"; Ogre::String lCustomCapacities = ""; /* Check for the valid ogre.cfg */ bool lCreateAWindowAutomatically = lRoot->restoreConfig(); if (!lCreateAWindowAutomatically) { initSomeRenderSystem(lRoot); } Ogre::RenderWindow* lWindow = lRoot->initialise(lCreateAWindowAutomatically, lWindowTitle, lCustomCapacities); if (!lWindow) { /* ogre.cfg is not available - start with hardcoded parameters */ unsigned int lSizeX = 800; unsigned int lSizeY = 600; bool lFullscreen = false; Ogre::NameValuePairList lParams; lParams["FSAA"] = "0"; lParams["vsync"] = "true"; lWindow = lRoot->createRenderWindow(lWindowTitle, lSizeX, lSizeY, lFullscreen, &lParams); } /* Create a scene manager */ Ogre::SceneManager* lScene = lRoot->createSceneManager(Ogre::ST_GENERIC, "SceneManager"); Ogre::SceneNode* lRootSceneNode = lScene->getRootSceneNode(); /* Create camera */ Ogre::Camera* lCamera = lScene->createCamera("MyCamera"); /* Create viewport (camera <-> window) */ Ogre::Viewport* vp = lWindow->addViewport(lCamera); vp->setAutoUpdated(true); vp->setBackgroundColour(Ogre::ColourValue(1, 0, 1)); lCamera->setAspectRatio(float(vp->getActualWidth()) / vp->getActualHeight()); lCamera->setPosition(Ogre::Vector3(0, 100, -1)); lCamera->lookAt(Ogre::Vector3(0, 0, 0)); /* Set clipping*/ lCamera->setNearClipDistance(1.5f); lCamera->setFarClipDistance(3000.0f); /* Lighting */ Ogre::Light* lLight = lScene->createLight("MainLight"); lLight->setPosition(Ogre::Vector3(0, 100, 0)); /* Resource manager */ Ogre::String lRcGroupName = "Main group"; initResourceMainGroup(lRcGroupName); /* Load model */ Ogre::Entity* lShipEntity = lScene->createEntity("airship.mesh"); lShipEntity->setCastShadows(false); Ogre::SceneNode* lShipNode = lRootSceneNode->createChildSceneNode(); lShipNode->attachObject(lShipEntity); lShipNode->setScale(Ogre::Vector3(3.15f, 3.15f, 3.15f)); /* Starship start point */ Ogre::Vector3 razorSP(0, -200, -100); lShipNode->setPosition(razorSP); /* Sprite billboard */ Ogre::SceneNode* lSpriteNode = lRootSceneNode->createChildSceneNode(); Ogre::BillboardSet* lBillboardSet = lScene->createBillboardSet(); lBillboardSet->setMaterialName("enemy_01", lRcGroupName); lBillboardSet->setTextureStacksAndSlices(1, 4); Ogre::Billboard* lSpriteBillboard = lBillboardSet->createBillboard(Ogre::Vector3(0, 0, 0)); lSpriteBillboard->setDimensions(48.0f / 2.0f, 58.0f / 2.0f); lSpriteBillboard->setTexcoordIndex(1); lSpriteNode->attachObject(lBillboardSet); lSpriteNode->setPosition(Ogre::Vector3(0, -200, 100)); /* Obtain the timer pointer */ Ogre::Timer* lTimer = lRoot->getTimer(); /* Skip all the messages */ lWindow->setAutoUpdated(false); lRoot->clearEventTimes(); while (!lWindow->isClosed()) { float angle = Ogre::Math::Sin(float(lTimer->getMilliseconds()) * Ogre::Math::PI / 2000.0f) * Ogre::Math::PI / 4.0f; float diplacement = Ogre::Math::Cos(float(lTimer->getMilliseconds()) * Ogre::Math::PI / 2000.0f) * 100.0f; lShipNode->setOrientation(Ogre::Quaternion(Ogre::Radian(angle), Ogre::Vector3(0, 0, 1))); lShipNode->setPosition(razorSP + Ogre::Vector3(diplacement, 0.0f, 0.0f)); unsigned int spriteFrame = (lTimer->getMilliseconds() / 125) % 2; lSpriteBillboard->setTexcoordIndex(spriteFrame); lWindow->update(false); lWindow->swapBuffers(); lRoot->renderOneFrame(); Ogre::WindowEventUtilities::messagePump(); } Ogre::LogManager::getSingleton().logMessage("Render window closed."); } catch (Ogre::Exception &e) { std::cerr << "Ogre::Exception: " << e.what() << std::endl; } catch (std::exception &e) { std::cerr << "std::exception: " << e.what() << std::endl; } return 0; }