Hi,

I've been able to setup a HUD via a slave camera in my app to draw a cross that 
would always face the user. Since I wanted that cross to be able to "move" 
across all the scene, I did the setup of the slave as the following:


Code:

    osg::ref_ptr<osg::Camera> hud = new osg::Camera;
    hud->setCullMask( HUD_CAM );
    hud->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
    hud->setClearMask( GL_DEPTH_BUFFER_BIT /*| GL_COLOR_BUFFER_BIT*/ );
    hud->setRenderOrder( osg::Camera::POST_RENDER );
    hud->setAllowEventFocus( false );

    osgViewer::Viewer::Windows windows;
    getWindows( windows );
    hud->setGraphicsContext( windows.front() );
    hud->setClearColor( osg::Vec4d( 0.0, 1.0, 0.0, 1.0 ) );
    hud->getOrCreateStateSet()->setMode( GL_DEPTH, osg::StateAttribute::OFF );




Please, correct me if I'm wrong: it's my understanding that if I use the same 
graphics context as the master camera, the slave camera's scene will be 
rendered in the same "window" as the main camera, whereas if I use a new 
graphics context, a new window will appear with the slave's scene (I tried this 
with the Cookbook power wall example).

Now, for the projection matrix:


Code:

    osg::observer_ptr<osg::Camera> cam = viewer.getCamera();
    osg::observer_ptr<osg::Viewport> vport = cam->getViewport();
    hud->setViewport( vport.get() );

    hud->setProjectionMatrix( osg::Matrix::ortho2D( vport->x(), vport->width(), 
vport->y(), vport->height() ) );




Specifying the same viewport as the master camera, I was able to move the cross 
all around the scene. I tried to specify a window, let's say:

Code:
 setViewport( 0, 0, 300, 300 )

 and the projection matrix:

Code:
setProjectionMatrix( osg::Matrix::ortho2D( 0, 300, 0, 300 ) );



This will make the cross appear only in that little window.

So!

I thought of adding the axes to the scene (as stated in my other  post 
(forum.openscenegraph.org/viewtopic.php?t=14088)). I want the axes to appear in 
a corner of the scene and to update them when I rotate the main scene. I don't 
want the axes to be zoomed or panned.


Code:

osg::ref_ptr<osg::Camera> slave = new osg::Camera;
slave->setGraphicsContext( viewer.getCamera()->getGraphicsContext() );
slave->setViewport( 0, 0, 300, 300 );
slave->setClearColor( osg::Vec4d(0.0,1.0,0.0,0.5) );
slave->setReferenceFrame( osg::Camera::ABSOLUTE_RF );




What I'm not sure is: 


1) Should the slave's render mode be PRE or POST?

2) How should I specify the projection matrix for this camera? I'm having a 
hard time to do this for the 3D axes.

3) Playing a bit with the viewport in 2D, I realized that if I move the master 
camera's child near the slave's "area", once ir crosses the "border" between 
them, the main model will disappear. If I want that everything that is rendered 
by the main camera to be able to appear as well in the slave's viewport when 
panning, what would the cull mask in this case?




NOTE: Both the master and slave cameras have their own cull mask. The nodes I 
add to the scene also have their node masks set accordingly to the camera that 
will host them.
... 

Thank you!

Cheers,
Andrés

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





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

Reply via email to