@@ -171,6 +171,14 @@ static SceneNode& _getSceneNode(SceneManager* sceneMgr, const String& name)
171
171
return *mo->getParentSceneNode ();
172
172
}
173
173
174
+ static ColourValue convertColor (const Scalar& val)
175
+ {
176
+ // BGR 0..255 (uchar) to RGB 0..1
177
+ ColourValue ret = ColourValue (val[2 ], val[1 ], val[0 ]) / 255 ;
178
+ ret.saturate ();
179
+ return ret;
180
+ }
181
+
174
182
struct Application : public OgreBites ::ApplicationContext, public OgreBites::InputListener
175
183
{
176
184
Ptr<LogManager> logMgr;
@@ -335,11 +343,7 @@ class WindowSceneImpl : public WindowScene
335
343
{
336
344
camman.reset (new OgreBites::CameraMan (camNode));
337
345
camman->setStyle (OgreBites::CS_ORBIT);
338
- #if OGRE_VERSION >= ((1 << 16) | (11 << 8) | 5)
339
346
camman->setFixedYaw (false );
340
- #else
341
- camNode->setFixedYawAxis (true , Vector3::NEGATIVE_UNIT_Y); // OpenCV +Y in Ogre CS
342
- #endif
343
347
}
344
348
345
349
if (!app->sceneMgr )
@@ -512,10 +516,7 @@ class WindowSceneImpl : public WindowScene
512
516
{
513
517
// hide background plane
514
518
bgplane->setVisible (false );
515
-
516
- // BGRA as uchar
517
- ColourValue _color = ColourValue (color[2 ], color[1 ], color[0 ], color[3 ]) / 255 ;
518
- rWin->getViewport (0 )->setBackgroundColour (_color);
519
+ rWin->getViewport (0 )->setBackgroundColour (convertColor (color));
519
520
}
520
521
521
522
void createEntity (const String& name, const String& meshname, InputArray tvec, InputArray rot) CV_OVERRIDE
@@ -579,7 +580,6 @@ class WindowSceneImpl : public WindowScene
579
580
const Scalar& specularColour) CV_OVERRIDE
580
581
{
581
582
Light* light = sceneMgr->createLight (name);
582
- light->setDirection (Vector3::NEGATIVE_UNIT_Z);
583
583
// convert to BGR
584
584
light->setDiffuseColour (ColourValue (diffuseColour[2 ], diffuseColour[1 ], diffuseColour[0 ]));
585
585
light->setSpecularColour (ColourValue (specularColour[2 ], specularColour[1 ], specularColour[0 ]));
@@ -838,9 +838,7 @@ class WindowSceneImpl : public WindowScene
838
838
839
839
void fixCameraYawAxis (bool useFixed, InputArray _up) CV_OVERRIDE
840
840
{
841
- #if OGRE_VERSION >= ((1 << 16) | (11 << 8) | 5)
842
841
if (camman) camman->setFixedYaw (useFixed);
843
- #endif
844
842
845
843
Vector3 up = Vector3::NEGATIVE_UNIT_Y;
846
844
if (!_up.empty ())
@@ -977,8 +975,8 @@ void setMaterialProperty(const String& name, int prop, const Scalar& val)
977
975
CV_Assert (mat);
978
976
979
977
Pass* rpass = mat->getTechniques ()[0 ]->getPasses ()[0 ];
980
- ColourValue col;
981
978
979
+ ColourValue col;
982
980
switch (prop)
983
981
{
984
982
case MATERIAL_POINT_SIZE:
@@ -991,17 +989,16 @@ void setMaterialProperty(const String& name, int prop, const Scalar& val)
991
989
rpass->setSceneBlending (SBT_TRANSPARENT_ALPHA);
992
990
rpass->setDepthWriteEnabled (false );
993
991
break ;
992
+ case MATERIAL_DIFFUSE:
993
+ col = convertColor (val);
994
+ col.a = rpass->getDiffuse ().a ;
995
+ rpass->setDiffuse (col);
996
+ break ;
994
997
case MATERIAL_EMISSIVE:
995
- col = ColourValue (val[2 ], val[1 ], val[0 ]) / 255 ; // BGR as uchar
996
- col.saturate ();
997
- rpass->setEmissive (col);
998
+ rpass->setEmissive (convertColor (val));
998
999
break ;
999
1000
case MATERIAL_LINE_WIDTH:
1000
- #if OGRE_VERSION >= ((1 << 16) | (11 << 8) | 2)
1001
1001
rpass->setLineWidth (val[0 ]);
1002
- #else
1003
- CV_Error (Error::StsError, " needs OGRE 1.11.2+ for this" );
1004
- #endif
1005
1002
break ;
1006
1003
default :
1007
1004
CV_Error (Error::StsBadArg, " invalid or non Scalar property" );
0 commit comments