Hi Akilan,

it is the camera manipulator that resets the position of the main camera.
Have a look at osghud example how to set up screen aligned views
-Nick


On Fri, Mar 26, 2010 at 12:56 PM, Akilan Thangamani <
[email protected]> wrote:

> Hi Nick
>
> Find my code below to compile,
>
>
> Code:
>
>
> #include <osg/Node>
> #include <osg/Geometry>
> #include <osg/Notify>
> #include <osg/MatrixTransform>
> #include <osg/Texture2D>
> #include <osg/DrawPixels>
> #include <osg/PolygonOffset>
> #include <osg/Geode>
> #include <osgDB/Registry>
> #include <osgDB/ReadFile>
> #include <osgText/Text>
> #include <osgViewer/Viewer>
> #include <osgViewer/CompositeViewer>
> #include <osgViewer/ViewerEventHandlers>
> #include <osgGA/StateSetManipulator>
> #include <osgGA/TrackballManipulator>
> #include <iostream.h>
>
> #undef MULTI_SCREEN
>
> #define NUM_CAMERA  1
> #define NUM_SCREEN      1
>
>
> unsigned char  *buf_1, *buf_2, *buf_3, *buf_4;
> int buf_width=1920, buf_height=1200;
> unsigned int numCameras = NUM_CAMERA;
> unsigned int numScreens = NUM_SCREEN;
>
>
> int width=1920 * NUM_SCREEN;
> int height=1200;
> int read_off=0;
>
>
> osg::ref_ptr<osg::Image> image;
> osg::Texture2D *texture[4];
> osg::Geometry  *geom[4];
>
>
>
> void initRead(char* fname, int w, int h)
> {
>        buf_1=new unsigned char[buf_width * buf_height];
>        buf_2=new unsigned char[buf_width * buf_height];
>        buf_3=new unsigned char[buf_width * buf_height];
>        buf_4=new unsigned char[buf_width * buf_height];
>
>        memset((unsigned char*)buf_1,(unsigned char)128,buf_width *
> buf_height);
>        memset((unsigned char*)buf_2,(unsigned char)160,buf_width *
> buf_height);
>        memset((unsigned char*)buf_3,(unsigned char)180,buf_width *
> buf_height);
>        memset((unsigned char*)buf_4,(unsigned char)200,buf_width *
> buf_height);
> }
>
> osg::Node* createTex(int index, unsigned char* buf)
> {
>    osg::Group* group=new osg::Group;
>
>        osg::Vec3 top_left(0.0f ,0.0f ,height);
>    osg::Vec3 bottom_left(0.0f ,0.0f ,0.0f);
>    osg::Vec3 bottom_right(width ,0.0f, 0.0f);
>    osg::Vec3 top_right(width, 0.0f, height);
>
>    geom[index] = new osg::Geometry;
>
>
>    osg::Vec3Array* vertices = new osg::Vec3Array(4);
>    (*vertices)[0] = top_left;
>    (*vertices)[1] = bottom_left;
>    (*vertices)[2] = bottom_right;
>    (*vertices)[3] = top_right;
>    geom[index]->setVertexArray(vertices);
>
>
>    osg::Vec2Array* texcoords = new osg::Vec2Array(4);
>
>    (*texcoords)[0].set(0.0f,1.0f);
>    (*texcoords)[1].set(0.0f,0.0f);
>    (*texcoords)[2].set(1.0f,0.0f);
>    (*texcoords)[3].set(1.0f,1.0f);
>
>    geom[index]->setTexCoordArray(0,texcoords);
>
>    osg::Vec3Array* normals = new osg::Vec3Array(1);
>    (*normals)[0].set(1.0f,0.0f,0.0f);
>    geom[index]->setNormalArray(normals);
>    geom[index]->setNormalBinding(osg::Geometry::BIND_OVERALL);
>
>    osg::Vec4Array* colors = new osg::Vec4Array(1);
>    (*colors)[0].set(1.0f,1.0f,1.0f,1.0f);
>    geom[index]->setColorArray(colors);
>    geom[index]->setColorBinding(osg::Geometry::BIND_OVERALL);
>
>    geom[index]->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
>
>    osg::Geode* geom_geode = new osg::Geode;
>    geom_geode->addDrawable(geom[index]);
>
>
>    texture[index] = new osg::Texture2D;
>    texture[index]->setName("TEXTURE");
>    texture[index]->setDataVariance(osg::Object::DYNAMIC); // protect from
> being optimized away as static state.
>    texture[index]->setResizeNonPowerOfTwoHint(false);
>
>    // Setting buffer
>    image = new osg::Image;
>    image->setName("BUFFER");
>    image->setOrigin(osg::Image::BOTTOM_LEFT);
>    image->setImage(buf_width, buf_height, 1, GL_LUMINANCE, GL_LUMINANCE,
> GL_UNSIGNED_BYTE,buf, osg::Image::NO_DELETE);
>
>    texture[index]->setImage(image);
>
>
>    osg::StateSet* stateset = geom[index]->getOrCreateStateSet();
>
>  
> stateset->setTextureAttributeAndModes(0,texture[index],osg::StateAttribute::ON);
>    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
>
>    group->addChild(geom_geode);
>
>    return group;
> }
>
> void setView(osgViewer::View* view, int screen_no)
> {
>
>            double aspectRatioScale = 1.0;
>        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
> osg::GraphicsContext::Traits;
>            traits->screenNum =  screen_no;
>        traits->x = (screen_no*width)/numCameras;
>        traits->y = 0;
>        traits->width = width/numCameras-1;
>        traits->height = height;
>        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, width/numCameras,
> height));
>
>
>  camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1920,0,1200));
>                 camera->setViewMatrix(osg::Matrix::identity());
>                camera->setClearMask(GL_DEPTH_BUFFER_BIT);
>
>        GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
>        camera->setDrawBuffer(buffer);
>        camera->setReadBuffer(buffer);
>         view->addSlave(camera.get(), osg::Matrix::scale(aspectRatioScale,
> 1.0, 1.0)*osg::Matrix::translate(0.0, 0.0, 0.0), osg::Matrix() );
> }
>
> int main(int , char **)
> {
>    osgViewer::CompositeViewer viewer;
>
>        osg::Group* root=new osg::Group;
>
>        osgGA::TrackballManipulator*    tm=new osgGA::TrackballManipulator;
>        // Screen-1
>         {
>            osg::Group* scene=new osg::Group;
>             scene->addChild(createTex(0,buf_1));
>
>            osgViewer::View* view = new osgViewer::View;
>         view->setName("View-1");
>         view->setSceneData(scene);
>            setView(view, 0);
>
>            view->setCameraManipulator(tm);
>            viewer.addView(view);
>        }
> #ifdef MULTI_SCREEN
>        // Screen-2
>         {
>            osg::Group* scene=new osg::Group;
>             scene->addChild(createTex(1,buf_2));
>
>            osgViewer::View* view = new osgViewer::View;
>         view->setName("View-2");
>         view->setSceneData(scene);
>            setView(view, 1);
>
>            view->setCameraManipulator(tm);
>            viewer.addView(view);
>        }
>         // Screen-3
>         {
>            osg::Group* scene=new osg::Group;
>             scene->addChild(createTex(2,buf_3));
>
>            osgViewer::View* view = new osgViewer::View;
>         view->setName("View-3");
>         view->setSceneData(scene);
>            setView(view, 2);
>
>            view->setCameraManipulator(tm);
>            viewer.addView(view);
>        }
>
>         // Screen-4
>         {
>            osg::Group* scene=new osg::Group;
>             scene->addChild(createTex(3,buf_4));
>
>            osgViewer::View* view = new osgViewer::View;
>         view->setName("View-4");
>         view->setSceneData(scene);
>            setView(view,  3);
>
>            view->setCameraManipulator(tm);
>            viewer.addView(view);
>        }
> #endif
>
>  
> viewer.setThreadingModel(osgViewer::CompositeViewer::CullDrawThreadPerContext);
>
>        viewer.realize();
>        while(!viewer.done()){
>                viewer.frame();
>        }
>
>        delete [] buf_1;
>        delete [] buf_2;
>        delete [] buf_3;
>        delete [] buf_4;
>
>        return 0;
> }
>
>
>
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=26184#26184
>
>
>
>
>
> _______________________________________________
> 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