Commit 91d108f3 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #1569 from paroj:ovisup

parents 7b4cdd5d a62f9c42
...@@ -7,19 +7,19 @@ cv.ovis.addResourceLocation("packs/Sinbad.zip") ...@@ -7,19 +7,19 @@ cv.ovis.addResourceLocation("packs/Sinbad.zip")
# camera intrinsics # camera intrinsics
imsize = (800, 600) imsize = (800, 600)
K = np.diag([800, 800, 1]) K = np.diag([800, 800, 1])
K[:2, 2] = (400, 100) # offset pp K[:2, 2] = (400, 500) # offset pp
# observer scene # observer scene
owin = cv.ovis.createWindow("VR", imsize) owin = cv.ovis.createWindow("VR", imsize)
cv.ovis.createGridMesh("ground", (10, 10), (10, 10)) cv.ovis.createGridMesh("ground", (10, 10), (10, 10))
owin.createEntity("ground", "ground", rot=(1.57, 0, 0)) owin.createEntity("ground", "ground", rot=(1.57, 0, 0))
owin.createCameraEntity("cam", K, imsize, 5) owin.createCameraEntity("cam", K, imsize, 5)
owin.createEntity("figure", "Sinbad.mesh", (0, -5, 0)) # externally defined mesh owin.createEntity("figure", "Sinbad.mesh", tvec=(0, -5, 0), rot=(np.pi, 0, 0)) # externally defined mesh
owin.createLightEntity("sun", (0, 0, -100)) owin.createLightEntity("sun", (0, 0, -100))
# interaction scene # interaction scene
iwin = cv.ovis.createWindow("AR", imsize, cv.ovis.SCENE_SEPERATE | cv.ovis.SCENE_INTERACTIVE) iwin = cv.ovis.createWindow("AR", imsize, cv.ovis.SCENE_SEPERATE | cv.ovis.SCENE_INTERACTIVE)
iwin.createEntity("figure", "Sinbad.mesh", (0, -5, 0)) iwin.createEntity("figure", "Sinbad.mesh", tvec=(0, -5, 0), rot=(np.pi, 0, 0))
iwin.createLightEntity("sun", (0, 0, -100)) iwin.createLightEntity("sun", (0, 0, -100))
iwin.setCameraIntrinsics(K, imsize) iwin.setCameraIntrinsics(K, imsize)
......
...@@ -49,12 +49,14 @@ void _createTexture(const String& name, Mat image) ...@@ -49,12 +49,14 @@ void _createTexture(const String& name, Mat image)
} }
static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3& t, static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3& t,
bool invert = false) bool invert = false, bool init = false)
{ {
CV_Assert(rot.empty() || rot.rows() == 3 || rot.size() == Size(3, 3), CV_Assert(rot.empty() || rot.rows() == 3 || rot.size() == Size(3, 3),
tvec.empty() || tvec.rows() == 3); tvec.empty() || tvec.rows() == 3);
q = Quaternion::IDENTITY; // make sure the entity is oriented by the OpenCV coordinate conventions
// when initialised
q = init ? Quaternion(toOGRE) : Quaternion::IDENTITY;
t = Vector3::ZERO; t = Vector3::ZERO;
if (!rot.empty()) if (!rot.empty())
...@@ -346,7 +348,7 @@ public: ...@@ -346,7 +348,7 @@ public:
Quaternion q; Quaternion q;
Vector3 t; Vector3 t;
_convertRT(rot, tvec, q, t); _convertRT(rot, tvec, q, t, false, true);
SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q); SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q);
node->attachObject(ent); node->attachObject(ent);
} }
...@@ -377,7 +379,7 @@ public: ...@@ -377,7 +379,7 @@ public:
Quaternion q; Quaternion q;
Vector3 t; Vector3 t;
_convertRT(rot, tvec, q, t); _convertRT(rot, tvec, q, t, false, true);
SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q); SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q);
node->attachObject(cam); node->attachObject(cam);
...@@ -400,7 +402,7 @@ public: ...@@ -400,7 +402,7 @@ public:
Quaternion q; Quaternion q;
Vector3 t; Vector3 t;
_convertRT(rot, tvec, q, t); _convertRT(rot, tvec, q, t, false, true);
SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q); SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q);
node->attachObject(light); node->attachObject(light);
} }
...@@ -420,7 +422,7 @@ public: ...@@ -420,7 +422,7 @@ public:
SceneNode& node = _getSceneNode(sceneMgr, name); SceneNode& node = _getSceneNode(sceneMgr, name);
Quaternion q; Quaternion q;
Vector3 t; Vector3 t;
_convertRT(rot, tvec, q, t, invert); _convertRT(rot, tvec, q, t, invert, true);
node.setOrientation(q); node.setOrientation(q);
node.setPosition(t); node.setPosition(t);
} }
...@@ -488,7 +490,7 @@ public: ...@@ -488,7 +490,7 @@ public:
SceneNode* node = cam->getParentSceneNode(); SceneNode* node = cam->getParentSceneNode();
Quaternion q; Quaternion q;
Vector3 t; Vector3 t;
_convertRT(rot, tvec, q, t, invert); _convertRT(rot, tvec, q, t, invert, true);
if (!rot.empty()) if (!rot.empty())
node->setOrientation(q); node->setOrientation(q);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment