Skip to content

Commit 768dead

Browse files
committed
Merge pull request #1593 from paroj:ovisup
2 parents fbaa1a1 + 7a35ae9 commit 768dead

File tree

3 files changed

+29
-37
lines changed

3 files changed

+29
-37
lines changed

modules/ovis/samples/aruco_ar_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
win = cv.ovis.createWindow("arucoAR", imsize, flags=0)
1616
win.setCameraIntrinsics(K, imsize)
17-
win.createEntity("figure", "Sinbad.mesh", (0, 0, -5), (-1.57, 0, 0))
18-
win.createLightEntity("sun", (0, 0, -100))
17+
win.createEntity("figure", "Sinbad.mesh", (0, 0, 5), (1.57, 0, 0))
18+
win.createLightEntity("sun", (0, 0, 100))
1919

2020
# video capture
2121
cap = cv.VideoCapture(0)

modules/ovis/src/meshes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ void createPlaneMesh(const String& name, const Size2f& size, InputArray image)
2828
}
2929

3030
// plane
31-
MovablePlane plane(Vector3::UNIT_Z, 0);
31+
MovablePlane plane(-Vector3::UNIT_Z, 0);
3232
MeshPtr mesh = MeshManager::getSingleton().createPlane(
33-
name, RESOURCEGROUP_NAME, plane, size.width, size.height, 1, 1, true, 1, 1, 1, Vector3::UNIT_Y);
33+
name, RESOURCEGROUP_NAME, plane, size.width, size.height, 1, 1, true, 1, 1, 1, -Vector3::UNIT_Y);
3434
mesh->getSubMesh(0)->setMaterialName(name);
3535
}
3636

modules/ovis/src/ovis.cpp

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ static const char* RENDERSYSTEM_NAME = "OpenGL 3+ Rendering Subsystem";
2323
static std::vector<String> _extraResourceLocations;
2424

2525
// convert from OpenCV to Ogre coordinates:
26-
// rotation by 180° around x axis
27-
static Matrix3 toOGRE = Matrix3(1, 0, 0, 0, -1, 0, 0, 0, -1);
26+
static Quaternion toOGRE(Degree(180), Vector3::UNIT_X);
2827
static Vector2 toOGRE_SS = Vector2(1, -1);
2928

3029
WindowScene::~WindowScene() {}
@@ -48,15 +47,12 @@ void _createTexture(const String& name, Mat image)
4847
texMgr.loadImage(name, RESOURCEGROUP_NAME, im);
4948
}
5049

51-
static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3& t,
52-
bool invert = false, bool init = false)
50+
static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3& t, bool invert = false)
5351
{
5452
CV_Assert(rot.empty() || rot.rows() == 3 || rot.size() == Size(3, 3),
5553
tvec.empty() || tvec.rows() == 3);
5654

57-
// make sure the entity is oriented by the OpenCV coordinate conventions
58-
// when initialised
59-
q = init ? Quaternion(toOGRE) : Quaternion::IDENTITY;
55+
q = Quaternion::IDENTITY;
6056
t = Vector3::ZERO;
6157

6258
if (!rot.empty())
@@ -74,7 +70,7 @@ static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3&
7470

7571
Matrix3 R;
7672
_R.copyTo(Mat_<Real>(3, 3, R[0]));
77-
q = Quaternion(toOGRE * R);
73+
q = Quaternion(R);
7874

7975
if (invert)
8076
{
@@ -85,7 +81,6 @@ static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3&
8581
if (!tvec.empty())
8682
{
8783
tvec.copyTo(Mat_<Real>(3, 1, t.ptr()));
88-
t = toOGRE * t;
8984

9085
if(invert)
9186
{
@@ -124,6 +119,10 @@ static SceneNode& _getSceneNode(SceneManager* sceneMgr, const String& name)
124119
try
125120
{
126121
mo = sceneMgr->getMovableObject(name, "Camera");
122+
123+
// with cameras we have an extra CS flip node
124+
if(mo)
125+
return *mo->getParentSceneNode()->getParentSceneNode();
127126
}
128127
catch (ItemIdentityException&)
129128
{
@@ -281,12 +280,14 @@ class WindowSceneImpl : public WindowScene
281280
cam->setNearClipDistance(0.5);
282281
cam->setAutoAspectRatio(true);
283282
camNode = sceneMgr->getRootSceneNode()->createChildSceneNode();
283+
camNode->setOrientation(toOGRE);
284284
camNode->attachObject(cam);
285285

286286
if (flags & SCENE_INTERACTIVE)
287287
{
288288
camman.reset(new OgreBites::CameraMan(camNode));
289289
camman->setStyle(OgreBites::CS_ORBIT);
290+
camNode->setFixedYawAxis(true, Vector3::NEGATIVE_UNIT_Y);
290291
}
291292

292293
if (!app->sceneMgr)
@@ -356,7 +357,7 @@ class WindowSceneImpl : public WindowScene
356357

357358
Quaternion q;
358359
Vector3 t;
359-
_convertRT(rot, tvec, q, t, false, true);
360+
_convertRT(rot, tvec, q, t);
360361
SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q);
361362
node->attachObject(ent);
362363
}
@@ -387,8 +388,10 @@ class WindowSceneImpl : public WindowScene
387388

388389
Quaternion q;
389390
Vector3 t;
390-
_convertRT(rot, tvec, q, t, false, true);
391+
_convertRT(rot, tvec, q, t);
391392
SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q);
393+
node = node->createChildSceneNode();
394+
node->setOrientation(toOGRE); // camera mesh is oriented by OGRE conventions by default
392395
node->attachObject(cam);
393396

394397
RealRect ext = cam->getFrustumExtents();
@@ -410,7 +413,7 @@ class WindowSceneImpl : public WindowScene
410413

411414
Quaternion q;
412415
Vector3 t;
413-
_convertRT(rot, tvec, q, t, false, true);
416+
_convertRT(rot, tvec, q, t);
414417
SceneNode* node = sceneMgr->getRootSceneNode()->createChildSceneNode(t, q);
415418
node->attachObject(light);
416419
}
@@ -430,7 +433,7 @@ class WindowSceneImpl : public WindowScene
430433
SceneNode& node = _getSceneNode(sceneMgr, name);
431434
Quaternion q;
432435
Vector3 t;
433-
_convertRT(rot, tvec, q, t, invert, true);
436+
_convertRT(rot, tvec, q, t, invert);
434437
node.setOrientation(q);
435438
node.setPosition(t);
436439
}
@@ -539,40 +542,33 @@ class WindowSceneImpl : public WindowScene
539542

540543
void fixCameraYawAxis(bool useFixed, InputArray _up)
541544
{
542-
Vector3 up = Vector3::UNIT_Y;
545+
Vector3 up = Vector3::NEGATIVE_UNIT_Y;
543546
if (!_up.empty())
544547
{
545548
_up.copyTo(Mat_<Real>(3, 1, up.ptr()));
546-
up = toOGRE * up;
547549
}
548550

549-
Camera* cam = sceneMgr->getCamera(title);
550-
cam->getParentSceneNode()->setFixedYawAxis(useFixed, up);
551+
camNode->setFixedYawAxis(useFixed, up);
551552
}
552553

553554
void setCameraPose(InputArray tvec, InputArray rot, bool invert)
554555
{
555-
Camera* cam = sceneMgr->getCamera(title);
556-
557-
SceneNode* node = cam->getParentSceneNode();
558556
Quaternion q;
559557
Vector3 t;
560-
_convertRT(rot, tvec, q, t, invert, true);
558+
_convertRT(rot, tvec, q, t, invert);
561559

562560
if (!rot.empty())
563-
node->setOrientation(q);
561+
camNode->setOrientation(q*toOGRE);
564562

565563
if (!tvec.empty())
566-
node->setPosition(t);
564+
camNode->setPosition(t);
567565
}
568566

569567
void getCameraPose(OutputArray R, OutputArray tvec, bool invert)
570568
{
571-
Camera* cam = sceneMgr->getCamera(title);
572-
SceneNode* node = cam->getParentSceneNode();
573-
574569
Matrix3 _R;
575-
node->getOrientation().ToRotationMatrix(_R);
570+
// toOGRE.Inverse() == toOGRE
571+
(camNode->getOrientation()*toOGRE).ToRotationMatrix(_R);
576572

577573
if (invert)
578574
{
@@ -581,20 +577,18 @@ class WindowSceneImpl : public WindowScene
581577

582578
if (tvec.needed())
583579
{
584-
Vector3 _tvec = node->getPosition();
580+
Vector3 _tvec = camNode->getPosition();
585581

586582
if (invert)
587583
{
588584
_tvec = _R * -_tvec;
589585
}
590586

591-
_tvec = toOGRE.Transpose() * _tvec;
592587
Mat_<Real>(3, 1, _tvec.ptr()).copyTo(tvec);
593588
}
594589

595590
if (R.needed())
596591
{
597-
_R = toOGRE.Transpose() * _R;
598592
Mat_<Real>(3, 3, _R[0]).copyTo(R);
599593
}
600594
}
@@ -607,18 +601,16 @@ class WindowSceneImpl : public WindowScene
607601

608602
void setCameraLookAt(const String& target, InputArray offset)
609603
{
610-
SceneNode* cam = sceneMgr->getCamera(title)->getParentSceneNode();
611604
SceneNode* tgt = sceneMgr->getEntity(target)->getParentSceneNode();
612605

613606
Vector3 _offset = Vector3::ZERO;
614607

615608
if (!offset.empty())
616609
{
617610
offset.copyTo(Mat_<Real>(3, 1, _offset.ptr()));
618-
_offset = toOGRE * _offset;
619611
}
620612

621-
cam->lookAt(tgt->_getDerivedPosition() + _offset, Ogre::Node::TS_WORLD);
613+
camNode->lookAt(tgt->_getDerivedPosition() + _offset, Ogre::Node::TS_WORLD);
622614
}
623615
};
624616

0 commit comments

Comments
 (0)