Re: [osg-users] MousepressEvent not able to capture from osg::Viewer by Qt
On 8.5.2013 7:04, Sujan Dasmahapatra wrote: I am trying to implement a mouse press event with QT and OSG but unable to do it. Pls help. Below is my ViewerWidget class which is derived from QWidget and osg::CompositeViewer..In the constructor I got gView which is a osg::GLWidget, I am trying override mousePressEvent but when I click message not coming. What I am doing wrong pls help.. [snip] osg::Camera* ViewerWidget::createCamera( int x, int y, int w, int h, const std::string name, bool windowDecoration ) { osg::DisplaySettings* ds = osg::DisplaySettings::instance().get(); osg::ref_ptrosg::GraphicsContext::Traits traits = new osg::GraphicsContext::Traits; 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_ptrosg::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_castdouble(traits-width)/static_castdouble(traits-height), 1.0f, 1.0f ); return camera.release(); } I don't know why this code didn't crash, I think it should. Anyway, you should create an instance of the CSGraphicsView somewhere within createCamera: CSGraphicsView* gView = new CSGraphicsView; gView-setGeometry(x, y, w, h); traits-inheritedWindowData = new osgQt::GraphicsWindowQt::WindowData( gView ); ... or you can pass an instance of the CSGraphicsView to the osgQt::GraphicsWindowQt constructor. Robert Milharcic ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] switch off mouse press events
In every example I see in the viewer that left mouse press and move cause it to rotate 3d, middle mouse press move cause it to pan, and left mouse press and move forward backward cause it zoom in and zoom out. How can I override this events. For example I dont want anything to happen on my left mouse. How can I achieve this?. 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
Re: [osg-users] MousepressEvent not able to capture from osg::Viewer by Qt
Thanks Robert. It is working fine... On the left mouse press I am showing a message using QMessagBox. But on the middle mouse press was having pan and right mouse press was having zoom in zoom out. How can I retain those functionalities. With this these functionalities are gone. void CSGraphicsView::mousePressEvent(QMouseEvent *e) { if(e-button()==Qt::LeftButton) { QMessageBox msg; msg.setText(Mouse pressed); msg.exec(); } } On Wed, May 8, 2013 at 3:59 PM, Robert Milharcic robert.milhar...@ib-caddy.si wrote: On 8.5.2013 7:04, Sujan Dasmahapatra wrote: I am trying to implement a mouse press event with QT and OSG but unable to do it. Pls help. Below is my ViewerWidget class which is derived from QWidget and osg::CompositeViewer..In the constructor I got gView which is a osg::GLWidget, I am trying override mousePressEvent but when I click message not coming. What I am doing wrong pls help.. [snip] osg::Camera* ViewerWidget::createCamera( int x, int y, int w, int h, const std::string name, bool windowDecoration ) { osg::DisplaySettings* ds = osg::DisplaySettings::** instance().get(); osg::ref_ptrosg::**GraphicsContext::Traits traits = new osg::GraphicsContext::Traits; 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_ptrosg::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-**setProjectionMatrixAsPerspecti**ve( 30.0f, static_castdouble(traits-** width)/static_castdouble(**traits-height), 1.0f, 1.0f ); return camera.release(); } I don't know why this code didn't crash, I think it should. Anyway, you should create an instance of the CSGraphicsView somewhere within createCamera: CSGraphicsView* gView = new CSGraphicsView; gView-setGeometry(x, y, w, h); traits-inheritedWindowData = new osgQt::GraphicsWindowQt::**WindowData( gView ); ... or you can pass an instance of the CSGraphicsView to the osgQt::GraphicsWindowQt constructor. Robert Milharcic __**_ osg-users mailing list osg-users@lists.**openscenegraph.org osg-users@lists.openscenegraph.org http://lists.openscenegraph.**org/listinfo.cgi/osg-users-** openscenegraph.orghttp://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
Re: [osg-users] switch off mouse press events
Hi Sujan, what you are describing is the normal behavior of the Trackball CameraManipulator. There are many ways how you can change processing of mouse events. Either remove the CameraManipulator (view-getCamera()-setCameraManipulator(0)) or inherit from the one CameraMainpulator that most suit your needs and override the processing of the events (handle method). If you have some specifics about how to handle mouse and keyboard events then go for the later, I would guess Nick On Wed, May 8, 2013 at 10:05 AM, Sujan Dasmahapatra sujan.dasmahapa...@gmail.com wrote: In every example I see in the viewer that left mouse press and move cause it to rotate 3d, middle mouse press move cause it to pan, and left mouse press and move forward backward cause it zoom in and zoom out. How can I override this events. For example I dont want anything to happen on my left mouse. How can I achieve this?. 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
Re: [osg-users] switch off mouse press events
Thanks Trajce for your nice suggestions I am looking into it. Thanks a lot. On Wed, May 8, 2013 at 4:40 PM, Trajce Nikolov NICK trajce.nikolov.n...@gmail.com wrote: Hi Sujan, what you are describing is the normal behavior of the Trackball CameraManipulator. There are many ways how you can change processing of mouse events. Either remove the CameraManipulator (view-getCamera()-setCameraManipulator(0)) or inherit from the one CameraMainpulator that most suit your needs and override the processing of the events (handle method). If you have some specifics about how to handle mouse and keyboard events then go for the later, I would guess Nick On Wed, May 8, 2013 at 10:05 AM, Sujan Dasmahapatra sujan.dasmahapa...@gmail.com wrote: In every example I see in the viewer that left mouse press and move cause it to rotate 3d, middle mouse press move cause it to pan, and left mouse press and move forward backward cause it zoom in and zoom out. How can I override this events. For example I dont want anything to happen on my left mouse. How can I achieve this?. 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
Re: [osg-users] MousepressEvent not able to capture from osg::Viewer by Qt
On 8.5.2013 10:16, Sujan Dasmahapatra wrote: Thanks Robert. It is working fine... On the left mouse press I am showing a message using QMessagBox. But on the middle mouse press was having pan and right mouse press was having zoom in zoom out. How can I retain those functionalities. With this these functionalities are gone. void CSGraphicsView::mousePressEvent(QMouseEvent *e) { if(e-button()==Qt::LeftButton) { QMessageBox msg; msg.setText(Mouse pressed); msg.exec(); } } Call base class implementation in a case where you need to retain original functionality: void CSGraphicsView::mousePressEvent(QMouseEvent *e) { if(e-button()==Qt::LeftButton) { QMessageBox msg; msg.setText(Mouse pressed); msg.exec(); } else GLWidget::mousePressEvent(e); } Also, calling frame on paintEvent might not be enough. You should also call frame on every user input, on all mouse and keyboard events for example... or you can mount a QTimer and make it call frame at some interval. Robert Milharcic ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] MousepressEvent not able to capture from osg::Viewer by Qt
Thats right Robert. Thanks a lot for your suggestions I appreciate it. Thanks Sujan On Wed, May 8, 2013 at 5:40 PM, Robert Milharcic robert.milhar...@ib-caddy.si wrote: On 8.5.2013 10:16, Sujan Dasmahapatra wrote: Thanks Robert. It is working fine... On the left mouse press I am showing a message using QMessagBox. But on the middle mouse press was having pan and right mouse press was having zoom in zoom out. How can I retain those functionalities. With this these functionalities are gone. void CSGraphicsView::mousePressEvent(QMouseEvent *e) { if(e-button()==Qt::LeftButton) { QMessageBox msg; msg.setText(Mouse pressed); msg.exec(); } } Call base class implementation in a case where you need to retain original functionality: void CSGraphicsView::mousePressEvent(QMouseEvent *e) { if(e-button()==Qt::LeftButton) { QMessageBox msg; msg.setText(Mouse pressed); msg.exec(); } else GLWidget::mousePressEvent(e); } Also, calling frame on paintEvent might not be enough. You should also call frame on every user input, on all mouse and keyboard events for example... or you can mount a QTimer and make it call frame at some interval. Robert Milharcic ___ 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
[osg-users] PointSprite Texture orientation
Hi all I use pointsprites to simulate precipitation (rain/snow). The implementation is completed and works very well. Now the end user decided to rotate the viewport about 90 degrees. The problem is now that the pointsprite texture coordinates to not take into accout the rotated viewport and the raindrops (small lines) are transversly and are not oriented in their falling direction. I tried to set a TexGen object in the stateset but what arguments do I have to set? Thank you! Cheers, Daniel -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=53959#53959 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Wish: convert osgGA::GUIEventAdapter to QKeySequence
I found Ctrl+Shift+0 is eaten by Windows to switch keyboards and may be disabled. I still wish the unmodified key was passed through for many purposes!!! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=53960#53960 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] PointSprite Texture orientation
Hello Daniel, I don't know if I get the problem correctly. So what you want is essentially to rotate the texture on the pointsprite. I can think of various solutions: 1. Setup the TextureMatrix to represent your rotation in texture space. 2. Use a vertex shader to do the rotation your-self (e.g. in your case you might swap xy to yx) 3. Rotate the texture ;-) cheers Sebastian Hi all I use pointsprites to simulate precipitation (rain/snow). The implementation is completed and works very well. Now the end user decided to rotate the viewport about 90 degrees. The problem is now that the pointsprite texture coordinates to not take into accout the rotated viewport and the raindrops (small lines) are transversly and are not oriented in their falling direction. I tried to set a TexGen object in the stateset but what arguments do I have to set? Thank you! Cheers, Daniel -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=53959#53959 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] OcclusionQueryNode and Depth Splitting
Hi all, I am facing a problem when trying to use the occlusion query node while implementing Z splitting for rendering large scenes. I know osg has z splitting but I had to implement by my self since I have a separated frustum and projection system (projection matrices are placed within osg camera). I am currently trying this: 1) I made a pausable occlusion query node that can be paused and its current passed state reamains unchanged. 2) I render the whole scene using a very large frustum (represeting the sum of all partitions, i.e the original large frustum). 3) I pause all OQN by using a visitor. 4) Render the scene using the partitions and the pre-set occlusion state that was paused while rendering the partitions. It is not working not even for a single object.. it blinks non-stop... Does anyone has any suggestion? Does Openscenegraph currently supports Z-Splitting along with OQNodes? Thanks! -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=53962#53962 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] OpenCL context creation
Hi forum, I believe that there are similar threads almost about this issue, but they did not answer the problem i am having now. I have been the going through the source of osgCuda and took the hint from it about context creation. I created a separate class that handles all the OpenCL context creation from osg as follows: Code: osgOpenCLContext::osgOpenCLContext(): m_clContext(NULL), m_clPlatform(NULL), m_clDevice(NULL), m_clCommandQueue(NULL) { } osgOpenCLContext::~osgOpenCLContext() { if(m_clCommandQueue) clReleaseCommandQueue(m_clCommandQueue); if(m_clContext) clReleaseContext(m_clContext); } bool osgOpenCLContext::setupOsgOpenCLAndViewer(osgViewer::ViewerBase viewer, int ctxID /*= -1 */) { // You must use single threaded version since osgCompute currently // does only support single threaded applications. viewer.setThreadingModel( osgViewer::ViewerBase::SingleThreaded ); // Does create a single OpenGL context // which is not released at the end of a frame to secure // CUDA launches everywhere viewer.setReleaseContextAtEndOfFrameHint(false); // Create the current OpenGL context and make it current if( !viewer.isRealized() ) viewer.realize(); osgViewer::ViewerBase::Contexts ctxs; viewer.getContexts( ctxs, true ); if( ctxs.empty() ) { osg::notify(osg::FATAL) __FUNCTION__ : no valid OpenGL context is found.std::endl; return false; } osg::GraphicsContext* ctx = NULL; #ifdef WIN32 osgViewer::GraphicsHandleWin32 *windowsContext = NULL; #else osgViewer::GraphicsHandleX11 *linuxContext = NULL; #endif if( ctxID != -1 ) { // Find context with ctxID and make it current. for( unsigned int c=0; cctxs.size(); ++c ) { if( ctxs[c]-getState()-getContextID() == ctxID ) { ctx = ctxs[c]; } } } else { ctx = ctxs.front(); } if( NULL == ctx ) { osg::notify(osg::FATAL) __FUNCTION__ : cannot find valid OpenGL context.std::endl; return false; } //platform dependent casting #ifdef WIN32 windowsContext = dynamic_castosgViewer::GraphicsHandleWin32*(ctx); if(NULL == windowsContext) { osg::notify(osg::FATAL) Win32 Graphics Context Casting is unsuccessful std::endl; return false; } else osg::notify(osg::INFO) Win32 Graphics Context Casting is successful std::endl; #else linuxContext = dynamic_castosgViewer::GraphicsHandleX11*(ctx); if(NULL == linuxContext) { osg::notify(osg::FATAL) X11 Graphics Context Casting is unsuccessful std::endl; return false; } else osg::notify(osg::INFO) X11 Graphics Context Casting is successful std::endl; #endif cl_uint numPlatforms; cl_platform_id *platformIDs; cl_int errNum; //first query the total number of platforms errNum = clGetPlatformIDs(0,NULL,numPlatforms); if(errNum != CL_SUCCESS || numPlatforms = 0) { osg::notify(osg::FATAL) Failed to find any OpenCL platform std::endl; return false; } //next, allocate memory for the installed platforms, and query //to get the list platformIDs = (cl_platform_id *)alloca(sizeof(cl_platform_id) * numPlatforms); errNum = clGetPlatformIDs(numPlatforms,platformIDs,NULL); if(errNum != CL_SUCCESS) { osg::notify(osg::FATAL) Failed to find any OpenCL platform std::endl; return false; } //now choose the very first platform m_clPlatform = platformIDs[0]; char cBuffer[1024]; //get the platform information from the selected platform errNum = clGetPlatformInfo(m_clPlatform,CL_PLATFORM_NAME,sizeof(cBuffer),cBuffer,NULL); if(errNum == CL_SUCCESS) { osg::notify(osg::INFO) OpenCL platform name: cBuffer std::endl; } //by now the graphics context is found //and the platform id is also found cl_context_properties contextProperties[] = { #ifdef WIN32 CL_GL_CONTEXT_KHR, (cl_context_properties) windowsContext-getWGLContext(), CL_WGL_HDC_KHR, (cl_context_properties) windowsContext-getHDC(), #else CL_GL_CONTEXT_KHR, (cl_context_properties) linuxContext-getContext(), CL_GLX_DISPLAY_KHR, (intptr_t) linuxContext-getDisplay(), #endif CL_CONTEXT_PLATFORM, (cl_context_properties) m_clPlatform, 0 }; //create context with the
[osg-users] Translate problem
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_castViewerWidget*(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_ptrosgGA::StateSetManipulator statesetManipulator = new osgGA::StateSetManipulator(view-getCamera()-getStateSet()); view-addEventHandler(statesetManipulator.get()); gw = dynamic_castosgQt::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_ptrosg::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_ptrosg::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_castdouble(traits-width)/static_castdouble(traits-height), 1.0f, 1.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