Skip to content

Commit 1b636e7

Browse files
committed
Merge pull request #2171 from AlexJ95:ovis-add-entity-LookAt
2 parents 297e8be + 51b16a8 commit 1b636e7

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

modules/ovis/include/opencv2/ovis.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ class CV_EXPORTS_W WindowScene {
165165
CV_WRAP virtual void setEntityPose(const String& name, InputArray tvec = noArray(),
166166
InputArray rot = noArray(), bool invert = false) = 0;
167167

168+
/**
169+
* Retrieves the current pose of an entity
170+
* @param name entity name
171+
* @param R 3x3 rotation matrix
172+
* @param tvec translation vector
173+
* @param invert return the inverted pose
174+
*/
175+
CV_WRAP virtual void getEntityPose(const String& name, OutputArray R = noArray(), OutputArray tvec = noArray(),
176+
bool invert = false) = 0;
177+
168178
/**
169179
* get a list of available entity animations
170180
* @param name entity name
@@ -236,6 +246,15 @@ class CV_EXPORTS_W WindowScene {
236246
*/
237247
CV_WRAP virtual void setCameraLookAt(const String& target, InputArray offset = noArray()) = 0;
238248

249+
/**
250+
* convenience method to orient an entity to a specific entity.
251+
* If target is an empty string the entity looks at the given offset point
252+
* @param origin entity to make look at
253+
* @param target name of target entity
254+
* @param offset offset from entity centre
255+
*/
256+
CV_WRAP virtual void setEntityLookAt(const String& origin, const String& target, InputArray offset = noArray()) = 0;
257+
239258
/**
240259
* Retrieves the current camera pose
241260
* @param R 3x3 rotation matrix

modules/ovis/src/ovis.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,36 @@ class WindowSceneImpl : public WindowScene
579579
node.setPosition(t);
580580
}
581581

582+
void getEntityPose(const String& name ,OutputArray R, OutputArray tvec, bool invert) CV_OVERRIDE
583+
{
584+
SceneNode* node = sceneMgr->getEntity(name)->getParentSceneNode();
585+
Matrix3 _R;
586+
// toOGRE.Inverse() == toOGRE
587+
(node->getOrientation()*toOGRE).ToRotationMatrix(_R);
588+
589+
if (invert)
590+
{
591+
_R = _R.Transpose();
592+
}
593+
594+
if (tvec.needed())
595+
{
596+
Vector3 _tvec = node->getPosition();
597+
598+
if (invert)
599+
{
600+
_tvec = _R * -_tvec;
601+
}
602+
603+
Mat_<Real>(3, 1, _tvec.ptr()).copyTo(tvec);
604+
}
605+
606+
if (R.needed())
607+
{
608+
Mat_<Real>(3, 3, _R[0]).copyTo(R);
609+
}
610+
}
611+
582612
void getEntityAnimations(const String& name, std::vector<String>& out) CV_OVERRIDE
583613
{
584614
SceneNode& node = _getSceneNode(sceneMgr, name);
@@ -848,6 +878,26 @@ class WindowSceneImpl : public WindowScene
848878

849879
camNode->lookAt(tgt->_getDerivedPosition() + _offset, Ogre::Node::TS_WORLD);
850880
}
881+
882+
void setEntityLookAt(const String& origin, const String& target, InputArray offset) CV_OVERRIDE
883+
{
884+
SceneNode* orig = sceneMgr->getEntity(origin)->getParentSceneNode();
885+
886+
Vector3 _offset = Vector3::ZERO;
887+
888+
if (!offset.empty())
889+
{
890+
offset.copyTo(Mat_<Real>(3, 1, _offset.ptr()));
891+
}
892+
893+
if(target.compare("") != 0){
894+
SceneNode* tgt = sceneMgr->getEntity(target)->getParentSceneNode();
895+
orig->lookAt(tgt->_getDerivedPosition() + _offset, Ogre::Node::TS_WORLD, Ogre::Vector3::UNIT_Z);
896+
}else{
897+
orig->lookAt(_offset, Ogre::Node::TS_WORLD, Ogre::Vector3::UNIT_Z);
898+
}
899+
}
900+
851901
};
852902

853903
CV_EXPORTS_W void addResourceLocation(const String& path)

0 commit comments

Comments
 (0)