void Ogre3DRendererPlugin::setupRTT() { if(!SBS) return; rtt_texture = Ogre::TextureManager::getSingleton().createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mWindow->getWidth(), mWindow->getHeight(), 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); renderTexture = rtt_texture->getBuffer()->getRenderTarget(); renderTexture->addViewport(mCamera2); renderTexture->getViewport(0)->setClearEveryFrame(true); renderTexture->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black); renderTexture->getViewport(0)->setOverlaysEnabled(false); rtt_texture2 = Ogre::TextureManager::getSingleton().createManual("RttTex2", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, mWindow->getWidth(), mWindow->getHeight(), 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); renderTexture2 = rtt_texture2->getBuffer()->getRenderTarget(); renderTexture2->addViewport(mCamera2); renderTexture2->getViewport(0)->setClearEveryFrame(true); renderTexture2->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black); renderTexture2->getViewport(0)->setOverlaysEnabled(false); Ogre::Rectangle2D *mMiniScreen = new Ogre::Rectangle2D(true); mMiniScreen->setCorners(0.0f, 1.0f, 1.0f, -1.0f);//mMiniScreen->setCorners(0.5f, -0.5f, 1.0f, -1.0f); mMiniScreen->setBoundingBox(Ogre::AxisAlignedBox(-100000.0f * Ogre::Vector3::UNIT_SCALE, 100000.0f * Ogre::Vector3::UNIT_SCALE)); Ogre::SceneNode* miniScreenNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("MiniScreenNode"); miniScreenNode->attachObject(mMiniScreen); Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName("BarrelDistort"); material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName("RttTex"); mMiniScreen->setMaterial("BarrelDistort"); Ogre::Rectangle2D *mMiniScreen2 = new Ogre::Rectangle2D(true); mMiniScreen2->setCorners(-1.0f, 1.0f, 0.0f, -1.0f); mMiniScreen2->setBoundingBox(Ogre::AxisAlignedBox(-100000.0f * Ogre::Vector3::UNIT_SCALE, 100000.0f * Ogre::Vector3::UNIT_SCALE)); Ogre::SceneNode* miniScreenNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("MiniScreenNode2"); miniScreenNode2->attachObject(mMiniScreen2); Ogre::MaterialPtr material2 = Ogre::MaterialManager::getSingleton().getByName("BarrelDistort"); material2->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName("RttTex2"); mMiniScreen2->setMaterial("BarrelDistort"); }
void SplashScreenState::createScene() { // creation image splash screen Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("SplashScreen", "General"); material->getTechnique(0)->getPass(0)->createTextureUnitState("splash_screen.jpg"); material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); material->getTechnique(0)->getPass(0)->setLightingEnabled(false); // creation rect Ogre::Rectangle2D *rect = new Ogre::Rectangle2D(true); rect->setCorners(-1.0, 1.0, 1.0, -1.0); rect->setMaterial("SplashScreen"); // priorité chargement rect->setRenderQueueGroup(Ogre::RenderQueueGroupID::RENDER_QUEUE_BACKGROUND); // stay visible Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); rect->setBoundingBox(aabInf); // Ogre::SceneNode* node = m_pSceneMgr->getRootSceneNode()->createChildSceneNode("SplashScreen"); node->attachObject(rect); m_pSceneMgr->setAmbientLight(Ogre::ColourValue(1, 1, 1)); }
inline void GUIRadarLayout::DrawCompas(Ogre::Quaternion players_orientation) { //static clock_t last_update_time=0; //if (clock()-last_update_time<100) // return; assert(CompasRect && CompasObj); //if (NULL==CompasRect || NULL==CompasObj) // return; //last_update_time = clock(); //CompasTarget; if (TargetID>0) { if (--WaitCompasTargetTimeout>=0) { CompasRect->setVisible(false); CompasObj->setVisible(false); return; } IAAObject *obj = CommonDeclarations::GetIDObject(TargetID); //assert(obj); if (NULL==obj) { RemoveCompasTarget(); return; } CompasTarget = obj->GetPosition(); } Ogre::Rectangle2D *row = CompasRect; Ogre::Rectangle2D *obj = CompasObj; //dst_pos -= CommonDeclarations::MaxDistForRadar/2; Ogre::Quaternion orientation(Ogre::Degree(30), Ogre::Vector3::UNIT_X); Ogre::Quaternion player_rotation(players_orientation.getYaw(), Ogre::Vector3::UNIT_Y); player_rotation = Ogre::Quaternion(players_orientation.getRoll(), Ogre::Vector3::UNIT_Z) * player_rotation; Ogre::Vector3 pl_pos = CommonDeclarations::GetPlayer()->GetPosition(); Ogre::Vector3 rel_pos = CompasTarget-pl_pos, base_pos = rel_pos; base_pos.y=0; bool checkpoint_mode=false; float scr_height = 0; if (rel_pos.squaredLength()>CommonDeclarations::SqMaxDistForRadar) { Ogre::Vector3 dist=base_pos; AAUtilities::Norm1(dist); base_pos = dist*CommonDeclarations::MaxDistForRadar; scr_height=0.01; checkpoint_mode=true; } else { scr_height =rel_pos.y*ScreenSize / CommonDeclarations::MaxDistForRadar; } base_pos = orientation * players_orientation * base_pos; base_pos = (base_pos / CommonDeclarations::MaxDistForRadar)*ScreenSize; base_pos.x += 0.75; base_pos.y -= 0.75; // if (!checkpoint_mode) { if (scr_height==0) scr_height=0.01; float left=base_pos.x-0.005, top=base_pos.y, right=base_pos.x+0.005, bottom=base_pos.y+scr_height; obj->setCorners(base_pos.x-0.01, base_pos.y+0.008, base_pos.x+0.01, base_pos.y-0.008); if (scr_height>0) { left=base_pos.x-0.0025; top=base_pos.y+scr_height; right=base_pos.x+0.0025; bottom=base_pos.y; obj->setMaterial("Radar/CompasObjMaterialUp"); } else if (scr_height<0) { left=base_pos.x-0.0025; top=base_pos.y; right=base_pos.x+0.0025; bottom=base_pos.y+scr_height; obj->setMaterial("Radar/CompasObjMaterialDn"); } row->setCorners(left, top, right, bottom); // row->setVisible(true); obj->setVisible(true); } else { obj->setMaterial("Radar/CompasFarMaterial"); obj->setCorners(base_pos.x-0.015, base_pos.y+0.015, base_pos.x+0.015, base_pos.y-0.015); obj->setVisible(true); } }
bool GUIRadarLayout::Load() { // rect = new Ogre::Rectangle2D(TRUE); rect->setMaterial("Radar/Background"); rect->getMaterial()->setDepthCheckEnabled(false); rect->getMaterial()->setDepthWriteEnabled(false); rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_6-3); //rect->setBoundingBox(Ogre::AxisAlignedBox(-1000000 * Ogre::Vector3::UNIT_SCALE, 1000000 * Ogre::Vector3::UNIT_SCALE)); //CommonDeclarations::GetSceneManager()->getRootSceneNode()->attachObject(rect); //rect->setCorners(0.5, -0.5, 1, -1); // // Create a manual object for 2D //char name[10]; Ogre::Rectangle2D *row = NULL; Ogre::Rectangle2D *obj = NULL; //Ogre::AxisAlignedBox aabInf; //aabInf.setInfinite(); if (!Ogre::MaterialManager::getSingleton().resourceExists("CompasMaterial")) { Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName("BaseWhiteNoLighting"); CompasMaterial = mat->clone("CompasMaterial"); CompasMaterial->setDepthCheckEnabled(false); CompasMaterial->setDepthWriteEnabled(false); CompasMaterial->setLightingEnabled(true); CompasMaterial->setAmbient(Ogre::ColourValue::Green); } if (!Ogre::MaterialManager::getSingleton().resourceExists("RadarRowMaterial")) { Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName("BaseWhiteNoLighting"); RadarRowMaterial = mat->clone("RadarRowMaterial"); RadarRowMaterial->setDepthCheckEnabled(false); RadarRowMaterial->setDepthWriteEnabled(false); RadarRowMaterial->setLightingEnabled(true); RadarRowMaterial->setAmbient(Ogre::ColourValue::Red); } /*if (!Ogre::MaterialManager::getSingleton().resourceExists("RadarObjMaterial")) { Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName("BaseWhiteNoLighting"); RadarObjMaterial = mat->clone("RadarObjMaterial"); RadarObjMaterial->setDepthCheckEnabled(false); RadarObjMaterial->setDepthWriteEnabled(false); RadarObjMaterial->setLightingEnabled(true); RadarObjMaterial->setAmbient(Ogre::ColourValue::Red); }*/ for (unsigned i=0;i<CommonDeclarations::RadarObjectsCount;++i) { // row = new Ogre::Rectangle2D(TRUE); row->setMaterial("RadarRowMaterial"); row->setRenderQueueGroup(Ogre::RENDER_QUEUE_6-2); //CommonDeclarations::GetSceneManager()->getRootSceneNode()->attachObject(row); //rect->setCorners(0.5, -0.5, 1, -1); Rows.Data[i] = row; // // obj = new Ogre::Rectangle2D(TRUE); obj->setMaterial("Radar/ObjMaterialUp"); obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_6-2); //CommonDeclarations::GetSceneManager()->getRootSceneNode()->attachObject(obj); //rect->setCorners(0.5, -0.5, 1, -1); Objects.Data[i] = obj; // } InitCompasRect(CompasRect); InitCompasRect(CompasObj); return true; }
int initOgreAR(aruco::CameraParameters camParams, unsigned char* buffer, std::string resourcePath) { /// INIT OGRE FUNCTIONS #ifdef _WIN32 root = new Ogre::Root(resourcePath + "plugins_win.cfg", resourcePath + "ogre_win.cfg"); #elif __x86_64__ || __ppc64__ root = new Ogre::Root(resourcePath + "plugins_x64.cfg", resourcePath + "ogre.cfg"); #else root = new Ogre::Root(resourcePath + "plugins.cfg", resourcePath + "ogre.cfg"); #endif if (!root->showConfigDialog()) return -1; Ogre::SceneManager* smgr = root->createSceneManager(Ogre::ST_GENERIC); /// CREATE WINDOW, CAMERA AND VIEWPORT Ogre::RenderWindow* window = root->initialise(true); Ogre::Camera *camera; Ogre::SceneNode* cameraNode; camera = smgr->createCamera("camera"); camera->setNearClipDistance(0.01f); camera->setFarClipDistance(10.0f); camera->setProjectionType(Ogre::PT_ORTHOGRAPHIC); camera->setPosition(0, 0, 0); camera->lookAt(0, 0, 1); double pMatrix[16]; camParams.OgreGetProjectionMatrix(camParams.CamSize,camParams.CamSize, pMatrix, 0.05,10, false); Ogre::Matrix4 PM(pMatrix[0], pMatrix[1], pMatrix[2] , pMatrix[3], pMatrix[4], pMatrix[5], pMatrix[6] , pMatrix[7], pMatrix[8], pMatrix[9], pMatrix[10], pMatrix[11], pMatrix[12], pMatrix[13], pMatrix[14], pMatrix[15]); camera->setCustomProjectionMatrix(true, PM); camera->setCustomViewMatrix(true, Ogre::Matrix4::IDENTITY); window->addViewport(camera); cameraNode = smgr->getRootSceneNode()->createChildSceneNode("cameraNode"); cameraNode->attachObject(camera); /// CREATE BACKGROUND FROM CAMERA IMAGE int width = camParams.CamSize.width; int height = camParams.CamSize.height; // create background camera image mPixelBox = Ogre::PixelBox(width, height, 1, Ogre::PF_R8G8B8, buffer); // Create Texture mTexture = Ogre::TextureManager::getSingleton().createManual("CameraTexture",Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D,width,height,0,Ogre::PF_R8G8B8,Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE); //Create Camera Material Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("CameraMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::Technique *technique = material->createTechnique(); technique->createPass(); material->getTechnique(0)->getPass(0)->setLightingEnabled(false); material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); material->getTechnique(0)->getPass(0)->createTextureUnitState("CameraTexture"); Ogre::Rectangle2D* rect = new Ogre::Rectangle2D(true); rect->setCorners(-1.0, 1.0, 1.0, -1.0); rect->setMaterial("CameraMaterial"); // Render the background before everything else rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND); // Hacky, but we need to set the bounding box to something big, use infinite AAB to always stay visible Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); rect->setBoundingBox(aabInf); // Attach background to the scene Ogre::SceneNode* node = smgr->getRootSceneNode()->createChildSceneNode("Background"); node->attachObject(rect); /// CREATE SIMPLE OGRE SCENE // add sinbad.mesh Ogre::ResourceGroupManager::getSingleton().addResourceLocation(resourcePath + "Sinbad.zip", "Zip", "Popular"); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); for(int i=0; i<MAX_MARKERS; i++) { Ogre::String entityName = "Marker_" + Ogre::StringConverter::toString(i); Ogre::Entity* ogreEntity = smgr->createEntity(entityName, "Sinbad.mesh"); Ogre::Real offset = ogreEntity->getBoundingBox().getHalfSize().y; ogreNode[i] = smgr->getRootSceneNode()->createChildSceneNode(); // add entity to a child node to correct position (this way, entity axis is on feet of sinbad) Ogre::SceneNode *ogreNodeChild = ogreNode[i]->createChildSceneNode(); ogreNodeChild->attachObject(ogreEntity); // Sinbad is placed along Y axis, we need to rotate to put it along Z axis so it stands up over the marker // first rotate along X axis, then add offset in Z dir so it is over the marker and not in the middle of it ogreNodeChild->rotate(Ogre::Vector3(1,0,0), Ogre::Radian(Ogre::Degree(90))); ogreNodeChild->translate(0,0,offset,Ogre::Node::TS_PARENT); // mesh is too big, rescale! const float scale = 0.006675f; ogreNode[i]->setScale(scale, scale, scale); // Init animation ogreEntity->getSkeleton()->setBlendMode(Ogre::ANIMBLEND_CUMULATIVE); if(i==0) { baseAnim[i] = ogreEntity->getAnimationState("HandsClosed"); topAnim[i] = ogreEntity->getAnimationState("HandsRelaxed"); } else if(i==1) { baseAnim[i] = ogreEntity->getAnimationState("Dance"); topAnim[i] = ogreEntity->getAnimationState("Dance"); } else if(i==2) { baseAnim[i] = ogreEntity->getAnimationState("RunBase"); topAnim[i] = ogreEntity->getAnimationState("RunTop"); } else { baseAnim[i] = ogreEntity->getAnimationState("IdleBase"); topAnim[i] = ogreEntity->getAnimationState("IdleTop"); } baseAnim[i]->setLoop(true); topAnim[i]->setLoop(true); baseAnim[i]->setEnabled(true); topAnim[i]->setEnabled(true); } /// KEYBOARD INPUT READING size_t windowHnd = 0; window->getCustomAttribute("WINDOW", &windowHnd); im = OIS::InputManager::createInputSystem(windowHnd); keyboard = static_cast<OIS::Keyboard*>(im->createInputObject(OIS::OISKeyboard, true)); return 1; }