Advertisement
pezzzz

Untitled

Jun 12th, 2012
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. static Ogre::Matrix3 convertToMatrix3(CvMat* m) {
  2.     Ogre::Matrix3 ret(
  3.     cvGetReal2D(m, 0, 0)
  4.     , cvGetReal2D(m, 0, 1)
  5.     , cvGetReal2D(m, 0, 2)
  6.     , cvGetReal2D(m, 1, 0)
  7.     , cvGetReal2D(m, 1, 1)
  8.     , cvGetReal2D(m, 1, 2)
  9.     , cvGetReal2D(m, 2, 0)
  10.     , cvGetReal2D(m, 2, 1)
  11.     , cvGetReal2D(m, 2, 2));
  12.     return ret;
  13. }
  14.  
  15. void Scene::setupARCamera() {
  16.     CvMat* intrinsicsCv = (CvMat*) cvLoad(INTRINSIC_XML);
  17.     const Ogre::Matrix3& intrinsics = convertToMatrix3(intrinsicsCv);
  18.     log("3x3: " + Ogre::StringConverter::toString(intrinsics));
  19.     /* TODO: load from xml */
  20.     const float w = 960.0;
  21.     const float h = 540.0;
  22.     Camera* camera = FrameWork::instance()->camera();
  23.     Matrix4 projection = camera->getProjectionMatrix();
  24.     projection[0][0] = intrinsics[0][0] / w;
  25.     projection[1][1] = intrinsics[1][1] / h;
  26.     projection[2][2] = -0.100;
  27.     projection[3][2] = -1.000;
  28.     projection[3][3] = 0.000;
  29.     log("ogre prj matrix: " + Ogre::StringConverter::toString(projection));
  30.     camera->setCustomProjectionMatrix(true, projection);
  31.     log("4x4: " + Ogre::StringConverter::toString(projection));
  32.     log("Camera position: " + Ogre::StringConverter::toString(camera->getPosition()));
  33.     log("Camera direction: " + Ogre::StringConverter::toString(camera->getOrientation()));
  34.     log("Camera far clip distance: " + Ogre::StringConverter::toString(camera->getFarClipDistance()));
  35.     log("Camera near clip distance: " + Ogre::StringConverter::toString(camera->getNearClipDistance()));
  36.     log("Camera focal length: " + Ogre::StringConverter::toString(camera->getFocalLength()));
  37.     log("Camera FOVy: " + Ogre::StringConverter::toString(camera->getFOVy()));
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement