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-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Yeah, I also thought of the POST_RENDER camera, but I wanted another opinion :D
About the cull masks, I switched them off. I thought it would be more efficient using them, but that's not my main concern right now. The clear color was a just a test to see what the specified viewport was. I forgot to remove it from the posted code. Sorry.
Okay, about the perspective. I think the problem is my poor understanding of the math involved. I will have to start again with the theory.
Also, using an ABSOLUTE reference frame, the axis appear but with too much zoom; almost all of the viewport is filled with the red axis. And I think the callback is not working properly here, as I can see no change in the axis (with the compositeviewer example it worked, though).
Changind the RF to RELATIVE, the axes appear, but very very small. I have to zoom them in to get a suitable size. But I don't want to have any events in that viewport.
So, as I said before, I'll check the theory again. Besides the OpenGL Red Book, do you know of any link or book that may be useful?
...
Thank you!
Cheers,
Andrés
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60493#60493
thanks for your help. I'll check the info you gave me!
...
Thank you!
Cheers,
Andrés
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60520#60520