hi,

I am using an osg code which plots a few points in 3D space. This
works fine and I am able to move around the scene with the mouse. But
when I add the  line "viewer.addEventHandler(new
KeyboardEventHandler());" to the code and run it, I cant move the
scene/objects (generally we can move the scene by clicking and
dragging with the mouse)  . It just stays still even if I drag the
mouse around. I am pasting the code I am using, below:

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include<iostream>
#include<vector>
#include<string>
#include<fstream>
#include"global.h"
#include"drawables.cpp"
#include"ransac.cpp"


using namespace std;

class KeyboardEventHandler : public osgGA::GUIEventHandler
{
public:
        virtual bool handle(const osgGA::GUIEventAdapter&
ea,osgGA::GUIActionAdapter&)
        {
        }
};

osg::Camera* createHUD()
{
        osg::Camera* camera = new osg::Camera;

        camera->setProjectionMatrix(osg::Matrix::ortho2D(0,2560,0,2048));

        camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
        camera->setViewMatrix(osg::Matrix::identity());

        camera->setClearMask(GL_DEPTH_BUFFER_BIT);

        camera->setRenderOrder(osg::Camera::POST_RENDER);

        camera->setAllowEventFocus(false);


        return camera;
}



int main(int argc,char* argv[])
{

        osgViewer::Viewer viewer;
        viewer.setCameraManipulator(new osgGA::TrackballManipulator);
        viewer.addEventHandler(new osgViewer::StatsHandler);
        viewer.addEventHandler(new KeyboardEventHandler());
               //this is the line giving problems

        osg::Group* root=new osg::Group();
        osg::Geode* geode=new osg::Geode();

        ifstream infile("data1",ios::in);
        vector<osg::Vec3> points;
        double temp1,temp2,temp3;
        //for(int i=0;i<540000;i++)
        //infile >> temp1 >> temp2 >> temp3;
        for(int i=0;i<180;i++)
        {
                if(infile >> temp1 >> temp2 >> temp3)
                        points.push_back(osg::Vec3(temp1,temp2,temp3));

        }
        osg::Plane plane(osg::Vec3(0,0,1.83),points[90],points[45]);
        for(int i=0;i<180;i++)
        {
                if(i==180)
                //      cout <<
"==============================================================" <<
endl;
                double dist=plane.distance(points[i]);
                if(i<180)

root->addChild(drawBox(points[i],0.2,osg::Vec4(1,1,1,1)));
                //cout << dist<< endl;
        }

        osg::Plane plane1(points[60],points[90],points[45]);
        osg::Vec3 norm=plane1.getNormal();
        norm.normalize();
        osg::Vec3Array* vertices=new osg::Vec3Array();
        vertices->push_back(osg::Vec3(100,-100,0)^norm);
        vertices->push_back(osg::Vec3(100,100,0)^norm);
        vertices->push_back(osg::Vec3(-100,100,0)^norm);
        vertices->push_back(osg::Vec3(-100,-100,0)^norm);


//      geode->addDrawable(createPolygon(vertices));
        root->addChild(geode);





        viewer.setSceneData(root);
        viewer.run();

}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to