Hi,

I've been having trouble implementing slave cameras for an application I'm 
working on. The camera gets its position and orientation from a motion tracking 
system or through joystick input. When I don't set up slave cameras, the camera 
properly responds to input. However, when I implement slave cameras, they do 
not update their position or orientation with input from the motion tracking or 
joy stick.

In the code below, if I comment out the code that sets up the slave cameras, 
the viewer responds properly to input from the joystick or the motion tracker. 
If it is not commented, the slave cameras will display, but they will not 
respond to the motion tracker or joystick. If anyone could provide any 
suggestions, they would be much appreciated.

Thank you!
rjkern

Code:

viewer = new FLTViewer(arguments); //FLTViewer is and extension of the 
osgViewer::Viewer class. It receives the camera position and orientation from a 
server program.

//Here is where I set up the slave camera
            int xoffset = 40;
            int yoffset = 40;
        
            // left window + left slave camera
            {
                osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits;
                traits->x = xoffset + 0;
                traits->y = yoffset + 0;
                traits->width = 600;
                traits->height = 480;
                traits->windowDecoration = true;
                traits->doubleBuffer = true;
                traits->sharedContext = 0;
        
                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));
                GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
                camera->setDrawBuffer(buffer);
                camera->setReadBuffer(buffer);
        
                // add this slave camera to the viewer, with a shift left of 
the projection matrix
                        viewer->addSlave(camera.get(), 
osg::Matrixd::translate(1.0,0.0,0.0), osg::Matrixd::rotate(45, Vec3f(1,0,0)));
            }
           
            // right window + right slave camera
            {
                osg::ref_ptr<osg::GraphicsContext::Traits> traits = new 
osg::GraphicsContext::Traits;
                traits->x = xoffset + 600;
                traits->y = yoffset + 0;
                traits->width = 600;
                traits->height = 480;
                traits->windowDecoration = true;
                traits->doubleBuffer = true;
                traits->sharedContext = 0;
        
                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));
                GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
                camera->setDrawBuffer(buffer);
                camera->setReadBuffer(buffer);
        
                // add this slave camera to the viewer, with a shift right of 
the projection matrix
                //viewer->addSlave(camera.get(), 
osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd());
                        viewer->addSlave(camera.get(), 
osg::Matrixd::translate(-1.0,0.0,0.0), osg::Matrixd::rotate(45, Vec3f(1,0,0)));
            }
        

        //create socket and set up connections.
    viewer->initRecvSocket();
    
    //Load the scene model
    viewer->setScene(viewer->file_name);

    osg::Group* rootnode;

    rootnode = viewer->getRootNode();
    if (!rootnode)
    {
        return -1;
    }  

    viewer->initPerspective();  //initialize the perspective
    viewer->startDataTransfer();
    
viewer->setCamera(osg::Vec3(0,0,1),osg::Vec3(0,1,0),osg::Vec3(-1,0,0),osg::Vec3(0,0,1));

    while( !viewer->done() )
    {
        viewer->frame();        
    }

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=35932#35932





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

Reply via email to