void ViargoOgreKinectTrackingCalibrationMetaphor::_finalizeCalibration() { // Build extended positions (calculates average normal plane and adds translated points to list, needed for opencv affine transformation solver) //_buildExtendedPositions(_screenPositions3D); //_buildExtendedPositions(_worldPositions); cv::Point3f origin = _worldPositions[2]; cv::Point3f xAxis = _worldPositions[3]; cv::Point3f yAxis = _worldPositions[0]; _buildTransformationMatrix(origin, xAxis, yAxis); // SVD //_solveRigidBodyTransformation(_worldPositions, _screenPositions3D); // Store transformation matrix in file _storeCalibrationData(); storeTransformation("kinect_calibration.txt"); // Reset state _calibrating = false; _calibrated = true; // Hide overlays _overlay->hide(); _backgroundOverlayContainer->hide(); for (unsigned int i = 0; i < _markers.size(); i++) { Ogre::OverlayContainer* currentMarkerOverlay = _markers[i]; currentMarkerOverlay->hide(); } _worldPositions.clear(); }
void OverlayMask::preViewportUpdate(const Ogre::RenderTargetViewportEvent &event) { if(event.source == mViewport) { Ogre::OverlayManager &overlayMgr = Ogre::OverlayManager::getSingleton(); for(Ogre::OverlayManager::OverlayMapIterator iter = overlayMgr.getOverlayIterator(); iter.hasMoreElements();) { Ogre::Overlay* item = iter.getNext(); for(Ogre::Overlay::Overlay2DElementsIterator it = item->get2DElementsIterator(); it.hasMoreElements();) { Ogre::OverlayContainer* container = it.getNext(); if(container) container->hide(); } } std::map<CSMWorld::CellCoordinates, TextOverlay *>::iterator it = mTextOverlays.begin(); for(; it != mTextOverlays.end(); ++it) { it->second->show(true); } } }
void ViargoOgreKinectTrackingCalibrationMetaphor::_buildPattern() { // Horizontal and vertical offets float horizontalOffset = _offsets.x + _offsets.z; float verticalOffset = _offsets.y + _offsets.w; // Step in horizontal and vertical direction double widthStep = (1.0 - horizontalOffset) / (_patternSize - 1); double heightStep = (1.0 - verticalOffset) / (_patternSize - 1); // Clear old positions _screenPositions.clear(); _screenPositions3D.clear(); // Build new 2d screen positions for (int j = 0; j < _patternSize; j++) { for (int i = 0; i < _patternSize; i++) { double positionX = _offsets.x + i * widthStep; double positionY = _offsets.y + j * heightStep; // Add to list _screenPositions.push_back(cv::Point2d(positionX, positionY)); } } // Transform 2d screen positions into world space relative to window center for (unsigned int i = 0; i < _screenPositions.size(); i++) { cv::Point3f worldPosition = cv::Point3f(0, 0, 0); // Scale to window size and correct position for [0,0] in window center worldPosition.x = _screenPositions[i].x * _windowSize.x - _windowSize.x / 2.0f; worldPosition.y = -(_screenPositions[i].y * _windowSize.y - _windowSize.y / 2.0f); // Flipped _screenPositions3D.push_back(worldPosition); } // Build pattern as overlays Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); // Main overlay, specific overlay containers are inserted here _overlay = overlayManager.create("KinectTrackingCalibrationOverlay"); _overlay->hide(); _backgroundOverlayContainer = static_cast<Ogre::OverlayContainer*>(overlayManager.createOverlayElement("Panel", "KinectTrackingCalibrationBG")); _backgroundOverlayContainer->setPosition(0.0, 0.0); _backgroundOverlayContainer->setDimensions(1.0, 1.0); _backgroundOverlayContainer->setMaterialName("kinecttrackingCalibrationBlackMat"); _backgroundOverlayContainer->hide(); // Add background first _overlay->add2D(_backgroundOverlayContainer); char overlayName[100]; // Build overlay for each marker for (unsigned int i = 0; i < _screenPositions.size(); i++) { Ogre::Vector2 screenPostion = Ogre::Vector2(_screenPositions[i].x, _screenPositions[i].y); sprintf(overlayName, "KinectTrackingCalibration_%d", i); Ogre::OverlayContainer* container = static_cast<Ogre::OverlayContainer*>(overlayManager.createOverlayElement("Panel", std::string(overlayName))); container->setPosition(screenPostion.x - _markerSize.x / (Ogre::Real)2.0, screenPostion.y - _markerSize.y / (Ogre::Real)2.0); container->setDimensions(_markerSize.x, _markerSize.y); container->setMaterialName("kinecttrackingCalibrationRedMat"); container->hide(); // Add overlay item _overlay->add2D(container); // Add to list _markers.push_back(container); } }
ExampleFrameListener::ExampleFrameListener( RenderWindow* win, Camera* cam, bool bufferedKeys /*= false*/, bool bufferedMouse /*= false*/, bool bufferedJoy /*= false */ ) : mCamera(cam), mTranslateVector(Vector3::ZERO), mCurrentSpeed(0), mWindow(win), mStatsOn(false), mNumScreenShots(0), mMoveScale(0.0f), mRotScale(0.0f), mTimeUntilNextToggle(0), mFiltering(TFO_BILINEAR), mAniso(1), mSceneDetailIndex(0), mMoveSpeed(500), mRotateSpeed(36), mDebugOverlay(0), mInputManager(0), mMouse(0), mKeyboard(0), mJoy(0) { LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); OIS::ParamList pl; unsigned int windowAttr = 15; size_t windowHnd = 10; std::ostringstream windowHndStr; win->getCustomAttribute("WINDOW", &windowAttr); windowHnd = windowAttr; printf("custom attribute = %lu, windowHnd = %lu\n",windowAttr,windowHnd); /*while (getParentWindowHandle(windowHnd)) // loop until we get top level window { windowHnd = getParentWindowHandle(windowHnd); } */ windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); pl.insert(std::make_pair(std::string("w32_keyboard"),std::string("DISCL_NONEXCLUSIVE"))); pl.insert(std::make_pair(std::string("w32_keyboard"),std::string("DISCL_BACKGROUND"))); pl.insert(std::make_pair(std::string("w32_mouse"),std::string("DISCL_NONEXCLUSIVE"))); pl.insert(std::make_pair(std::string("w32_mouse"),std::string("DISCL_BACKGROUND"))); //LogManager::getSingletonPtr()->logMessage( "*** Initializing OIS step1 ***" ); #if 0 //LogManager::getSingletonPtr()->logMessage( "*** Initializing OIS step2 ***" ); mInputManager = OIS::InputManager::createInputSystem( windowHnd ); //LogManager::getSingletonPtr()->logMessage( "*** Initializing OIS step3 ***" ); //Create all devices (We only catch joystick exceptions here, as, most people have Key/Mouse) try { mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, bufferedMouse )); mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, bufferedKeys )); } catch (OIS::Exception& e) { //LogManager::getSingletonPtr()->logMessage("Exception when createInputObject, description = " + e); printf("exception = %s\n", e.eText); } #endif #if 0 try { mJoy = static_cast<OIS::JoyStick*>(mInputManager->createInputObject( OIS::OISJoyStick, bufferedJoy )); } catch(...) { mJoy = 0; } #endif //Set initial mouse clipping size //LogManager::getSingletonPtr()->logMessage( "*** Initializing OIS step4 ***" ); windowResized(mWindow); //LogManager::getSingletonPtr()->logMessage( "*** Initializing OIS step5 ***" ); #if SHOW_OGRE_DEBUG_OVERLAY mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); Ogre::OverlayContainer* logo = mDebugOverlay->getChild("Core/LogoPanel"); logo->hide(); mDebugOverlay->hide(); showDebugOverlay(false); #endif //LogManager::getSingletonPtr()->logMessage( "*** Initializing OIS step6 ***" ); //Register as a Window listener WindowEventUtilities::addWindowEventListener(mWindow, this); LogManager::getSingletonPtr()->logMessage( "*** Finish Initialize OIS ***" ); }