Hello,

   the math involved depends on whether the rectangle is perpendicular to
the camera view direction (no rotation needed) and if the projection is
either orthographic or perspective and if it is symmetric or not. In either
case you must take into account which edges of the rectangle you want to fit
with the view edges (in OSG i suppose this is what ProjectionResizePolicy is
meant for) if the rectangle aspect ratio (width by height) differ form the
camera. Your objectives in the algebra must be a new view matrix and a new
projection matrix (but i suppose you knew that already). With this two
matrix you can position the camera where you want.

   Supposing the simpler case (rectangle is perpendicular to view direction
and the symmetric orthographic projection), the center of the rectangle give
you the new center of the view matrix. If the camera have perspective
projection, make the new frustums near plane be your new rectangle.

  Once you have the new view matrix and the projection matrix, you can set
them to the camera with setViewMatrix and setProjectionMatrix.

   Of course, this is only a method, you can also orient your math to
compute the vector needed to use setViewMatrixAsLookAt. The eye vector will
be the rectangle's plane normal, the center can be computed with the
projection matrix of the camera and the up vector is just the cross product
(or the camera up vector, if it doesn't roll).

   A good reference of the model of a camera in 3D is Opengl Programmers
Guide (official OpenGL guide). OSG Camera class is just a thin wrapper about
opengl methods w.r.t. position and orientation.

  I think this will not help you much if you have problems with the math
methods involved but your problem is just such one. Is this is your case
(was mine a few months ago), take a good 3D math book (Allan Watts 3D
Computer Graphics for example), a heat coffee or tea and a lot of patience
until you understand perfectly 3d math algebra, or you will have problems in
the future (if you are working with 3d, of course). Please, don't
misunderstand my words. I think sooner or later we all have to read "the
avoided math chapter"...

   If you were asking if OSG has some method that can help you, i haven't
found one yet, but the right place to start looking for something similar
are the camera manipulator classes. Of course they have more algebra than
osg methods..

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

Reply via email to