@@ -23,8 +23,7 @@ static const char* RENDERSYSTEM_NAME = "OpenGL 3+ Rendering Subsystem";
23
23
static std::vector<String> _extraResourceLocations;
24
24
25
25
// 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);
28
27
static Vector2 toOGRE_SS = Vector2(1 , -1 );
29
28
30
29
WindowScene::~WindowScene () {}
@@ -48,15 +47,12 @@ void _createTexture(const String& name, Mat image)
48
47
texMgr.loadImage (name, RESOURCEGROUP_NAME, im);
49
48
}
50
49
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 )
53
51
{
54
52
CV_Assert (rot.empty () || rot.rows () == 3 || rot.size () == Size (3 , 3 ),
55
53
tvec.empty () || tvec.rows () == 3 );
56
54
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;
60
56
t = Vector3::ZERO;
61
57
62
58
if (!rot.empty ())
@@ -74,7 +70,7 @@ static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3&
74
70
75
71
Matrix3 R;
76
72
_R.copyTo (Mat_<Real>(3 , 3 , R[0 ]));
77
- q = Quaternion (toOGRE * R);
73
+ q = Quaternion (R);
78
74
79
75
if (invert)
80
76
{
@@ -85,7 +81,6 @@ static void _convertRT(InputArray rot, InputArray tvec, Quaternion& q, Vector3&
85
81
if (!tvec.empty ())
86
82
{
87
83
tvec.copyTo (Mat_<Real>(3 , 1 , t.ptr ()));
88
- t = toOGRE * t;
89
84
90
85
if (invert)
91
86
{
@@ -281,6 +276,7 @@ class WindowSceneImpl : public WindowScene
281
276
cam->setNearClipDistance (0.5 );
282
277
cam->setAutoAspectRatio (true );
283
278
camNode = sceneMgr->getRootSceneNode ()->createChildSceneNode ();
279
+ camNode->setOrientation (toOGRE);
284
280
camNode->attachObject (cam);
285
281
286
282
if (flags & SCENE_INTERACTIVE)
@@ -356,7 +352,7 @@ class WindowSceneImpl : public WindowScene
356
352
357
353
Quaternion q;
358
354
Vector3 t;
359
- _convertRT (rot, tvec, q, t, false , true );
355
+ _convertRT (rot, tvec, q, t);
360
356
SceneNode* node = sceneMgr->getRootSceneNode ()->createChildSceneNode (t, q);
361
357
node->attachObject (ent);
362
358
}
@@ -387,7 +383,7 @@ class WindowSceneImpl : public WindowScene
387
383
388
384
Quaternion q;
389
385
Vector3 t;
390
- _convertRT (rot, tvec, q, t, false , true );
386
+ _convertRT (rot, tvec, q, t);
391
387
SceneNode* node = sceneMgr->getRootSceneNode ()->createChildSceneNode (t, q);
392
388
node->attachObject (cam);
393
389
@@ -410,7 +406,7 @@ class WindowSceneImpl : public WindowScene
410
406
411
407
Quaternion q;
412
408
Vector3 t;
413
- _convertRT (rot, tvec, q, t, false , true );
409
+ _convertRT (rot, tvec, q, t);
414
410
SceneNode* node = sceneMgr->getRootSceneNode ()->createChildSceneNode (t, q);
415
411
node->attachObject (light);
416
412
}
@@ -430,7 +426,7 @@ class WindowSceneImpl : public WindowScene
430
426
SceneNode& node = _getSceneNode (sceneMgr, name);
431
427
Quaternion q;
432
428
Vector3 t;
433
- _convertRT (rot, tvec, q, t, invert, true );
429
+ _convertRT (rot, tvec, q, t, invert);
434
430
node.setOrientation (q);
435
431
node.setPosition (t);
436
432
}
@@ -546,33 +542,27 @@ class WindowSceneImpl : public WindowScene
546
542
up = toOGRE * up;
547
543
}
548
544
549
- Camera* cam = sceneMgr->getCamera (title);
550
- cam->getParentSceneNode ()->setFixedYawAxis (useFixed, up);
545
+ camNode->setFixedYawAxis (useFixed, up);
551
546
}
552
547
553
548
void setCameraPose (InputArray tvec, InputArray rot, bool invert)
554
549
{
555
- Camera* cam = sceneMgr->getCamera (title);
556
-
557
- SceneNode* node = cam->getParentSceneNode ();
558
550
Quaternion q;
559
551
Vector3 t;
560
- _convertRT (rot, tvec, q, t, invert, true );
552
+ _convertRT (rot, tvec, q, t, invert);
561
553
562
554
if (!rot.empty ())
563
- node ->setOrientation (q);
555
+ camNode ->setOrientation (q*toOGRE );
564
556
565
557
if (!tvec.empty ())
566
- node ->setPosition (t);
558
+ camNode ->setPosition (t);
567
559
}
568
560
569
561
void getCameraPose (OutputArray R, OutputArray tvec, bool invert)
570
562
{
571
- Camera* cam = sceneMgr->getCamera (title);
572
- SceneNode* node = cam->getParentSceneNode ();
573
-
574
563
Matrix3 _R;
575
- node->getOrientation ().ToRotationMatrix (_R);
564
+ // toOGRE.Inverse() == toOGRE
565
+ (camNode->getOrientation ()*toOGRE).ToRotationMatrix (_R);
576
566
577
567
if (invert)
578
568
{
@@ -581,20 +571,18 @@ class WindowSceneImpl : public WindowScene
581
571
582
572
if (tvec.needed ())
583
573
{
584
- Vector3 _tvec = node ->getPosition ();
574
+ Vector3 _tvec = camNode ->getPosition ();
585
575
586
576
if (invert)
587
577
{
588
578
_tvec = _R * -_tvec;
589
579
}
590
580
591
- _tvec = toOGRE.Transpose () * _tvec;
592
581
Mat_<Real>(3 , 1 , _tvec.ptr ()).copyTo (tvec);
593
582
}
594
583
595
584
if (R.needed ())
596
585
{
597
- _R = toOGRE.Transpose () * _R;
598
586
Mat_<Real>(3 , 3 , _R[0 ]).copyTo (R);
599
587
}
600
588
}
@@ -607,18 +595,16 @@ class WindowSceneImpl : public WindowScene
607
595
608
596
void setCameraLookAt (const String& target, InputArray offset)
609
597
{
610
- SceneNode* cam = sceneMgr->getCamera (title)->getParentSceneNode ();
611
598
SceneNode* tgt = sceneMgr->getEntity (target)->getParentSceneNode ();
612
599
613
600
Vector3 _offset = Vector3::ZERO;
614
601
615
602
if (!offset.empty ())
616
603
{
617
604
offset.copyTo (Mat_<Real>(3 , 1 , _offset.ptr ()));
618
- _offset = toOGRE * _offset;
619
605
}
620
606
621
- cam ->lookAt (tgt->_getDerivedPosition () + _offset, Ogre::Node::TS_WORLD);
607
+ camNode ->lookAt (tgt->_getDerivedPosition () + _offset, Ogre::Node::TS_WORLD);
622
608
}
623
609
};
624
610
0 commit comments