Hi Robert and osgUsers,
I have modified my code in order to use 2 Camera Node but the problem is the
same. I have used an osg::Camera in order to render some text in screen with
ortho2D projection with resolution 1600x1200. When I attach, as a child, a
new camera node (with viewport sets as a rectangle of 100x100) dimension is
refering to Default projection (Monitor resolution, in my case 1280x800)
not in resolution that I have specified in parent Camera Node.
In attach there is an example of what I mean
Thank you very much
Carlo

2006/12/14, Carlo Camporesi <[EMAIL PROTECTED]>:

Hi Robert,
Thank you for your suggestion.
Carlo

2006/12/14, Robert Osfield <[EMAIL PROTECTED]>:
>
> Hi Alberto,
>
> On 12/14/06, Alberto Luaces <[EMAIL PROTECTED]> wrote:
> > Is osg::Camera only available on CVS? Here on OSG 1.2 I can only find
> > Producer::Camera and osg::CameraNode
>
> In CVS osg::CameraNode has been simply renamed osg::Camera, there now
> a typedef from Camera to CameraNode so old code work without any
> changes.
>
> Robert.
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://openscenegraph.net/mailman/listinfo/osg-users
> http://www.openscenegraph.org/
>


/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 
 *
 * This library is open source and may be redistributed and/or modified under  
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 * OpenSceneGraph Public License for more details.
*/

#include <osgUtil/Optimizer>
#include <osgDB/ReadFile>
#include <osgProducer/Viewer>

#include <osg/Material>
#include <osg/Geode>
#include <osg/BlendFunc>
#include <osg/Depth>
#include <osg/Projection>
#include <osg/PolygonOffset>
#include <osg/MatrixTransform>
#include <osg/Camera>
#include <osg/FrontFace>

#include <osgText/Text>


osg::Node* createRearView(osg::Node* subgraph, const osg::Vec4& clearColour)
{
    osg::Camera* camera = new osg::Camera;

        osg::Vec3 centermodel = subgraph->getBound().center();

        osg::Vec3 center(centermodel.x(), centermodel.y(), centermodel.z() -90);
        osg::Vec3 eye(center.x(), center.y(), center.z()  -100);
        osg::Vec3 up(0.0,-1.0,0.0);

    // set the viewport
    camera->setViewport(10,10,400,300);


    // set the view matrix
    camera->setCullingActive(false);    
    camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    camera->setTransformOrder(osg::Camera::POST_MULTIPLY);

    //camera->setProjectionMatrix(osg::Matrixd::scale(-1.0f,1.0f,1.0f));
    
//camera->setViewMatrix(osg::Matrixd::rotate(osg::inDegrees(180.0f),0.0f,1.0f,0.0f));
        camera->setViewMatrixAsLookAt(eye, center, up);
        camera->setProjectionMatrixAsFrustum(-100,100,-100,100,-1000,1000);

    // set clear the color and depth buffer
    camera->setClearColor(clearColour);
    camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    // draw subgraph after main camera view.
    camera->setRenderOrder(osg::Camera::POST_RENDER);

    // add the subgraph to draw.
    camera->addChild(subgraph);
    
    // switch of back face culling as we've swapped over the projection matrix 
making back faces become front faces.
    camera->getOrCreateStateSet()->setAttribute(new 
osg::FrontFace(osg::FrontFace::CLOCKWISE));
    
    return camera;
}

int main( int argc, char **argv )
{

    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);
    
    // set up the usage document, in case we need to print out how to use this 
program.
    
arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+"
 is the example which demonstrates how to do Head Up Displays.");
    
arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+"
 [options] [filename] ...");
    arguments.getApplicationUsage()->addCommandLineOption("-h or 
--help","Display this information");
    

    // construct the viewer.
    osgProducer::Viewer viewer(arguments);

    // set up the value with sensible default event handlers.
    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);

    // get details on keyboard and mouse bindings used by the viewer.
    viewer.getUsage(*arguments.getApplicationUsage());

    // if user request help write it out to cout.
    if (arguments.read("-h") || arguments.read("--help"))
    {
        arguments.getApplicationUsage()->write(std::cout);
        return 1;
    }

    // any option left unread are converted into errors to write out later.
    arguments.reportRemainingOptionsAsUnrecognized();

    // report any errors if they have occured when parsing the program aguments.
    if (arguments.errors())
    {
        arguments.writeErrorMessages(std::cout);
        return 1;
    }
    
    // read the scene from the list of file specified commandline args.
    osg::ref_ptr<osg::Node> scene = osgDB::readNodeFiles(arguments);

    osg::ref_ptr<osg::Group> group  = new osg::Group;
    
    // add the HUD subgraph.    
    if (scene.valid()) group->addChild(scene.get());

    osg::Vec4 colour =  viewer.getClearColor();
    colour.r() *= 0.5f;
    colour.g() *= 0.5f;
    colour.b() *= 0.5f;



//INIT - EXAMPLE CODE: camera 1
        osg::Camera* cam = new osg::Camera;

        cam->setProjectionMatrixAsOrtho2D(0, 1600, 0, 1200);  //I'm setting 
Projection To 1600x1200
        cam->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
    cam->setViewMatrix( osg::Matrix::identity() );
    cam->setRenderOrder( osg::Camera::POST_RENDER );
    cam->setClearMask( GL_DEPTH_BUFFER_BIT );

//EXAMPLE CODE: camera 2
        osg::Camera* camera = new osg::Camera;

        osg::Vec3 centermodel = scene.get()->getBound().center();

        osg::Vec3 center(centermodel.x(), centermodel.y(), centermodel.z() -90);
        osg::Vec3 eye(center.x(), center.y(), center.z()  -100);
        osg::Vec3 up(0.0,-1.0,0.0);

    // set the viewport
    camera->setViewport(0,0,100,100); //I'm setting the Viewport (THESE 
coordinates live in monitor resolution not in 1600x1200)

    // set the view matrix
    camera->setCullingActive(false);    
    camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    camera->setTransformOrder(osg::Camera::POST_MULTIPLY);
        camera->setViewMatrixAsLookAt(eye, center, up);
        camera->setProjectionMatrixAsFrustum(-100,100,-100,100,-1000,1000);

    // set clear the color and depth buffer
    camera->setClearColor(colour);
    camera->setClearMask(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    // draw subgraph after main camera view.
    camera->setRenderOrder(osg::Camera::POST_RENDER);

    // add the subgraph to draw.
    camera->addChild(scene.get());

        //add Camera in Camera
        cam->addChild(camera);
        
        osg::ref_ptr<osg::Geode> geode = new osg::Geode();
        osg::ref_ptr<osgText::Text> text = new  osgText::Text; //This text 
lives in 1600x1200
        
        osg::StateSet* stateset = geode->getOrCreateStateSet();
    stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
    stateset->setMode( GL_DEPTH_TEST,osg::StateAttribute::OFF );
    
        geode->setName( "Label Message" );
    cam->addChild( geode.get() );
        
    geode->addDrawable( text.get() );
        
    text->setFont( "Arial.ttf" );
    text->setText( "TEXTTTTTTTTTT" );
        text->setPosition( osg::Vec3(20.0f, 600.0f, 0.0f) );
        text->setCharacterSize( 30.0f );


    // note tone down the normal back ground colour to make it obvious that 
there is a seperate camera inserted.
    group->addChild(cam);

//END - EXAMPLE CODE

    // set the scene to render
    viewer.setSceneData(group.get());

    // create the windows and run the threads.
    viewer.realize();

    while( !viewer.done() )
    {
        // wait for all cull and draw threads to complete.
        viewer.sync();

        // update the scene by traversing it with the the update visitor which 
will
        // call all node update callbacks and animations.
        viewer.update();
         
        // fire off the cull and draw traversals of the scene.
        viewer.frame();
        
    }
    
    // wait for all cull and draw threads to complete.
    viewer.sync();

    // run a clean up frame to delete all OpenGL objects.
    viewer.cleanup_frame();

    // wait for all the clean up frame to complete.
    viewer.sync();
    
    return 0;
}
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to