Orthographic Cameras

May 14, 2010 at 7:10 PM

Are there plans to add support for orthographic cameras, as well as perspective cameras?

May 14, 2010 at 10:00 PM
Edited May 14, 2010 at 10:00 PM

Yes, orthographic cameras should be supported, but there are a few other camera features I would like to add first (zoom to extents of model, rotate around a point that is not at the center of the view). Does anyone know how to do this?

May 14, 2010 at 10:07 PM

I added this to the issue tracker.

May 14, 2010 at 11:56 PM
objo wrote:

 (zoom to extents of model, rotate around a point that is not at the center of the view). Does anyone know how to do this?

For zooming to extents, it depends on whether you're orthographic or perspective.  

In orthographic, you just set the camera's width to be wide enough to encompass the bounding box.  

Perspective is a bit trickier.  For this, you need the radius of a bounding sphere, and the camera's field of view.  Basically, you just position the camera so that its at a distance (from the bounding sphere's center):

double cameraDistanceToWorld = worldBoundsRadius / Math.Sin(camera.FieldOfView * Math.PI / 360.0d);


For rotating around a point not at center, the main issue is that you need to track the rotation point separate from the camera itself.  Right now, you're not rotating around the center of the model, but rather the point defined by the end of the look vector...  To rotate around an arbitrary point, you'd need to track the rotation point.  That being said, I'm not sure this is a good idea - it wouldn't behave like a standard trackball at this point, but rather have some very odd behavior...

May 16, 2010 at 8:37 PM
Edited May 16, 2010 at 8:39 PM

Thanks for your suggestions - I was thinking to implement zoom to extents using the 2D bounding box (see Eric Sink's blog post), but I can try the bounding sphere first. I will assume the center of the bounding sphere is the current camera target point. And maybe use the Visual3D.Bounds property (which is cached), even if it will not give the minimum bounding sphere?

The rotation around a point which is not in the center of the view is a behaviour I see in Google Earth and many CAD/modelling programs - the point where you press down the mouse button is used as the center of the rotation. Maybe this needs a special camera that derives from MatrixCamera? I tried changing both Position and Direction of the ProjectionCamera at the same time, but that solution was not very stable...

May 17, 2010 at 6:28 PM

I'd avoid the 2D bounding box approach, at least as specified in that post.  It goes through the entire world, and requires checking every single point's location.  That's going to be pretty horribly slow, especially once you add the visual transform checks to world space (his current implementation in that post won't work if you have transforms on your objects...)

You should be able to use the Visual3D.Bounds property directly.  Just use the center of the bounds as the center point, and 1/2 the bounds diagonal length as a radius, and you'll get a pretty decent implementation.  It might, in some cases, be zoomed out slightly more than necessary (since the minimum bounding sphere could be smaller than the bounding box), but it should be pretty decent, and it's very fast - for any size model.



Aug 4, 2010 at 10:56 PM

The CameraController and HelixView3D controls now support orthographic cameras.