Commit f3193174 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #1555 from paroj:ovisup

parents 2c0eb14f 0520753d
......@@ -5,9 +5,15 @@ find_package(OGRE 1.10 QUIET)
if(NOT OGRE_FOUND)
message(STATUS "Module opencv_ovis disabled because OGRE3D was not found")
ocv_module_disable(ovis)
elseif(OGRE_VERSION VERSION_LESS 1.10)
message(STATUS "Module opencv_ovis disabled because OGRE3D version is less than 1.10 (${OGRE_VERSION})")
elseif(OGRE_VERSION VERSION_LESS 1.10 OR OGRE_VERSION VERSION_GREATER 2.0)
message(STATUS "Module opencv_ovis disabled because of incompatible OGRE3D version (${OGRE_VERSION})")
ocv_module_disable(ovis)
elseif(OGRE_VERSION VERSION_GREATER 1.10) # we need C++11 for OGRE 1.11
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qstd=c++11")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif()
include_directories(${OGRE_INCLUDE_DIRS}})
......
......@@ -70,6 +70,12 @@ public:
CV_WRAP virtual void createEntity(const String& name, const String& meshname,
InputArray tvec = noArray(), InputArray rot = noArray()) = 0;
/**
* remove an entity from the scene
* @param name entity name
*/
CV_WRAP virtual void removeEntity(const String& name) = 0;
/**
* convenience method to visualize a camera position
*
......
......@@ -107,13 +107,13 @@ static void _setCameraIntrinsics(Camera* cam, InputArray _K, const Size& imsize)
cam->setFrustumOffset(toOGRE_SS * Vector2(pp_offset.val));
}
static SceneNode* _getSceneNode(SceneManager* sceneMgr, const String& name)
static SceneNode& _getSceneNode(SceneManager* sceneMgr, const String& name)
{
MovableObject* mo = NULL;
try
{
mo = sceneMgr->getCamera(name);
mo = sceneMgr->getMovableObject(name, "Camera");
}
catch (ItemIdentityException&)
{
......@@ -123,7 +123,7 @@ static SceneNode* _getSceneNode(SceneManager* sceneMgr, const String& name)
try
{
if (!mo)
mo = sceneMgr->getLight(name);
mo = sceneMgr->getMovableObject(name, "Light");
}
catch (ItemIdentityException&)
{
......@@ -131,9 +131,9 @@ static SceneNode* _getSceneNode(SceneManager* sceneMgr, const String& name)
}
if (!mo)
mo = sceneMgr->getEntity(name);
mo = sceneMgr->getMovableObject(name, "Entity"); // throws if not found
return mo->getParentSceneNode();
return *mo->getParentSceneNode();
}
struct Application : public OgreBites::ApplicationContext, public OgreBites::InputListener
......@@ -323,12 +323,21 @@ public:
Pass* rpass = bgplane->getMaterial()->getBestTechnique()->getPasses()[0];
rpass->getTextureUnitStates()[0]->setTextureName(name);
// ensure bgplane is visible
bgplane->setVisible(true);
}
void setBackground(const Scalar& color)
{
Mat img(1, 1, CV_8UC3, color);
setBackground(img);
// hide background plane
bgplane->setVisible(false);
// BGRA as uchar
ColourValue _color = ColourValue(color[2], color[1], color[0], color[3]) / 255;
rWin->getViewport(0)->setBackgroundColour(_color);
if(frameSrc != rWin)
frameSrc->getViewport(0)->setBackgroundColour(_color);
}
void createEntity(const String& name, const String& meshname, InputArray tvec, InputArray rot)
......@@ -342,6 +351,13 @@ public:
node->attachObject(ent);
}
void removeEntity(const String& name) {
SceneNode& node = _getSceneNode(sceneMgr, name);
node.getAttachedObject(name)->detachFromParent();
sceneMgr->destroyEntity(name);
sceneMgr->destroySceneNode(&node);
}
Rect2d createCameraEntity(const String& name, InputArray K, const Size& imsize, float zFar,
InputArray tvec, InputArray rot)
{
......@@ -391,22 +407,22 @@ public:
void updateEntityPose(const String& name, InputArray tvec, InputArray rot)
{
SceneNode* node = _getSceneNode(sceneMgr, name);
SceneNode& node = _getSceneNode(sceneMgr, name);
Quaternion q;
Vector3 t;
_convertRT(rot, tvec, q, t);
node->rotate(q, Ogre::Node::TS_LOCAL);
node->translate(t, Ogre::Node::TS_LOCAL);
node.rotate(q, Ogre::Node::TS_LOCAL);
node.translate(t, Ogre::Node::TS_LOCAL);
}
void setEntityPose(const String& name, InputArray tvec, InputArray rot, bool invert)
{
SceneNode* node = _getSceneNode(sceneMgr, name);
SceneNode& node = _getSceneNode(sceneMgr, name);
Quaternion q;
Vector3 t;
_convertRT(rot, tvec, q, t, invert);
node->setOrientation(q);
node->setPosition(t);
node.setOrientation(q);
node.setPosition(t);
}
void _createBackground()
......
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