[osg-users] Setting a camera view frustum

Bob Balfour bob at BAL4.com
Sun Jun 22 17:57:10 PDT 2008


I need to set up a specific calibrated view frustum, and I need to be 
sure I'm doing it right in OSG, as I've gotten a bit confused and my OGL 
matrix math is a bit rusty!

The frustum is predefined by:
1. LeftAngle, RightAngle, TopAngle, BottomAngle of the frustum.
2. A set of rotations (defined as Euler angles) on the frustum:
    ViewAngleA (first rotation about the z axis**)
    ViewAngleB (second rotation about the y axis**)
    ViewAngleC (final rotation about the x axis**)
3. A translation: Xoffset, Yoffset, Zoffset of the viewpt of the frustum.

**Note that the axes are defined to be: +x to the right, +y up, -z into 
the screen (the same as OGL? but different than the OSG camera 
manipulators?)

The sample OpenGL code I have tells me to do the following with this info:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(   near*tan(DegreesToRad*LeftAngle),
                   near*tan(DegreesToRad*RightAngle),
                   near*tan(DegreesToRad*BottomAngle),
                   near*tan(DegreesToRad*TopAngle),
                   near,far);
glRotated(ViewAngleA, 0.0, 0.0, 1.0);
glRotated(ViewAngleB, 0.0, 1.0, 0.0);
glRotated(ViewAngleC, 1.0, 0.0, 0.0);
glTranslated(Xoffset, Yoffset, Zoffset);
-----------------------------------------------------------

Now to do this with an OSG::camera I'm not sure what to do about 
matching up the axis orientation, if anything (the OSG manipulators and 
my models work with +z up, +x easting, +y northing, or is that just wrt 
the modelview matrix and nothing to do with the projection matrix?), use 
preMult, postMult, makeRotate, etc? ...

I have some OSG code that looks like below, but I'm not sure it's doing 
it right (it just mimicks the OGL code with OSG methods):

osg::Matrixd mat;
mat.makeIdentity();
mat.preMult(osg::Matrixd::frustum(
                                                    
near*tan(DEG_TO_RAD*LeftAngle),
                                                    
near*tan(DEG_TO_RAD*RightAngle),
                                                    
near*tan(DEG_TO_RAD*BottomAngle),
                                                    
near*tan(DEG_TO_RAD*TopAngle),
                                                    near,far) );
mat.preMult(osg::Matrixd::rotate(DEG_TO_RAD*ViewAngleA, 0.0, 0.0, 1.0);
mat.preMult(osg::Matrixd::rotate(DEG_TO_RAD*ViewAngleB, 0.0, 1.0, 0.0);
mat.preMult(osg::Matrixd::rotate(DEG_TO_RAD*ViewAngleC, 1.0, 0.0, 0.0);
mat.preMult(osg::Matrixd::translate(Xoffset, Yoffset, Zoffset);
camera->setProjectionMatrix(mat);
------------------------------------------------------------------------

Advice/suggestions from anyone more proficient in this would be 
appreciated...

Thanks.

Bob.
-- 

Robert E. Balfour, Ph.D.
Exec. V.P. & CTO,  BALFOUR Technologies LLC
960 So. Broadway, Suite 108, Hicksville NY 11801
Phone: (516)513-0030  Fax: (516)513-0027  email: bob at BAL4.com
/"Solutions in four dimensions" with *fourDscape*®/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080622/c2fff175/attachment.htm>


More information about the osg-users mailing list