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

John Cummings jcummings2 at users.sf.net
Tue Mar 17 00:31:38 PDT 2009


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



More information about the osg-users mailing list