I think you need to pass the events from the main thread to your manipulator
thread. There was recent discussion about this

http://www.mail-archive.com/[email protected]/msg35853.html
<http://www.mail-archive.com/[email protected]/msg35853.html>
Nick

http://www.linkedin.com/in/tnick
Sent from Devlet, Ankara, Turkey

On Wed, Jan 13, 2010 at 10:51 AM, Tufan Taş <[email protected]> wrote:

> Hi,
>
> I define a manipulator for my project that rotates the scene using arrow
> keys and view the scene in a control of windows form by using a thread. But
> my manipulator does not work when I embed the scene into windows form. Here
> is my code.
>
>
> Viewer osgViewer;
>
> void OSGProject::OSGThread()
> {
>        MyManipulator* myManpltr = new MyManipulator();
>        osgViewer.setCameraManipulator(myManpltr);
>
>        osgViewer.getCamera()->setProjectionMatrixAsPerspective(90, 1, 1,
> 100);
>
>        Matrix initialTranslate;
>        initialTranslate.makeTranslate(0, 0, 0);
>
>        Matrix initialRotate;
>        initialRotate.makeRotate(180, Vec3(1, 1, 1));
>
>        osgViewer.getCamera()->setViewMatrix( initialRotate *
> initialTranslate );
>
>        osgViewer.run();
> }
>
>
>        void OSGProject::show(System::IntPtr controlToRender)
>        {
> mapNode =
> readNodeFile(msclr::interop::marshal_as<string>(mapPath->Copy(mapPath)));
>
>                Group* root = new Group();
>                root->addChild(mapNode);
>
>                osgViewer.setSceneData(root);
>
>
>
>                RECT rect;
>        HWND mHwnd=(HWND)controlToRender.ToPointer();
>        GetWindowRect(mHwnd, &rect);
>
>        osg::ref_ptr<osg::Referenced> windata = new
> osgViewer::GraphicsWindowWin32::WindowData(mHwnd);
>        osg::ref_ptr<osg::GraphicsContext::Traits> traits=new
> osg::GraphicsContext::Traits();
>
>        traits->x = 0;
>        traits->y = 0;
>        traits->width = rect.right - rect.left;
>        traits->height = rect.bottom - rect.top;
>        traits->windowDecoration = false;
>        traits->doubleBuffer = true;
>        traits->sharedContext = 0;
>
> traits->supportsResize = true;
>
>        traits->inheritedWindowData = windata;
>
>
>        traits->setInheritedWindowPixelFormat = true;
>
>        PIXELFORMATDESCRIPTOR pixelFormat =
>        {
>                sizeof(PIXELFORMATDESCRIPTOR),
>                1,
>                PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,
>                PFD_TYPE_RGBA,
>                24,
>                0, 0, 0, 0, 0, 0, 0, 0,
>                0, 0, 0, 0, 0,
>                24,
>                0,
>                0,
>                PFD_MAIN_PLANE,
>                0,
>                0, 0, 0
>        };
>
>        HDC hdc = ::GetDC(mHwnd);
>        if (hdc==0)
>        {
>                ::DestroyWindow(mHwnd);
>                return ;
>        }
>
>        int pixelFormatIndex = ::ChoosePixelFormat(hdc, &pixelFormat);
>        if (pixelFormatIndex==0)
>        {
>                ::ReleaseDC(mHwnd, hdc);
>                ::DestroyWindow(mHwnd);
>                return ;
>        }
>
>        if (!::SetPixelFormat(hdc, pixelFormatIndex, &pixelFormat))
>        {
>                ::ReleaseDC(mHwnd, hdc);
>                ::DestroyWindow(mHwnd);
>                return ;
>        }
>
>        osg::ref_ptr<osg::GraphicsContext>
> gc=osg::GraphicsContext::createGraphicsContext(traits.get());
>
>        osg::ref_ptr<osg::Camera> camera=new osg::Camera;
>        camera->setGraphicsContext(gc.get());
>        camera->setViewport(new
> osg::Viewport(0,0,traits->width,traits->height));
>
>
>        camera->setDrawBuffer(GL_BACK);
>        camera->setReadBuffer(GL_BACK);
>
>        osgViewer.addSlave(camera.get());
>
> System::Threading::Thread^ OSGthread;
>
>        OSGthread=gcnew System::Threading::Thread(gcnew
> System::Threading::ThreadStart(this, &OSGProject::OSGThread));
>        OSGthread->Priority=Threading::ThreadPriority::BelowNormal;
>        OSGthread->Start();
> }
>
> Thank you!
>
> Cheers,
> Tufan
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=22486#22486
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to