//------------------------------------------------------------------------------------------- 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())); }
int Hundir::start() { _root = new Ogre::Root(); if(!_root->restoreConfig()) { _root->showConfigDialog(); _root->saveConfig(); } Ogre::RenderWindow* window = _root->initialise(true,"Hundir Example"); _sceneManager = _root->createSceneManager(Ogre::ST_GENERIC); Ogre::Camera* cam = _sceneManager->createCamera("MainCamera"); cam->setPosition(Ogre::Vector3(-10,30,35)); cam->lookAt(Ogre::Vector3(0,0,0)); cam->setNearClipDistance(5); cam->setFarClipDistance(10000); Ogre::Viewport* viewport = window->addViewport(cam); viewport->setBackgroundColour(Ogre::ColourValue(0.0,0.0,0.0)); double width = viewport->getActualWidth(); double height = viewport->getActualHeight(); cam->setAspectRatio(width / height); loadResources(); createScene(); _framelistener = new MyFrameListener(window, cam, _sceneManager); _root->addFrameListener(_framelistener); _root->startRendering(); return 0; }
int startup(){ _root = new Ogre::Root("plugins_d.cfg"); if(!_root->showConfigDialog()){ return -1; } Ogre::RenderWindow* window = _root->initialise(true, "Ventana Ogre"); _sceneManager = _root->createSceneManager(Ogre::ST_GENERIC); Ogre::Camera* camera = _sceneManager->createCamera("Camera"); camera->setPosition(Ogre::Vector3(500,100,500)); camera->lookAt(Ogre::Vector3(0,0,0)); camera->setNearClipDistance(5); Ogre::Viewport* viewport = window->addViewport(camera); viewport->setBackgroundColour(Ogre::ColourValue(0.0,0.0,0.0)); camera->setAspectRatio(Ogre::Real(viewport->getActualWidth()/viewport->getActualHeight())); _listener = new FrameListenerProyectos(window,camera); _root->addFrameListener(_listener); loadResources(); createScene(); _root->startRendering(); return 0; }
void SingleplayerGame::createScene(std::vector<std::string> partyNames){ auto scnMgr = mRenderer->mSceneManager; auto root = scnMgr->getRootSceneNode(); Ogre::Camera* camera = mRenderer->mCamera; mRoomRoot = root->createChildSceneNode(); scnMgr->setSkyBox(true, "Examples/MorningSkyBox", 5000, true); // Set ambient light scnMgr->setAmbientLight(Ogre::ColourValue(0.3, 0.3, 0.3)); scnMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); // Create a light mMainLight = scnMgr->createLight(BaseGame::mainLightName); mMainLight->setPosition(0, 500, 0); mMainLight->setType(Ogre::Light::LT_POINT); mMainLight->setDiffuseColour(.5, .5, .5); // Create ground plane ground = new Plane(scnMgr, mRoomRoot); // Add test objects Player* p = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo(partyNames[0]), Ogre::Vector3(500, 0, 200), mSoundBank); myParty.push_back(p); Player* p2 = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo(partyNames[1]), Ogre::Vector3(500, 0, 0), mSoundBank); myParty.push_back(p2); Player* p3 = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo(partyNames[2]), Ogre::Vector3(500, 0, -200), mSoundBank); myParty.push_back(p3); Player* p4 = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo("Mecha-Scoot"), Ogre::Vector3(-500, 0, 200), mSoundBank); enemyParty.push_back(p4); Player* p5 = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo("SSJVirginia"), Ogre::Vector3(-500, 0, 0), mSoundBank); enemyParty.push_back(p5); Player* p6 = new Player(scnMgr, mRoomRoot, mPlayerBank->getPlayerInfo("Metal Scoot"), Ogre::Vector3(-500, 0, -200), mSoundBank); enemyParty.push_back(p6); // Set Camera Position cameraInitialPosition = Ogre::Vector3(1100, 250, 700); cameraInitialLookAt = Ogre::Vector3(0, 0, 0); camera->setPosition(cameraInitialPosition); camera->lookAt(cameraInitialLookAt); }
// 设置观察点的位置 ogre 坐标. VOID CEngineInterface::Camera_SetLookAtPos(const fVector3& fvPos) { if(m_pFairySystem) { Ogre::Camera* pOgreCamera = m_pFairySystem->getCamera(); pOgreCamera->lookAt(Ogre::Vector3(fvPos.x, fvPos.y, fvPos.z)); } }
// 设置观察点的位置 ogre 坐标. VOID CRenderSystem::Camera_SetLookAtPos(const fVector3& fvPos) { if(m_pRenderSystem) { Ogre::Camera* pOgreCamera = m_pRenderSystem->getCamera(); pOgreCamera->lookAt(Ogre::Vector3(fvPos.x, fvPos.y, fvPos.z)); } }
int main(int argc, char* argv[]){ cout << "Test Ogre Program blaha" << endl; //Relative to where its executed from, not binary location Ogre::Root *mRoot = new Ogre::Root("configs/plugins.cfg","configs/config.cfg","logs/main.log"); if(!(mRoot->restoreConfig() || mRoot->showConfigDialog())){ delete mRoot; return -1; } // setup resources // Only add the minimally required resource locations to load up the Ogre head mesh Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/programs", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/programs/GLSL", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/scripts", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/materials/textures", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/Users/jgrey/OgreSDK/Media/models", "FileSystem", "General"); //Create the window Ogre::RenderWindow *mWindow = mRoot->initialise(true, "initial Render Window"); Ogre::SceneManager *sceneManager = mRoot->createSceneManager(Ogre::ST_GENERIC); Ogre::Camera *camera = sceneManager->createCamera("PlayerCam"); camera->setPosition(Ogre::Vector3(0,0,80)); camera->lookAt(Ogre::Vector3(0,0,-300)); camera->setNearClipDistance(5); Ogre::Viewport* vp = mWindow->addViewport(camera); vp->setBackgroundColour(Ogre::ColourValue(0,0,0,0)); camera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); Ogre::Entity* ogreHead = sceneManager->createEntity("Head","ogreHead.mesh"); Ogre::SceneNode* headNode = sceneManager->getRootSceneNode()->createChildSceneNode(); headNode->attachObject(ogreHead); sceneManager->setAmbientLight(Ogre::ColourValue(0.5,0.5,0.5)); //Run the system bool continueRunning = true; while(continueRunning){ mRoot->renderOneFrame(); headNode->rotate(Ogre::Vector3(0,1,0),Ogre::Radian(0.005)); if(mWindow->isClosed()){ continueRunning = false; } } delete mRoot; }
void application::create_camera() { cam = scene_mgr->createCamera("PlayerCam"); cam->setPosition(Ogre::Vector3 {0, 0, 80}); cam->lookAt(Ogre::Vector3 {0, 0, -300}); cam->setNearClipDistance(5); cameraman = new OgreBites::SdkCameraMan(cam); }
void GraphicsImpl::createCamera() { camera = sceneMgr->createCamera("MainCamera"); // Position it at 500 in Z direction camera->setPosition(Ogre::Vector3(0, 50, 100)); // Look back along -Z camera->lookAt(Ogre::Vector3(0, -10, 0)); camera->setNearClipDistance(5); camera->setFarClipDistance(0); }
void BaseApp::createCamera() { Ogre::Camera* cam = mSceneMgr->createCamera("PlayerCam"); cam->setPosition(0,0,0); cam->lookAt(0,0,0); //cam->setAutoAspectRatio(true); cam->setNearClipDistance(1); cam->setFarClipDistance(10000); mCameraMan = new OgreBites::SdkCameraMan(cam); mCameraMan->setTopSpeed(1000); }
// funcion que configura la camara void createCamera(Ogre::RenderWindow* window){ camera = _sceneManager->createCamera("Camera"); camera->setPosition(Ogre::Vector3(0,60,-100)); camera->lookAt(Ogre::Vector3(0,0,50)); camera->setNearClipDistance(5); Ogre::Viewport* viewport = window->addViewport(camera); viewport->setBackgroundColour(Ogre::ColourValue(0.0,0.0,0.0)); camera->setAspectRatio(Ogre::Real(viewport->getActualWidth())/Ogre::Real(viewport->getActualHeight())); }
//------------------------------------------------------------------------ void TApplySetup_CameraUp::WorkFromThread_Ogre() { Ogre::Camera* pCamera = TModuleLogic::Get()->GetC()->pGraphicEngine->GetGE()->GetCamera(); nsMathTools::TVector3 point(0,0,0); pCamera->setPosition(point.x, point.y, point.z); pCamera->lookAt(mVCameraUp.x, mVCameraUp.y, mVCameraUp.z); Ogre::Degree degree; degree = 90; Ogre::Radian rad; rad = degree.valueRadians(); pCamera->pitch(rad); }
void ReliefApp::GenerateRelief() { //Get depth data Ogre::TexturePtr depthTex = Ogre::TextureManager::getSingleton().createManual( "DepthTexture", // name Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, // type 512, // width 512, // height 0, // number of mipmaps //Ogre::PF_B8G8R8A8, // pixel format Ogre::PF_FLOAT32_R, Ogre::TU_RENDERTARGET ); Ogre::RenderTarget* pTarget = depthTex->getBuffer()->getRenderTarget(); Ogre::Camera* pOrthCam = MagicCore::RenderSystem::GetSingleton()->GetMainCamera(); pOrthCam->setProjectionType(Ogre::PT_ORTHOGRAPHIC); pOrthCam->setOrthoWindow(3, 3); pOrthCam->setPosition(0, 0, 3); pOrthCam->lookAt(0, 0, 0); pOrthCam->setAspectRatio(1.0); pOrthCam->setNearClipDistance(0.5); pOrthCam->setFarClipDistance(5); Ogre::Viewport* pViewport = pTarget->addViewport(pOrthCam); pViewport->setDimensions(0, 0, 1, 1); MagicCore::RenderSystem::GetSingleton()->RenderLightMesh3D("RenderMesh", "Depth", mpLightMesh); MagicCore::RenderSystem::GetSingleton()->Update(); Ogre::Image img; depthTex->convertToImage(img); std::vector<double> heightField(512 * 512); for(int x = 0; x < 512; x++) { for(int y = 0; y < 512; y++) { heightField.at(x * 512 + y) = (img.getColourAt(x, 511 - y, 0))[1]; } } Ogre::TextureManager::getSingleton().remove("DepthTexture"); // MagicDGP::LightMesh3D* pReliefMesh = MagicDGP::ReliefGeneration::PlaneReliefFromHeightField(heightField, 511, 511); //MagicDGP::LightMesh3D* pReliefMesh = MagicDGP::ReliefGeneration::CylinderReliefFromHeightField(heightField, 511, 511); if (pReliefMesh != NULL) { delete mpLightMesh; mpLightMesh = pReliefMesh; mpLightMesh->UnifyPosition(2); mpLightMesh->UpdateNormal(); } MagicCore::RenderSystem::GetSingleton()->SetupCameraDefaultParameter(); MagicCore::RenderSystem::GetSingleton()->RenderLightMesh3D("RenderMesh", "MyCookTorrance", mpLightMesh); }
void World::EnableFreeCamera( bool bEnable ) { assert(m_pRenderSystem->m_pMainCamera && m_cameraMan); if(!bEnable) { Ogre::Camera* cam = m_pRenderSystem->m_pMainCamera; const Ogre::Vector3 pos = cam->getPosition(); cam->setPosition(0, 24, 0); cam->lookAt(0, 0, 8); } m_bFreeCamMode = bEnable; }
static void setupScene() { LOGI("------->setupScene()"); Ogre::ConfigFile cf; cf.load(openAPKFile("resources.cfg")); Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); while (seci.hasMoreElements()) { Ogre::String sec, type, arch; sec = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap* settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); i++) { type = i->first; arch = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation(arch, type, sec); } } Ogre::ResourceGroupManager::getSingletonPtr()->initialiseResourceGroup( Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); gSceneMgr = gRoot->createSceneManager(Ogre::ST_GENERIC); Ogre::Camera* camera = gSceneMgr->createCamera("MyCam"); Ogre::Entity* pEntity = gSceneMgr->createEntity("SinbadInstance", "Sinbad.mesh"); Ogre::SceneNode* pNode = gSceneMgr->getRootSceneNode()->createChildSceneNode(); pNode->attachObject(pEntity); Ogre::Light* pDirLight = gSceneMgr->createLight(); pDirLight->setDirection(Ogre::Vector3(0, -1, 0)); pDirLight->setType(Ogre::Light::LT_DIRECTIONAL); pNode->attachObject(pDirLight); camera->setNearClipDistance(1.0f); camera->setFarClipDistance(100000.0f); camera->setPosition(0, 0, 20.0f); camera->lookAt(0, 0, 0); camera->setAutoAspectRatio(true); Ogre::Viewport* vp = gRenderWnd->addViewport(camera); vp->setBackgroundColour(Ogre::ColourValue(1, 0, 0)); LOGI("<-------setupScene()"); }
int MyApp::start() { _root = new Ogre::Root(); if(!_root->restoreConfig()) { _root->showConfigDialog(); _root->saveConfig(); } _pTrackManager = new TrackManager; _pSoundFXManager = new SoundFXManager; Ogre::RenderWindow* window = _root->initialise(true,"MyApp Example"); _sceneManager = _root->createSceneManager(Ogre::ST_GENERIC); Ogre::Camera* cam = _sceneManager->createCamera("MainCamera"); cam->setPosition(Ogre::Vector3(7,10.5,8)); cam->lookAt(Ogre::Vector3(0,3.5,0)); cam->setNearClipDistance(5); cam->setFarClipDistance(10000); Ogre::Viewport* viewport = window->addViewport(cam); viewport->setBackgroundColour(Ogre::ColourValue(0.0,0.0,0.0)); double width = viewport->getActualWidth(); double height = viewport->getActualHeight(); cam->setAspectRatio(width / height); loadResources(); createScene(); createOverlay(); Ogre::SceneNode *node = _sceneManager->getSceneNode("Neptuno"); _framelistener = new MyFrameListener(this, window, cam, node, _overlayManager, _sceneManager); _root->addFrameListener(_framelistener); // Reproducción del track principal... this->_mainTrack->play(); _root->startRendering(); return 0; }
//--------------------------------------------------------------------------------------------- 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); }
//---------------------------------------------------------------------------------------- ImageConverter::ImageConverter(const size_t& width/*=128*/, const size_t& height/*=128*/) { mWidth = width; mHeight = height; mResourceManager = Ogre::ResourceGroupManager::getSingletonPtr(); mResourceManager->createResourceGroup("QTImageConverter"); mResourceManager->initialiseResourceGroup("QTImageConverter"); mSceneMgrPtr = Ogre::Root::getSingletonPtr()->createSceneManager("OctreeSceneManager", "QTImageConverterSceneManager"); mSceneMgrPtr->setAmbientLight(Ogre::ColourValue(1, 1, 1)); Ogre::TexturePtr rendertexture = Ogre::TextureManager::getSingleton().createManual("RenderTex", "QTImageConverter", Ogre::TEX_TYPE_2D, mWidth, mHeight, 1, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); mRttTex = rendertexture->getBuffer()->getRenderTarget(); // create our plane to set a texture to Ogre::Plane plane(Ogre::Vector3::UNIT_Z, 0); Ogre::MeshManager::getSingleton().createPlane("terrain", "QTImageConverter", plane, 100, 100, 1, 1, true, 1, 1, 1, Ogre::Vector3::UNIT_Y); // attach the plane to the scene manager and rotate it so the camera can see it mEntityTerrain = mSceneMgrPtr->createEntity("terrainEntity", "terrain"); Ogre::SceneNode* node = mSceneMgrPtr->getRootSceneNode()->createChildSceneNode(); node->attachObject(mEntityTerrain); mEntityTerrain->setCastShadows(false); Ogre::Camera* RTTCam = mSceneMgrPtr->createCamera("QTImageConverterCam"); RTTCam->setNearClipDistance(0.01F); RTTCam->setFarClipDistance(0); RTTCam->setAspectRatio(1); RTTCam->setFOVy(Ogre::Degree(90)); RTTCam->setPosition(0, 0, 50); RTTCam->lookAt(0, 0, 0); Ogre::Viewport *v = mRttTex->addViewport(RTTCam); v->setBackgroundColour(Ogre::ColourValue(1, 1, 1)); v->setClearEveryFrame(true); }
int startup(){ _root = new Ogre::Root("plugins_d.cfg"); /* if(!_root->showConfigDialog()){ return -1; } */ Ogre::RenderSystem* _rs = _root->getRenderSystemByName("Direct3D9 Rendering Subsystem"); // or use "OpenGL Rendering Subsystem" _root->setRenderSystem(_rs); _rs->setConfigOption("Full Screen", "No"); _rs->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour"); _rs->setConfigOption("FSAA", "0"); _rs->setConfigOption("Floating-point mode", "Fastest"); _rs->setConfigOption("Use Multihead", "Auto"); _rs->setConfigOption("VSync", "No"); _rs->setConfigOption("VSync Interval", "1"); Ogre::RenderWindow* window = _root->initialise(true, "Ventana Ogre"); _sceneManager = _root->createSceneManager(Ogre::ST_GENERIC); Ogre::Camera* camera = _sceneManager->createCamera("Camera"); camera->setPosition(Ogre::Vector3(0.0f,300.0f,-1000.0f)); camera->lookAt(Ogre::Vector3(0,0,0)); camera->setNearClipDistance(5); Ogre::Viewport* viewport = window->addViewport(camera); viewport->setBackgroundColour(Ogre::ColourValue(0.0,0.0,0.0)); camera->setAspectRatio(Ogre::Real(viewport->getActualWidth()/viewport->getActualHeight())); _listener = new FrameListenerProyectos(window,camera); _root->addFrameListener(_listener); loadResources(); createScene(); _root->startRendering(); return 0; }
void InputHandler::miniMap(){ Ogre::TexturePtr tex = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual( "RTT", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); Ogre::RenderTexture *rtex = tex->getBuffer()->getRenderTarget(); Ogre::Camera *cam = mSceneMgr->createCamera("MiniCam"); //Vector3 fool = Ogre::Vector3(1550,0,1250); cam->setPosition(0, 300, 0); cam->lookAt(750,50,750); Ogre::Viewport *v = rtex->addViewport(cam); v->setOverlaysEnabled(false); v->setClearEveryFrame(true); v->setBackgroundColour(Ogre::ColourValue::Black); CEGUI::Texture &guiTex = mGUIRenderer->createTexture(tex); CEGUI::Imageset &imageSet = CEGUI::ImagesetManager::getSingleton().create("RTTImageset", guiTex); imageSet.defineImage("RTTImage", CEGUI::Point(0.0f, 0.0f), CEGUI::Size(guiTex.getSize().d_width, guiTex.getSize().d_height), CEGUI::Point(0.0f, 0.0f)); mini_map = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "RTTWindow"); mini_map->setSize(CEGUI::UVector2(CEGUI::UDim(0.3f, 0),CEGUI::UDim(0.2f, 0))); mini_map->setPosition(CEGUI::UVector2(CEGUI::UDim(0.69f, 0),CEGUI::UDim(0.0f, 0))); mini_map->setProperty("Image", CEGUI::PropertyHelper::imageToString(&imageSet.getImage("RTTImage"))); sheet->addChildWindow(mini_map); mini_map->setVisible(false); }
void OgreApplication::InitViewport(void){ try { /* Retrieve scene manager and root scene node */ Ogre::SceneManager* scene_manager = ogre_root_->createSceneManager(Ogre::ST_GENERIC, "MySceneManager"); Ogre::SceneNode* root_scene_node = scene_manager->getRootSceneNode(); /* Create camera object */ Ogre::Camera* camera = scene_manager->createCamera("MyCamera"); Ogre::SceneNode* camera_scene_node = root_scene_node->createChildSceneNode("MyCameraNode"); camera_scene_node->attachObject(camera); camera->setNearClipDistance(camera_near_clip_distance_g); camera->setFarClipDistance(camera_far_clip_distance_g); camera->setPosition(camera_position_g); camera->lookAt(camera_look_at_g); camera->setFixedYawAxis(true, camera_up_g); /* Create viewport */ Ogre::Viewport *viewport = ogre_window_->addViewport(camera, viewport_z_order_g, viewport_left_g, viewport_top_g, viewport_width_g, viewport_height_g); viewport->setAutoUpdated(true); viewport->setBackgroundColour(viewport_background_color_g); /* Set aspect ratio */ float ratio = float(viewport->getActualWidth()) / float(viewport->getActualHeight()); camera->setAspectRatio(ratio); } catch (Ogre::Exception &e){ throw(OgreAppException(std::string("Ogre::Exception: ") + std::string(e.what()))); } catch(std::exception &e){ throw(OgreAppException(std::string("std::Exception: ") + std::string(e.what()))); } }
int _tmain(int argc, _TCHAR* argv[]) { // ------------------------- Check for command line argument ------------------------------------------- if (! argv[1]) { printf("\n"); printf("Missing argument.\nExample: \"Converter.exe job1.cfg\""); return 0; } // ------------------------- Basic Ogre Engine initialization ------------------------------------------- Ogre::Root* root = new Ogre::Root; Ogre::RenderSystem* rendersys = root->getRenderSystemByName("Direct3D9 Rendering Subsystem"); rendersys->setConfigOption("Full Screen", "No"); rendersys->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour"); root->setRenderSystem(rendersys); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resource", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); root->initialise(false); Ogre::RenderWindow* window = root->createRenderWindow("RAW2OGT", 800, 600, false); Ogre::SceneManager* scenemgr = root->createSceneManager(Ogre::SceneType::ST_GENERIC); Ogre::Camera* camera = scenemgr->createCamera("camera"); Ogre::Viewport* viewport = window->addViewport(camera); /*Ogre::Vector3 lightdir(0, -0.3, 0.75); lightdir.normalise(); Ogre::Light* l = scenemgr->createLight("tstLight"); l->setType(Ogre::Light::LT_DIRECTIONAL); l->setDirection(lightdir); l->setDiffuseColour(Ogre::ColourValue(1.0, 1.0, 1.0)); l->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4));*/ scenemgr->setAmbientLight(Ogre::ColourValue(0.7, 0.7, 0.7)); // --------------------------------- Start convert ---------------------------------------------------- // Load job config Ogre::ConfigFile* terrainconfig = OGRE_NEW Ogre::ConfigFile(); terrainconfig->loadDirect(argv[1]); // Load info from [general] block Ogre::String heightmapfile = terrainconfig->getSetting("heightmap", "general"); Ogre::Real heightmapscale = Ogre::StringConverter::parseReal(terrainconfig->getSetting("heightmapscale", "general")); Ogre::Real heightmapoffset = Ogre::StringConverter::parseReal(terrainconfig->getSetting("heightmapoffset", "general")); Ogre::uint16 terrainsize = Ogre::StringConverter::parseUnsignedInt(terrainconfig->getSetting("terrainsize", "general")); Ogre::Real worldsize = Ogre::StringConverter::parseReal(terrainconfig->getSetting("worldsize", "general")); Ogre::uint16 layercount = Ogre::StringConverter::parseUnsignedInt(terrainconfig->getSetting("layercount", "general")); // initialise stream to heightmapfile Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(heightmapfile, "General"); size_t size = stream.get()->size(); // verify size if(size != terrainsize * terrainsize * 4) OGRE_EXCEPT( Ogre::Exception::ERR_INTERNAL_ERROR, "Size of stream does not match terrainsize!", "TerrainPage" ); // load to buffer float* buffer = OGRE_ALLOC_T(float, size, Ogre::MEMCATEGORY_GENERAL); stream->read(buffer, size); // apply scale and offset for(int i=0;i<terrainsize*terrainsize;i++) { buffer[i] = (buffer[i] + heightmapoffset) * heightmapscale; } // Terrain initialization Ogre::TerrainGlobalOptions* terrainglobals = OGRE_NEW Ogre::TerrainGlobalOptions(); terrainglobals->setMaxPixelError(1); //terrainglobals->setCompositeMapDistance(30000); //terrainglobals->setLightMapDirection(lightdir); //terrainglobals->setCompositeMapAmbient(scenemgr->getAmbientLight()); //terrainglobals->setCompositeMapDiffuse(l->getDiffuseColour()); Ogre::TerrainMaterialGeneratorA::SM2Profile* pMatProfile = static_cast<Ogre::TerrainMaterialGeneratorA::SM2Profile*>(terrainglobals->getDefaultMaterialGenerator()->getActiveProfile()); pMatProfile->setLightmapEnabled(false); pMatProfile->setCompositeMapEnabled(false); Ogre::TerrainGroup* terraingroup = OGRE_NEW Ogre::TerrainGroup(scenemgr, Ogre::Terrain::ALIGN_X_Z, terrainsize, worldsize); terraingroup->setFilenameConvention(Ogre::String("terrain"), Ogre::String("ogt")); terraingroup->setOrigin(Ogre::Vector3::ZERO); Ogre::Terrain* terrain = OGRE_NEW Ogre::Terrain(scenemgr); // terrainsettings Ogre::Terrain::ImportData& imp = terraingroup->getDefaultImportSettings(); imp.terrainSize = terrainsize; imp.worldSize = worldsize; imp.minBatchSize = 33; imp.maxBatchSize = 65; // use float RAW heightmap as input imp.inputFloat = buffer; // process texture layers imp.layerList.resize(layercount); Ogre::StringVector blendmaps(layercount); for(int i=0;i<layercount;i++) { // load layer info Ogre::String sectionStr = Ogre::StringConverter::toString(i); Ogre::Real layerworldsize = Ogre::StringConverter::parseReal(terrainconfig->getSetting("worldsize", sectionStr)); if (i==0) { // no blendmap at layer 0 (baselayer) Ogre::String specular = terrainconfig->getSetting("specular", sectionStr); Ogre::String normal = terrainconfig->getSetting("normal", sectionStr); // add layer imp.layerList[i].textureNames.push_back(specular); imp.layerList[i].textureNames.push_back(normal); imp.layerList[i].worldSize = layerworldsize; } else { Ogre::String specular = terrainconfig->getSetting("specular", sectionStr); Ogre::String normal = terrainconfig->getSetting("normal", sectionStr); Ogre::String blend = terrainconfig->getSetting("blend", sectionStr); // add layer imp.layerList[i].textureNames.push_back(specular); imp.layerList[i].textureNames.push_back(normal); imp.layerList[i].worldSize = layerworldsize; blendmaps[i] = blend; } } // load the terrain terrain->prepare(imp); terrain->load(); // load those blendmaps into the layers for(int j = 1;j < terrain->getLayerCount();j++) { Ogre::TerrainLayerBlendMap *blendmap = terrain->getLayerBlendMap(j); Ogre::Image img; img.load(blendmaps[j],"General"); int blendmapsize = terrain->getLayerBlendMapSize(); if(img.getWidth() != blendmapsize) img.resize(blendmapsize, blendmapsize); float *ptr = blendmap->getBlendPointer(); Ogre::uint8 *data = static_cast<Ogre::uint8*>(img.getPixelBox().data); for(int bp = 0;bp < blendmapsize * blendmapsize;bp++) ptr[bp] = static_cast<float>(data[bp]) / 255.0f; blendmap->dirty(); blendmap->update(); } // create filename for writing int pos = heightmapfile.find_last_of('.'); if (pos < 0) heightmapfile = heightmapfile + ".ogt"; else heightmapfile = heightmapfile.substr(0, pos) + ".ogt"; // save as Ogre .OGT terrain->save(heightmapfile); Ogre::LogManager::getSingletonPtr()->logMessage(Ogre::LogMessageLevel::LML_NORMAL, heightmapfile + " successfully written."); // debug viewing (exit with CTRL+C) camera->setPosition(-terrainsize, 7000, -terrainsize); camera->lookAt(terrainsize/2,0,terrainsize/2); root->startRendering(); return 0; }
Camera::Camera(Event::Lane& lane, GameHandle cameraHandle, Ogre::SceneNode* camNode, Ogre::RenderTarget* renderTarget, u32 width, u32 height, const v3& position, const qv4& orientation, GameHandle parent) : mSubLane(lane.createSubLane()), mCameraNode(camNode), mRenderTarget(renderTarget), mHandle(cameraHandle), mNodeCreated(false), mRenderTargetCreated(false) { Ogre::SceneManager* sceneMgr = Ogre::Root::getSingleton().getSceneManager(BFG_SCENEMANAGER); if (mCameraNode == NULL) // Create SceneNode { if (sceneMgr->hasSceneNode(stringify(mHandle))) { mCameraNode = sceneMgr->getSceneNode(stringify(mHandle)); } else { mCameraNode = sceneMgr->getRootSceneNode()->createChildSceneNode(stringify(mHandle)); mNodeCreated = true; } } mCameraNode->setOrientation(toOgre(orientation)); mCameraNode->setPosition(toOgre(position)); v3 target = toBFG(mCameraNode->getOrientation().zAxis()); norm(target); Ogre::Camera* cam; cam = sceneMgr->createCamera(stringify(mHandle)); cam->setFOVy(Ogre::Degree(60.0f)); cam->setNearClipDistance(0.1f); cam->setFarClipDistance(250000.0f); cam->lookAt(toOgre(target)*10); mCameraNode->attachObject(cam); infolog << "Camera: " << stringify(mHandle) << " created."; if (mRenderTarget == NULL) { // Create renderToTexture RenderTarget if (width == 0 || height == 0) { throw std::logic_error("Too few information to create a render target."); } cam->setAspectRatio((f32)width / (f32)height); Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual ( stringify(mHandle), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET ); mRenderTarget = texture->getBuffer()->getRenderTarget(); prepareRenderTarget(); mRenderTarget->addViewport(cam); mRenderTarget->getViewport(0)->setClearEveryFrame(true); mRenderTarget->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black); mRenderTarget->getViewport(0)->setOverlaysEnabled(false); Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(stringify(mHandle)); if (mat.isNull()) { mat = Ogre::MaterialManager::getSingleton().create( stringify(mHandle), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); } Ogre::Technique* tech = mat->getTechnique(0); if (!tech) { tech = mat->createTechnique(); } Ogre::Pass* pass = tech->getPass(0); if (!pass) { pass = tech->createPass(); } pass->setLightingEnabled(false); if (pass->getNumTextureUnitStates() > 0) { Ogre::TextureUnitState* txState = NULL; txState = pass->getTextureUnitState(0); txState->setTextureName(stringify(mHandle)); } else { pass->createTextureUnitState(stringify(mHandle)); } mRenderTarget->setAutoUpdated(true); mRenderTargetCreated = true; infolog << "Rendertarget: " << stringify(mHandle) << " created."; } else { prepareRenderTarget(); f32 width = static_cast<f32>(mRenderTarget->getWidth()); f32 height = static_cast<f32>(mRenderTarget->getHeight()); cam->setAspectRatio(width / height); mRenderTarget->addViewport(cam); } // mSubLane->connect(ID::VE_UPDATE_POSITION, this, &Camera::updatePosition, mHandle); // mSubLane->connect(ID::VE_UPDATE_ORIENTATION, this, &Camera::updateOrientation, mHandle); mSubLane->connect(ID::VE_SET_CAMERA_TARGET, this, &Camera::onSetTarget, mHandle); if (parent != NULL_HANDLE) { onSetTarget(parent); } }
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(); }
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #else int main (int argc, char *argv[]) { #endif #define OGRE_STATIC_ParticleFX 1 Ogre::Root *ogre; Ogre::RenderWindow *window; Ogre::SceneManager *sceneMgr; Ogre::Camera *camera; // fire up an Ogre rendering window. Clearing the first two (of three) params will let us // specify plugins and resources in code instead of via text file ogre = new Ogre::Root("", ""); // This is a VERY minimal rendersystem loading example; we are hardcoding the OpenGL // renderer, instead of loading GL and D3D9. We will add renderer selection support in a // future article. // I separate the debug and release versions of my plugins using the same "_d" suffix that // the Ogre main libraries use; you may need to remove the "_d" in your code, depending on the // naming convention you use ogre->loadPlugin("RenderSystem_GL_d"); ogre->loadPlugin("Plugin_ParticleFX_d"); const Ogre::RenderSystemList &renderSystems = ogre->getAvailableRenderers(); Ogre::RenderSystemList::const_iterator r_it; // we do this step just to get an iterator that we can use with setRenderSystem. In a future article // we actually will iterate the list to display which renderers are available. // renderSystems = ogre->getAvailableRenderers(); r_it = renderSystems.begin(); ogre->setRenderSystem(*r_it); ogre->initialise(false); // load common plugins ogre->loadPlugin("Plugin_CgProgramManager_d"); ogre->loadPlugin("Plugin_OctreeSceneManager_d"); // setup main window; hardcode some defaults for the sake of presentation Ogre::NameValuePairList opts; opts["resolution"] = "1024x768"; opts["fullscreen"] = "false"; opts["vsync"] = "true"; // create a rendering window with the title "CDK" window = ogre->createRenderWindow("CDK", 1024, 768, false, &opts); // load the basic resource location(s) Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "resource", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "resource/gui.zip", "Zip", "GUI"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "resource/textures", "FileSystem", "Textures"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "resource/particles", "FileSystem", "Particles"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "resource/materials", "FileSystem", "Materials"); #if defined(WIN32) Ogre::ResourceGroupManager::getSingleton().addResourceLocation( "c:\\windows\\fonts", "FileSystem", "GUI"); #endif //Must initialize resource groups after window if using particle effects. Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("GUI"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Textures"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Materials"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Particles"); // since this is basically a CEGUI app, we can use the ST_GENERIC scene manager for now; in a later article // we'll see how to change this sceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC); camera = sceneMgr->createCamera("camera"); camera->setNearClipDistance(1); Ogre::Viewport* vp = window->addViewport(camera); vp->setBackgroundColour(Ogre::ColourValue(0,0,0)); // most examples get the viewport size to calculate this; for now, we'll just // set it to 4:3 the easy way camera->setAspectRatio((Ogre::Real)1.333333); // with a scene manager and window, we can create a the GUI renderer // new way to instantiate a CEGUIOgreRenderer (Ogre 1.7) Ogre::RenderTarget *mRenderTarget = window; CEGUI::OgreRenderer* pGUIRenderer = &CEGUI::OgreRenderer::bootstrapSystem(*mRenderTarget); // create the root CEGUI class CEGUI::System* pSystem = CEGUI::System::getSingletonPtr(); // tell us a lot about what is going on (see CEGUI.log in the working directory) CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative); // use this CEGUI scheme definition (see CEGUI docs for more) CEGUI::SchemeManager::getSingleton().create((CEGUI::utf8*)"TaharezLookSkin.scheme", (CEGUI::utf8*)"GUI"); // show the CEGUI mouse cursor (defined in the look-n-feel) pSystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow"); // use this font for text in the UI CEGUI::FontManager::getSingleton().create("Tahoma-8.font", (CEGUI::utf8*)"GUI"); pSystem->setDefaultFont((CEGUI::utf8*)"Tahoma-8"); // load a layout from the XML layout file (you'll find this in resources/gui.zip), and // put it in the GUI resource group CEGUI::Window* pLayout = CEGUI::WindowManager::getSingleton().loadWindowLayout("katana.layout", "", "GUI"); // you need to tell CEGUI which layout to display. You can call this at any time to change the layout to // another loaded layout (i.e. moving from screen to screen or to load your HUD layout). Note that this takes // a CEGUI::Window instance -- you can use anything (any widget) that serves as a root window. pSystem->setGUISheet(pLayout); // this next bit is for the sake of the input handler unsigned long hWnd; // WINDOW is generic to all platforms now as of Eihort window->getCustomAttribute("WINDOW", &hWnd); // set up the input handlers Simulation *sim = new Simulation(); // since the input handler deals with pushing input to CEGUI, we need to give it a pointer // to the CEGUI System instance to use InputHandler *handler = new InputHandler(pSystem, sim, hWnd); // put us into our "main menu" state sim->requestStateChange(GUI); // make an instance of our GUI sheet handler class MainMenuDlg* pDlg = new MainMenuDlg(pSystem, pLayout, sim); //testing shit Ogre::SceneNode *systemNode = sceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,0)); SphereMesh *sphere = NULL; sphere->createSphere("sphereMesh", 80, 64, 64); /* // Now I can create several entities using that mesh Ogre::Entity *MoonEntity = sceneMgr->createEntity("Moon", planetMesh); // Now I attach it to a scenenode, so that it becomes present in the scene. Ogre::SceneNode *EarthOrbitNode = systemNode->createChildSceneNode("Earth Orbit", Ogre::Vector3(0,0,0)); Ogre::SceneNode *EarthNode = EarthOrbitNode->createChildSceneNode("Earth", Ogre::Vector3(200,0,0)); Ogre::SceneNode *MoonNode = EarthNode->createChildSceneNode("Moon", Ogre::Vector3(150,0,0)); MoonNode->attachObject(MoonEntity); MoonEntity->getParentNode()->scale(0.5,0.5,0.5); */ //Material Tests Ogre::MaterialManager& lMaterialManager = Ogre::MaterialManager::getSingleton(); Ogre::String lNameOfResourceGroup = "Mission 1 : Deliver Tom"; Ogre::ResourceGroupManager& lRgMgr = Ogre::ResourceGroupManager::getSingleton(); lRgMgr.createResourceGroup(lNameOfResourceGroup); { Ogre::MaterialPtr lMaterial = lMaterialManager.create("M_Lighting+OneTexture",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); lFirstPass->setDiffuse(0.8f, 0.8f, 0.8f,1.0f); lFirstPass->setAmbient(0.3f, 0.3f, 0.3f); lFirstPass->setSpecular(1.0f, 1.0f, 1.0f, 1.0f); lFirstPass->setShininess(64.0f); lFirstPass->setSelfIllumination(0.1f, 0.1f, 0.1f); Ogre::TextureUnitState* lTextureUnit = lFirstPass->createTextureUnitState(); lTextureUnit->setTextureName("SimpleTexture.bmp", Ogre::TEX_TYPE_2D); lTextureUnit->setTextureCoordSet(0); } // 3/ Lighting color. // To have the feeling of '3D', the lighting is good feeling. // It often requires the object to have correct normals (see my manual object construction), // and some lights in the scene. { Ogre::MaterialPtr lMaterial = lMaterialManager.create("Sun",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); // Lighting is allowed on this pass. lFirstPass->setLightingEnabled(true); // Emissive / self illumination is the color 'produced' by the object. // Color values vary between 0.0(minimum) to 1.0 (maximum). Ogre::ColourValue lSelfIllumnationColour(0.5f, 0.0f, 0.0f, 1.0f); lFirstPass->setSelfIllumination(lSelfIllumnationColour); // diffuse color is the traditionnal color of the lit object. Ogre::ColourValue lDiffuseColour(1.0f, 0.4f, 0.4f, 1.0f); lFirstPass->setDiffuse(lDiffuseColour); // ambient colour is linked to ambient lighting. // If there is no ambient lighting, then this has no influence. // It the ambient lighting is at 1, then this colour is fully added. // This is often use to change the general feeling of a whole scene. Ogre::ColourValue lAmbientColour(0.4f, 0.1f, 0.1f, 1.0f); lFirstPass->setAmbient(lAmbientColour); // specular colour, is the colour of the 'little light reflection' // that you can see on some object. For example, my bald head skin // reflect the sun. This make a 'round of specular lighting'. // Set this to black if you don't want to see it. Ogre::ColourValue lSpecularColour(1.0f, 1.0f, 1.0f, 1.0f); lFirstPass->setSpecular(lSpecularColour); // Shininess is the 'inverse of specular color splattering' coefficient. // If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface). // If this is 0, you get a simple color layer (the dot has become very wide). Ogre::Real lShininess = 64.0f; lFirstPass->setShininess(lShininess); } { Ogre::MaterialPtr lMaterial = lMaterialManager.create("mars",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); // Lighting is allowed on this pass. lFirstPass->setLightingEnabled(true); // Emissive / self illumination is the color 'produced' by the object. // Color values vary between 0.0(minimum) to 1.0 (maximum). Ogre::ColourValue lSelfIllumnationColour(0.6f, 0.1f, 0.1f, 0.0f); lFirstPass->setSelfIllumination(lSelfIllumnationColour); // diffuse color is the traditionnal color of the lit object. Ogre::ColourValue lDiffuseColour(1.0f, 0.2f, 0.0f, 0.0f); lFirstPass->setDiffuse(lDiffuseColour); // ambient colour is linked to ambient lighting. // If there is no ambient lighting, then this has no influence. // It the ambient lighting is at 1, then this colour is fully added. // This is often use to change the general feeling of a whole scene. Ogre::ColourValue lAmbientColour(1.0f, 0.2f, 0.0f, 0.0f); lFirstPass->setAmbient(lAmbientColour); // specular colour, is the colour of the 'little light reflection' // that you can see on some object. For example, my bald head skin // reflect the sun. This make a 'round of specular lighting'. // Set this to black if you don't want to see it. Ogre::ColourValue lSpecularColour(1.0f, 0.3f, 0.3f, 0.3f); lFirstPass->setSpecular(lSpecularColour); // Shininess is the 'inverse of specular color splattering' coefficient. // If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface). // If this is 0, you get a simple color layer (the dot has become very wide). Ogre::Real lShininess = 34.0f; lFirstPass->setShininess(lShininess); } { Ogre::MaterialPtr lMaterial = lMaterialManager.create("gaia",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); // Lighting is allowed on this pass. lFirstPass->setLightingEnabled(true); // Emissive / self illumination is the color 'produced' by the object. // Color values vary between 0.0(minimum) to 1.0 (maximum). Ogre::ColourValue lSelfIllumnationColour(0.0f, 0.0f, 0.1f, 0.3f); lFirstPass->setSelfIllumination(lSelfIllumnationColour); // diffuse color is the traditionnal color of the lit object. Ogre::ColourValue lDiffuseColour(0.1f, 0.2f, 0.8f, 1.0f); lFirstPass->setDiffuse(lDiffuseColour); // ambient colour is linked to ambient lighting. // If there is no ambient lighting, then this has no influence. // It the ambient lighting is at 1, then this colour is fully added. // This is often use to change the general feeling of a whole scene. Ogre::ColourValue lAmbientColour(0.0f, 0.1f, 0.4f, 1.0f); lFirstPass->setAmbient(lAmbientColour); // specular colour, is the colour of the 'little light reflection' // that you can see on some object. For example, my bald head skin // reflect the sun. This make a 'round of specular lighting'. // Set this to black if you don't want to see it. Ogre::ColourValue lSpecularColour(0.0f, 0.3f, 1.0f, 1.0f); lFirstPass->setSpecular(lSpecularColour); // Shininess is the 'inverse of specular color splattering' coefficient. // If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface). // If this is 0, you get a simple color layer (the dot has become very wide). Ogre::Real lShininess = 34.0f; lFirstPass->setShininess(lShininess); } { Ogre::MaterialPtr lMaterial = lMaterialManager.create("barren",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); // Lighting is allowed on this pass. lFirstPass->setLightingEnabled(true); // Emissive / self illumination is the color 'produced' by the object. // Color values vary between 0.0(minimum) to 1.0 (maximum). Ogre::ColourValue lSelfIllumnationColour(0.1f, 0.1f, 0.1f, 0.1f); lFirstPass->setSelfIllumination(lSelfIllumnationColour); // diffuse color is the traditionnal color of the lit object. Ogre::ColourValue lDiffuseColour(0.3f, 0.3f, 0.3f, 0.3f); lFirstPass->setDiffuse(lDiffuseColour); // ambient colour is linked to ambient lighting. // If there is no ambient lighting, then this has no influence. // It the ambient lighting is at 1, then this colour is fully added. // This is often use to change the general feeling of a whole scene. Ogre::ColourValue lAmbientColour(0.3f, 0.3f, 0.3f, 0.3f); lFirstPass->setAmbient(lAmbientColour); // specular colour, is the colour of the 'little light reflection' // that you can see on some object. For example, my bald head skin // reflect the sun. This make a 'round of specular lighting'. // Set this to black if you don't want to see it. Ogre::ColourValue lSpecularColour(0.7f, 0.7f, 0.7f, 0.7f); lFirstPass->setSpecular(lSpecularColour); // Shininess is the 'inverse of specular color splattering' coefficient. // If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface). // If this is 0, you get a simple color layer (the dot has become very wide). Ogre::Real lShininess = 34.0f; lFirstPass->setShininess(lShininess); } { Ogre::MaterialPtr lMaterial = lMaterialManager.create("gasgiant",lNameOfResourceGroup); Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0); Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0); // Lighting is allowed on this pass. lFirstPass->setLightingEnabled(true); // Emissive / self illumination is the color 'produced' by the object. // Color values vary between 0.0(minimum) to 1.0 (maximum). Ogre::ColourValue lSelfIllumnationColour(0.0f, 0.3f, 0.0f, 0.1f); lFirstPass->setSelfIllumination(lSelfIllumnationColour); // diffuse color is the traditionnal color of the lit object. Ogre::ColourValue lDiffuseColour(0.1f, 0.7f, 0.1f, 0.3f); lFirstPass->setDiffuse(lDiffuseColour); // ambient colour is linked to ambient lighting. // If there is no ambient lighting, then this has no influence. // It the ambient lighting is at 1, then this colour is fully added. // This is often use to change the general feeling of a whole scene. Ogre::ColourValue lAmbientColour(0.1f, 0.7f, 0.3f, 0.3f); lFirstPass->setAmbient(lAmbientColour); // specular colour, is the colour of the 'little light reflection' // that you can see on some object. For example, my bald head skin // reflect the sun. This make a 'round of specular lighting'. // Set this to black if you don't want to see it. Ogre::ColourValue lSpecularColour(0.2f, 1.0f, 0.6f, 0.6f); lFirstPass->setSpecular(lSpecularColour); // Shininess is the 'inverse of specular color splattering' coefficient. // If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface). // If this is 0, you get a simple color layer (the dot has become very wide). Ogre::Real lShininess = 34.0f; lFirstPass->setShininess(lShininess); } //end material tests //System Creator std::string systemDefinition[10] = {"15000,0,0,false,false,false,700000,0", "300,0,0,false,false,barren,2500,1", "300,x,y,false,co2,barren,6000,2", "300,x,y,h2o,n2/o2,gaia,6300,3", "300,x,y,false,co2,mars,3400,4", "300,x,y,false,h2/he,gasgiant,71000,5", "300,x,y,false,h2/he,gasgiant,60000,6", "300,x,y,false,h2/he,gasgiant,25001,7", "300,x,y,false,h2/he,gasgiant,25000,8", "300,x,y,false,n-ice,ice,1100,9"}; StarSystem sol = StarSystem::StarSystem(sceneMgr, systemDefinition); //Star Creator /* { int x = 0; int y = 0; int kelvin = 15000; CelestialBody newstar = CelestialBody::CelestialBody(kelvin, 100, systemNode, sceneMgr, x, y); } // Spectrum testing and multi star generation. int time = 200; int x = -500; int y = 500; for ( int count = 1; count <= time; count++){ int kelvin = count * (40000/time); Star newstar = Star::Star(kelvin, 100, systemNode, sceneMgr, x, y); x += 20; if (count % 10 == 0) { y -= 20; x = -500; } } */ // I move the SceneNode back 15 so that it is visible to the camera. float PositionOffset = 0.0; float distance = -2000.0; systemNode->translate(0, PositionOffset, distance); camera->lookAt(Ogre::Vector3(0,0,distance)); while (sim->getCurrentState() != SHUTDOWN) { sol.rotateOrbits(); handler->capture(); ogre->renderOneFrame(); // run the message pump (uncomment for Eihort) Ogre::WindowEventUtilities::messagePump(); } { window->removeAllViewports(); } { sceneMgr->destroyAllCameras(); sceneMgr->destroyAllManualObjects(); sceneMgr->destroyAllEntities(); sceneMgr->destroyAllLights(); systemNode->removeAndDestroyAllChildren(); } { Ogre::ResourceGroupManager& lRgMgr = Ogre::ResourceGroupManager::getSingleton(); lRgMgr.destroyResourceGroup(lNameOfResourceGroup); } // clean up after ourselves delete pDlg; delete handler; delete sim; delete ogre; return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { #else int main (int argc, char *argv[]) { #endif Ogre::Root *ogre; Ogre::RenderWindow *window; Ogre::SceneManager *sceneMgr; Ogre::SceneManager *guiSceneMgr; Ogre::Camera *camera; Ogre::Camera *guiCamera; // fire up an Ogre rendering window. Clearing the first two (of three) params will let us // specify plugins and resources in code instead of via text file ogre = new Ogre::Root("", ""); #if defined(_DEBUG) ogre->loadPlugin("RenderSystem_GL_d"); #else ogre->loadPlugin("RenderSystem_GL"); #endif Ogre::RenderSystemList *renderSystems = NULL; Ogre::RenderSystemList::iterator r_it; renderSystems = ogre->getAvailableRenderers(); r_it = renderSystems->begin(); ogre->setRenderSystem(*r_it); ogre->initialise(false); // load common plugins #if defined(_DEBUG) //ogre->loadPlugin("Plugin_CgProgramManager_d"); ogre->loadPlugin("Plugin_OctreeSceneManager_d"); #else //ogre->loadPlugin("Plugin_CgProgramManager"); ogre->loadPlugin("Plugin_OctreeSceneManager"); #endif // load the basic resource location(s) Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resource", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resource/gui.zip", "Zip", "GUI"); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("meshes", "FileSystem", "Meshes"); #if defined(WIN32) Ogre::ResourceGroupManager::getSingleton().addResourceLocation("c:\\windows\\fonts", "FileSystem", "GUI"); #endif Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("GUI"); Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Meshes"); // setup main window; hardcode some defaults for the sake of presentation Ogre::NameValuePairList opts; opts["resolution"] = "1024x768"; opts["fullscreen"] = "false"; opts["vsync"] = "false"; // create a rendering window with the title "CDK" window = ogre->createRenderWindow("Bouwgame Client v0.1", 1024, 768, false, &opts); // since this is basically a CEGUI app, we can use the ST_GENERIC scene manager for now; in a later article // we'll see how to change this sceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC); guiSceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC); guiCamera = guiSceneMgr->createCamera("GUICamera"); guiCamera->setNearClipDistance(5); camera = sceneMgr->createCamera("camera"); camera->setNearClipDistance(5); Ogre::Viewport* vp = window->addViewport(guiCamera); vp->setBackgroundColour(Ogre::ColourValue(0.2f,0.2f,0.8f)); /* ambient light */ sceneMgr->setAmbientLight(Ogre::ColourValue(0.8, 0.8, 0.8)); sceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); /* meshes */ Ogre::Entity* ent = sceneMgr->createEntity( "BouwPlaatsEntity", "world.mesh" ); Ogre::SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode("BouwNode", Ogre::Vector3(0, 0, 0)); node->attachObject(ent); //node->setScale(Ogre::Vector3(0.7,0.7,0.7)); ent = sceneMgr->createEntity("plaats", "bouwplaats_step_00.mesh"); Ogre::Vector3 size = ent->getBoundingBox().getSize(); Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats size: ") + Ogre::StringConverter::toString(size)); size = ent->getBoundingBox().getMaximum(); Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats max: ") + Ogre::StringConverter::toString(size)); size = ent->getBoundingBox().getMinimum(); Ogre::LogManager::getSingletonPtr()->getDefaultLog()->logMessage(Ogre::String("Bouwplaats min: ") + Ogre::StringConverter::toString(size)); Ogre::Entity* ent1 = sceneMgr->createEntity( "KeetEntity", "keet.mesh" ); Ogre::SceneNode* scenenode = sceneMgr->getRootSceneNode()->createChildSceneNode("KeetNode", Ogre::Vector3(0, 0, 0)); scenenode->attachObject(ent1); Ogre::Entity* ent2 = sceneMgr->createEntity( "HekjeEntity", "hekje.mesh" ); Ogre::SceneNode* scenenode2 = sceneMgr->getRootSceneNode()->createChildSceneNode("HekjeNode", Ogre::Vector3(0, -100, 0)); scenenode2->attachObject(ent2); scenenode2->setScale(Ogre::Vector3(400,0,100)); // most examples get the viewport size to calculate this; for now, we'll just // set it to 4:3 the easy way camera->setAspectRatio((Ogre::Real)1.333333); camera->setPosition(Ogre::Vector3(40,100,10)); guiCamera->setPosition(0, 0, 300); guiCamera->lookAt(node->getPosition()); // this next bit is for the sake of the input handler unsigned long hWnd; window->getCustomAttribute("WINDOW", &hWnd); // set up the input handlers Simulation *sim = new Simulation(); InputHandler *handler = new InputHandler(sim, hWnd, camera); DataManager *dataManager = new DataManager(); GameAI* gameAI = new GameAI(dataManager); //Create Network Network * net = new Network(dataManager); //net->start(); sim->requestStateChange(GUI); gui = new GuiManager(); // networkshit while(!net->isConnected()) { Sleep(1000); } net->Send(GETGROUPS, "", "", NULL); net->Send(LOGIN, "gast", "gast", 1); gui->setSimulation(sim); gui->init("", ogre, guiSceneMgr, window); gui->activate("main"); handler->setWindowExtents(1024,768); SimulationState cState; Ogre::WindowEventUtilities::addWindowEventListener(window, handler); DWORD tFrameStart = 0x0; //in miliseconds signed long tFrameX = 0x0; float tDelta2 = 0.0f; //in seconds float m_fps = 60.0f; tFrameStart = GetTickCount(); float tDelta; //testAI->calculateNextPath(40,10); while ((cState = sim->getCurrentState()) != SHUTDOWN) { tFrameX = GetTickCount() - tFrameStart; tDelta2 = (float)tFrameX / 1000.0f; if (tDelta2 > 3600) // tDelta > 1 hour tDelta2 = 1.0f / m_fps; //< System tick count has highly likely overflowed, so get approximation tFrameStart = GetTickCount(); m_fps = (int)(1.0f / tDelta2); tDelta = tDelta2; handler->capture(); handler->update(tDelta); gui->update(tDelta); //if (sim->getCurrentState() == SIMULATION || sim->getCurrentState() == SIMULATION_MOUSELOOK) // testAI->update(tDelta); // run the message pump (Eihort) Ogre::WindowEventUtilities::messagePump(); ogre->renderOneFrame(); if (sim->getCurrentState() != cState) { handler->StateSwitched(cState, sim->getCurrentState()); switch (sim->getCurrentState()) { case GUI: window->getViewport(0)->setCamera(guiCamera); break; case SIMULATION: window->getViewport(0)->setCamera(camera); break; } } } // clean up after ourselves //delete testAI; delete sim; delete ogre; delete handler; delete gameAI; delete dataManager; return 0; }
// Ogre::Camera::lookAt(Ogre::Vector3 const&) // Ogre::Camera::lookAt(float, float, float) void camera_lookat(CoiHandle camera_handle, const float x, const float y, const float z) { Ogre::Camera* camera = reinterpret_cast<Ogre::Camera*>(camera_handle); camera->lookAt(Ogre::Vector3(x, y, z)); }
int main( int argc, char** argv ) { // initialize the entire render system RenderSystem* render_system = RenderSystem::get(); QApplication app( argc, argv ); // make the render window RenderWidget* window = new RenderWidget( render_system ); window->setWindowTitle( "I hope this is not all black." ); QVBoxLayout* layout = new QVBoxLayout; layout->addWidget( window ); QPushButton* hide_button = new QPushButton( "hide" ); layout->addWidget( hide_button ); QPushButton* show_button = new QPushButton( "show" ); layout->addWidget( show_button ); QWidget container; container.setLayout( layout ); container.resize( 900, 600 ); container.show(); // Make a scene and show it in the window. Ogre::SceneManager* scene_manager = render_system->root()->createSceneManager( Ogre::ST_GENERIC ); Ogre::Entity* thing = scene_manager->createEntity( "thing", "rviz_cone.mesh" ); Ogre::SceneNode* node = scene_manager->getRootSceneNode()->createChildSceneNode(); node->attachObject( thing ); scene_manager->setAmbientLight( Ogre::ColourValue( .5, .5, .5 )); Ogre::Light* light = scene_manager->createLight( "light" ); light->setPosition( 20, 80, 50 ); Ogre::Camera* camera = scene_manager->createCamera( "SampleCam" ); camera->setPosition( Ogre::Vector3( 0, 0, 10 )); camera->lookAt( Ogre::Vector3( 0, 0, -300 )); camera->setNearClipDistance( 5 ); Ogre::Viewport* viewport = window->getRenderWindow()->addViewport( camera ); viewport->setBackgroundColour( Ogre::ColourValue( 0, 0, 1.0 )); camera->setAspectRatio( Ogre::Real( viewport->getActualWidth() ) / Ogre::Real( viewport->getActualHeight() )); // redraw every 33ms. QTimer timer; QObject::connect( &timer, SIGNAL(timeout()), window, SLOT(update()) ); timer.start( 33 ); RenderWidget window2( render_system ); window2.resize( 400, 400 ); window2.setWindowTitle( "I hope this is also not all black." ); window2.show(); hide_button->connect( hide_button, SIGNAL( clicked() ), &window2, SLOT( hide() )); show_button->connect( show_button, SIGNAL( clicked() ), &window2, SLOT( show() )); Ogre::Camera* camera2 = scene_manager->createCamera( "SampleCam2" ); camera2->setPosition( Ogre::Vector3( 0, 10, 0 )); camera2->setFixedYawAxis( false ); camera2->lookAt( Ogre::Vector3( 0, 0, 0 )); camera2->setNearClipDistance( 5 ); Ogre::Viewport* viewport2 = window2.getRenderWindow()->addViewport( camera2 ); viewport2->setBackgroundColour( Ogre::ColourValue( 0, 1.0, 0 )); camera2->setAspectRatio( Ogre::Real( viewport2->getActualWidth() ) / Ogre::Real( viewport2->getActualHeight() )); // redraw every 33ms. QTimer timer2; QObject::connect( &timer2, SIGNAL(timeout()), &window2, SLOT(update()) ); timer2.start( 33 ); // main loop return app.exec(); }
// Ogre::Camera::lookAt(Ogre::Vector3 const&) // Ogre::Camera::lookAt(float, float, float) void camera_lookat(CameraHandle camera_handle, const float x, const float y, const float z) { Ogre::Camera* camera = static_cast<Ogre::Camera*>(camera_handle); camera->lookAt(Ogre::Vector3(x, y, z)); }
void SetUpCustomContent() { Ogre::String CustomCameraName = "TestRenderTargetCamera"; Ogre::String CustomTextureName = "TestRenderTargetTexture"; Ogre::String CustomMaterialName = "CustomRenderTargetMaterial"; Ogre::String CustomWorkSpaceName = "TestCustomRenderTargetWorkSpaceName"; m_CustomRTTCamera = mSceneManager->createCamera(CustomCameraName); m_CustomRTTCamera->setPosition(0, 30, 0); m_CustomRTTCamera->lookAt(0, 0, 0); m_CustomRTTCamera->setFarClipDistance(1000); m_CustomRTTCamera->setNearClipDistance(0.1); m_CustomRenderTexture = Ogre::TextureManager::getSingleton().createManual(CustomTextureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 1, Ogre::PF_A8B8G8R8, Ogre::TU_RENDERTARGET); m_CustomRenderTexture->load(); Ogre::RenderTexture* rtt = m_CustomRenderTexture->getBuffer(0)->getRenderTarget(); Ogre::CompositorManager2 *compositorManager = mRoot->getCompositorManager2(); const Ogre::IdString workspaceName(CustomWorkSpaceName); if( !compositorManager->hasWorkspaceDefinition( workspaceName ) ) { compositorManager->createBasicWorkspaceDef( workspaceName, mBackgroundColour, Ogre::IdString() ); } m_CustomRenderTarget = compositorManager->addWorkspace( mSceneManager, (Ogre::RenderTarget*)rtt, m_CustomRTTCamera, workspaceName, false ); //m_CustomRenderTarget->setEnabled(false); // not auto update #if 0 // create manual object Ogre::MaterialPtr CustomMaterial = Ogre::MaterialManager::getSingleton().create(CustomMaterialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); CustomMaterial->getTechnique(0)->removeAllPasses(); Ogre::Pass* pass = CustomMaterial->getTechnique(0)->createPass(); Ogre::TextureUnitState* tu = pass->createTextureUnitState(); tu->setTextureName(CustomTextureName); #endif Ogre::HlmsManager *hlmsManager = Ogre::Root::getSingleton().getHlmsManager(); Ogre::Hlms *hlms = hlmsManager->getHlms( Ogre::HLMS_UNLIT ); Ogre::HlmsDatablock *datablock = hlms->createDatablock( CustomMaterialName, CustomMaterialName, Ogre::HlmsMacroblock(), Ogre::HlmsBlendblock(), Ogre::HlmsParamVec() ); Ogre::HlmsUnlitDatablock *unlitDb = static_cast<Ogre::HlmsUnlitDatablock*>( datablock ); unlitDb->setTexture( 0, 0, m_CustomRenderTexture ); #if 1 Ogre::ManualObject* CustomManualObject = mSceneManager->createManualObject(); CustomManualObject->begin(CustomMaterialName); CustomManualObject->position(-100, -100, -100); CustomManualObject->textureCoord(0, 0); CustomManualObject->position(100, -100, -100); CustomManualObject->textureCoord(1, 0); CustomManualObject->position(100, 100, -100); CustomManualObject->textureCoord(1, 1); CustomManualObject->position(-100, 100, -100); CustomManualObject->textureCoord(0, 1); CustomManualObject->quad(0, 1, 2, 3); CustomManualObject->end(); // CustomManualObject->setDatablock(0, CustomMaterialName); Ogre::SceneNode *sceneNodeLines = mSceneManager->getRootSceneNode( Ogre::SCENE_DYNAMIC )-> createChildSceneNode( Ogre::SCENE_DYNAMIC ); sceneNodeLines->attachObject(CustomManualObject); sceneNodeLines->scale(0.4f, 0.4f, 0.4f); sceneNodeLines->translate(0.0f, 0.0f, 0.0f, Ogre::SceneNode::TS_WORLD); #endif }