[osg-users] Projection matrix and inline or nested cameras

John Cummings jcummings2 at users.sf.net
Tue Mar 17 03:05:44 PDT 2009


Thank you both for your feedback. I have looked at the HUD example
before and I use a post-render camera for my own HUD-type display.
Unless I've missed something, that is the only kind of camera in the HUD
example.

As Guy suggested, here is the relative code section (the osgGroup() is a
group for this node):

Constructor()
{
   m_camera = new osg::Camera;
   osgGroup()->addChild(m_camera.get());

   m_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
   m_camera->setViewMatrix(osg::Matrix::identity());
   m_camera->setClearMask(0);
   m_camera->setRenderOrder(osg::Camera::NESTED_RENDER);

   osg::Geode* geode = new osg::Geode;
   m_camera->addChild(geode);
   geode->setCullingActive(false);

   // Geometry...
   // StateSet...

}

Update()
{
   m_camera->setProjectionMatrixAsOrtho2D(0.0, viewportWidth, 0.0,
viewportHeight);
   // Update geometry...
}


As is typical when finally sending a mail for help, I sure thought I had
tried this exact combination (suggested my Guy in his message).
Nonetheless, I believe this code will work for me. I'll have to check
when I go to work and plug it into the large scene graph, but it seems
to accomplish what I want in my smaller test setup. I knew I couldn't be
that far off from the right answer.

Thank you, I'll let you know how this ends up working.
John Cummings

Robert Osfield wrote:
> Hi John,
>
> An in scene graph osg::Camera is certainly the route you'd want to
> take, the osghud example is probably a good place to start.  You can
> assign your own Viewport to an scene graph osg::Camera, but if you
> don't it'll just inherit it's parent Camera's Viewport.  osg::Camera
> also allows you to control which of the frame buffer components to
> clear, if you don't want to clear anything just use
> camera->setClearMask(0);
>
> Robert.
>
> On Tue, Mar 17, 2009 at 7:31 AM, John Cummings
> <jcummings2 at users.sf.net <mailto:jcummings2 at users.sf.net>> wrote:
>
>     First, I'm using OSG 2.8.0
>
>     I'm have been porting an old application from a homegrown OpenGL
>     scene-graph to osg and I've come across an issue that I'm sure
>     there is
>     a way to handle, but I seem to be unable to locate just the right
>     combination of Camera, Drawables, etc.
>
>     While most of the old nodes are simply geometry nodes, some of them do
>     their own Projection before issuing geometry-type calls. I may want to
>     do this for a variety of reasons, including allowing finer grained
>     control of the depth buffer or simply covering over something that has
>     already been drawn. In my old OpenGL code, the render method for
>     one of
>     these problem  nodes may look something like:
>
>     void MyNode::Render()
>     {
>     glMatrixMode(GL_PROJECTION);
>     glPushMatrix();
>     glLoadIdentity();
>
>     // Then either:
>     glOrtho (...);
>     // or
>     gluPerspective(...);
>     // or
>     glFrustrum();
>
>     glMatrixMode(GL_MODELVIEW);
>
>     // begin, end, etc.
>
>     glMatrixMode(GL_PROJECTION);
>     glPopMatrix();
>     glMatrixMode(GL_MODELVIEW);
>
>     RenderChildren();
>     }
>
>     I've played with the Camera node and "NESTED_RENDER" seemed from its
>     name to be what I wanted. That is, I though I could simply attach an
>     osg::Camera node anywhere in my scene graph and it would act much like
>     my nodes above. I either didn't set the correct options or this is
>     not a
>     valid use of the Camera class.
>
>     I've also tried attaching a camera to the root node (more properly
>     I am
>     attaching it to the Scene data for my view). That works great for
>     things
>     like a HUD, but that doesn't quite seem right in this particular case.
>     For what it's worth "this particular case" is where I would like
>     to put
>     a viewport size quad over the viewport, which would cover effectively
>     cover up my ancestors but allow my children to be seen (I also thought
>     an osg::Billboard is what I might want, but that didn't seem to be
>     right
>     either). However, I've also wanted to do this same thing for sky
>     effects, etc. but have found clunky workarounds for most of the
>     other cases.
>
>     I then got to looking at the Drawable class and thought that
>     overloading
>     drawImplementation would be the best thing to do. However, that
>     doesn't
>     seem quite right. Perhaps it is after all.
>
>     So, I'm sure that I can do this in osg, I'm just not sure how. I'm
>     still
>     adjust my mind to the osg paradigm, so I've probably overlooked
>     something obvious, although I didn't see it when I search the mailing
>     list. In essence, I want to be able to do the same type of inline
>     projection I did before. What am I missing?
>
>     Thank you
>     John Cummings
>     _______________________________________________
>     osg-users mailing list
>     osg-users at lists.openscenegraph.org
>     <mailto:osg-users at lists.openscenegraph.org>
>     http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>




More information about the osg-users mailing list