Dear Nick thanks a lot for your code snippet. I appreciate it. I am after
custom mouse event handling, I dont want TrackBallManipulator as I am more
interested to manage events from Qt.


On Thu, May 9, 2013 at 2:35 PM, Trajce Nikolov NICK <
trajce.nikolov.n...@gmail.com> wrote:

> Hi Sujan,
>
> viewerWid->getView()->getCamera()->setViewMatrix(::osg::Matrix::translate(1000.5,
> 0.0, 0.0));
> this code is wrong. Also, you have attached TrackballCameraManipulator so
> it will fight you against the translation you do.
>
> If you want to translate an object in the scene, then use
> osg::MatrixTransofrm as parent of your object and there set the
> translation. If you want to change the ViewMatrix, then set the inverse of
> your world translation, but also update the CameraManipulator, so something
> like:
>
> osg::Matrixd myMatrix = osg::Matrix::translate(1000.5, 0.0, 0.0);
> viewerWid->getView()->
> getCamera()->setViewMatrix(osg::Matrix::inverse(myMatrix));
> viewerWid->getView()->getCameraManipulator()->setByMatrix(myMatrix);
>
> If you are after custom mouse management, then I would inherit from
> TrackballcameraManipulator and override handle - look in the code od
> TrackballCameraManipulator::handle since it is the closest to your wish of
> mouse handling
>
> Hope this helps a bit
>
> Nick
>
>
> On Thu, May 9, 2013 at 4:09 AM, Sujan Dasmahapatra <
> sujan.dasmahapa...@gmail.com> wrote:
>
>> I am trying to translate my objects in scene, when the right mouse button
>> is pressed. But it is not moving. Pls check the snippet.
>>
>> [code]
>> //CSGraphicsView
>> //.h
>> class CSGraphicsView : public osgQt::GLWidget
>> {
>> Q_OBJECT
>> public:
>> CSGraphicsView(QWidget* parent=0);
>>  ~CSGraphicsView();
>> virtual void mousePressEvent(QMouseEvent *e);
>> virtual void mouseReleaseEvent(QMouseEvent *e);
>>  virtual void mouseMoveEvent(QMouseEvent *e);
>>
>> };
>>
>> #endif // GVIEW_H
>> ////////////////////////////////////////////.cpp
>> void CSGraphicsView::mousePressEvent(QMouseEvent *e)
>> {
>> if(e->button()==Qt::LeftButton)
>> {
>>  QMessageBox msg;
>> msg.setText("Left Mouse pressed");
>> msg.exec();
>>  }
>> else if(e->button()==Qt::RightButton)
>> {
>>  //QMessageBox msg;
>> //msg.setText("Right Mouse pressed");
>> //msg.exec();
>>
>> ViewerWidget* viewerWid = qobject_cast<ViewerWidget*>(parent());
>> viewerWid->getView()->getCamera()->setViewMatrix(::osg::Matrix::translate(1000.5,
>> 0.0, 0.0));
>>  }
>> else if(e->button()==Qt::MiddleButton)
>> {
>>  QMessageBox msg;
>> msg.setText("Middle Mouse pressed");
>> msg.exec();
>>  }
>> else
>> return;
>> }
>>
>>
>> ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>> //This is my ViewerWidget class
>>
>> class ViewerWidget : public QWidget, public osgViewer::CompositeViewer
>> {
>> Q_OBJECT
>> public:
>>     ViewerWidget(osgViewer::ViewerBase::ThreadingModel
>> threadingModel=osgViewer::CompositeViewer::SingleThreaded, osg::Group*
>> scene=NULL);
>>
>> osgQt::GLWidget* addViewWidget( osg::Camera* camera, osg::Group* scene );
>>
>> osg::Camera* createCamera( int x, int y, int w, int h, const std::string&
>> name="", bool windowDecoration=false );
>>
>>     virtual void paintEvent( QPaintEvent* event );
>>
>> osgViewer::View* getView();
>>
>> protected:
>>
>>     QTimer _timer;
>>
>> osgQt::GraphicsWindowQt* gw;
>>
>> CSGraphicsView*  gView;
>>
>> osgViewer::View* view;
>> };
>>
>> #endif // VIEWERWIDGET_H
>>
>> //viewerwidget.cpp
>>
>> ViewerWidget::ViewerWidget(osgViewer::ViewerBase::ThreadingModel
>> threadingModel, osg::Group* scene) : QWidget()
>>     {
>>         setThreadingModel(threadingModel);
>>
>>         gView = (CSGraphicsView*) (addViewWidget(
>> createCamera(0,0,100,100), scene ));
>>
>>         QGridLayout* grid = new QGridLayout;
>>         grid->addWidget( gView, 0, 0 );
>>          setLayout( grid );
>>
>>         connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
>>         _timer.start( 10 );
>>     }
>>
>> osgQt::GLWidget* ViewerWidget::addViewWidget( osg::Camera* camera,
>> osg::Group* scene )
>> {
>>     view = new osgViewer::View;
>>         view->setCamera( camera );
>>         addView( view );
>>         view->setSceneData( scene );
>>  view->addEventHandler( new osgViewer::StatsHandler );
>>         view->setCameraManipulator( new osgGA::TrackballManipulator );
>> osg::ref_ptr<osgGA::StateSetManipulator> statesetManipulator = new
>> osgGA::StateSetManipulator(view->getCamera()->getStateSet());
>>  view->addEventHandler(statesetManipulator.get());
>>         gw = dynamic_cast<osgQt::GraphicsWindowQt*> (
>> camera->getGraphicsContext() );
>>         return gw ? gw->getGLWidget() : NULL;
>> }
>>
>>
>> osg::Camera* ViewerWidget::createCamera( int x, int y, int w, int h,
>> const std::string& name, bool windowDecoration )
>>     {
>> gView = new CSGraphicsView(this);
>> gView->setGeometry(x, y, w, h);
>>          osg::DisplaySettings* ds =
>> osg::DisplaySettings::instance().get();
>>         osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
>> osg::GraphicsContext::Traits;
>>
>> traits->inheritedWindowData = new osgQt::GraphicsWindowQt::WindowData(
>> gView );
>>         traits->windowName = name;
>>         traits->windowDecoration = windowDecoration;
>>         traits->x = x;
>>         traits->y = y;
>>         traits->width = w;
>>         traits->height = h;
>>         traits->doubleBuffer = true;
>>         traits->alpha = ds->getMinimumNumAlphaBits();
>>         traits->stencil = ds->getMinimumNumStencilBits();
>>         traits->sampleBuffers = ds->getMultiSamples();
>>         traits->samples = ds->getNumMultiSamples();
>>
>>         osg::ref_ptr<osg::Camera> camera = new osg::Camera;
>>         camera->setGraphicsContext( new
>> osgQt::GraphicsWindowQt(traits.get()) );
>>
>>         camera->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
>>         camera->setViewport( new osg::Viewport(0, 0, traits->width,
>> traits->height) );
>>         camera->setProjectionMatrixAsPerspective(
>>             30.0f,
>> static_cast<double>(traits->width)/static_cast<double>(traits->height),
>> 1.0f, 10000.0f );
>>         return camera.release();
>>  }
>>
>>
>>
>> void ViewerWidget::paintEvent( QPaintEvent* event )
>> {
>> frame();
>> }
>>
>>
>> osgViewer::View* ViewerWidget::getView()
>> {
>> return view;
>> }
>>
>>
>> [/code]
>>
>>
>> Please tell me why is it not moving ??.....I want to implement a rotate
>> functionality on right mouse press button, a pan function on middle mouse
>> press function and a zoom function on wheel event.       Any help is highly
>> appreciated. Thanks Sujan
>>
>>
>>
>>
>>
>>
>>
>> --
>> Thanks & Regards
>> Sujan
>>
>> _______________________________________________
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>>
>
>
> --
> trajce nikolov nick
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


-- 
Thanks & Regards
Sujan
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to