Dear community,
I use the OpenCV Library to collect feature points in an image and I need to do
intersection testing through the 2D-coordinates of these feature points with
osg.
The origin of the opencv image data structure is top left. The topmost pixel on
the left side is 0,0 and the bottommost on the right side is 639, 479 for
images with the resolution 640x480.
OpenSceneGraph has its origin at the bottom left. That's no problem so far. If
the origin of Osg was at 0,0 bottom left I would just need to use (x, (height -
1) - y) to get a conversion.
But is the Origin of the visible osgviewer at 0,0? because when I use a
PickHandler i get at each corner:
Bottom left: 0, 1
Bottom right: 639, 1
Top left: 0, 480
Top right: 639, 480
So, is the origin really at 0,1? I thought it was strange that x and y
coordinate origin are different. If it was like that I would need to use (x,
height - y) .
This is the code I used to check the coordinates. Is there something I missed
or are my thoughts correct?
Code:
#include <windows.h>
#include <iostream>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
class PickHandler : public osgGA::GUIEventHandler {
public:
PickHandler(){}
~PickHandler() {}
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa);
virtual void pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea);
};
bool PickHandler::handle(const osgGA::GUIEventAdapter&
ea,osgGA::GUIActionAdapter& aa){
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::PUSH):
{
osgViewer::View* view =
dynamic_cast<osgViewer::View*>(&aa);
if (view) pick(view,ea);
return false;
}
default:
return false;
}
}
void PickHandler::pick(osgViewer::View* view, const osgGA::GUIEventAdapter& ea){
float x = ea.getX();
float y = ea.getY();
std::cout<<"X: "<<x<<" Y: "<<y<<std::endl;
}
int main( int argc, char **argv ){
osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
viewer->setSceneData(root.get());
viewer->addEventHandler(new osgViewer::StatsHandler);
viewer->setCameraManipulator(new osgGA::TrackballManipulator);
viewer->addEventHandler(new PickHandler());
viewer->setUpViewInWindow(100, 50, 640, 480);
viewer->run();
}
Thank you!
Dakota
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=45529#45529
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org