1

I have an orthographic camera in an osg scene. There are flat objects (planes) which will be displayed in that scene, and I want to be able to have the camera automatically point at them to as to view them head-on, and also to be zoomed to show as much of the plane as possible without chopping off any edges.

So far I've oriented myself correctly to look at the plane:

        osg::Vec3d eye; // dummy
        osg::Vec3d center; // we only really care about this here
        osg::Vec3d up; // dummy

        cameraManipulator->getViewMatrixAsLookAt(eye, center, up);

        osg::Vec3d desiredVec(velocityX, velocityY, velocityZ); // velocity of the plane I want to look at

        desiredVec.normalize();
        desiredVec = -desiredVec; // invert
        desiredVec += center; // align

        cameraManipulator->setViewMatrixAsLookAt(desiredVec, center, osg::Vec3d(0, 0, -1));

This positions me so that I'm viewing the plane head-on, but it's zoomed in way too far, so I think what I need to do is offset my camera back a bit along the velocity vector by some value, and I don't know how to calculate that value. Something like this:

            osg::Vec3d dir = desiredVec - center; // the direction (vector) in which we want to move

            dir.normalize();

            double scaleFactor = (width * height) / 2; // test

            desiredVec += (dir * scaleFactor); // add it to desiredVec to move back in that direction (by scaleFactor)

The scaleFactor "test" stuff seems to work ok, it produces a view of the plane with a margin around the edge. I imagine this is what needs to change.

Basically, how do I calculate the distance I need to move the camera back by in order to view all of the current plane? I have information about the plane's velocity, size etc.

Touchdown
  • 494
  • 4
  • 19
  • this is done for a perspective camera but might give you some insights - https://stackoverflow.com/questions/25410044/convert-a-bounding-box-in-ecef-coordinates-to-enu-coordinates – sn710 Mar 15 '19 at 08:18

1 Answers1

0

When using an orthographic camera, the size of the rendered objects (zoom effect) is not achieved by moving the camera, but by the size of the projection frustum you set on the camera. None of the OSG camera manipulators implements a zooming effect for an ortho camera. See this forum topic as a reference: http://forum.openscenegraph.org/viewtopic.php?t=10763&view=next

rickyviking
  • 846
  • 6
  • 17
  • So would a perspective camera be a better option? The only reason I picked ortho was because I thought it'd be simpler since all I want to display is a 2D plane. – Touchdown Mar 13 '19 at 12:41
  • Perspective and ortho cameras give a completely different result, so that's up to what you want to achieve. They cannot be used interchangeably. – rickyviking Mar 13 '19 at 13:38