IanG on Tap

Ian Griffiths in Weblog Form (RSS 2.0)

Blog Navigation

April (2018)

(1 item)

August (2014)

(1 item)

July (2014)

(5 items)

April (2014)

(1 item)

March (2014)

(1 item)

January (2014)

(2 items)

November (2013)

(2 items)

July (2013)

(4 items)

April (2013)

(1 item)

February (2013)

(6 items)

September (2011)

(2 items)

November (2010)

(4 items)

September (2010)

(1 item)

August (2010)

(4 items)

July (2010)

(2 items)

September (2009)

(1 item)

June (2009)

(1 item)

April (2009)

(1 item)

November (2008)

(1 item)

October (2008)

(1 item)

September (2008)

(1 item)

July (2008)

(1 item)

June (2008)

(1 item)

May (2008)

(2 items)

April (2008)

(2 items)

March (2008)

(5 items)

January (2008)

(3 items)

December (2007)

(1 item)

November (2007)

(1 item)

October (2007)

(1 item)

September (2007)

(3 items)

August (2007)

(1 item)

July (2007)

(1 item)

June (2007)

(2 items)

May (2007)

(8 items)

April (2007)

(2 items)

March (2007)

(7 items)

February (2007)

(2 items)

January (2007)

(2 items)

November (2006)

(1 item)

October (2006)

(2 items)

September (2006)

(1 item)

June (2006)

(2 items)

May (2006)

(4 items)

April (2006)

(1 item)

March (2006)

(5 items)

January (2006)

(1 item)

December (2005)

(3 items)

November (2005)

(2 items)

October (2005)

(2 items)

September (2005)

(8 items)

August (2005)

(7 items)

June (2005)

(3 items)

May (2005)

(7 items)

April (2005)

(6 items)

March (2005)

(1 item)

February (2005)

(2 items)

January (2005)

(5 items)

December (2004)

(5 items)

November (2004)

(7 items)

October (2004)

(3 items)

September (2004)

(7 items)

August (2004)

(16 items)

July (2004)

(10 items)

June (2004)

(27 items)

May (2004)

(15 items)

April (2004)

(15 items)

March (2004)

(13 items)

February (2004)

(16 items)

January (2004)

(15 items)

Blog Home

RSS 2.0

Writing

Programming C# 5.0

Programming WPF

Other Sites

Interact Software

OrthographicCamera and PerspectiveCamera - 3D Projections in WPF (aka Avalon)

Wednesday 10 August, 2005, 09:44 AM

The WPF allows us to add 3D content to our user interfaces. (WPF == Windows Presentation Foundation. It'll take me a little while to get used to this new name for The Framework Formerly Known as Avalon.) Since computer screens can only display two-dimensional images, rendering 3D always involves using some kind of projection process to get rid of that pesky extra dimension.

WPF offers both orthographic and perspective projections. Orthographic projections are simpler - they effectively just remove one dimension. As a simple example of such a projection, you could decide where to draw a 3D point on the screen by ignoring the Z coordinate, drawing the points (10,5,100) and (10,5,50) at the same location on screen - (10,5). In the case where the plane you're projecting onto happens not to be aligned with your axes, the process isn't quite as simple as ignoring one of the three coordinates, but the net result is the same. (You could do it by rotating the world so that your target plane is aligned with your axes, setting one of the coordinates to zero, then rotating back.)

Orthographic projections preserve certain characteristics of the original 3D model that may be useful. Parallel lines continue to be parallel after the projection. 3D objects of the same size, shape, and orientation will be rendered as having the same size, shape, and orientation.

The downside of orthographic projections is that they look somewhat unrealistic. Let's look at an example:

Orthographic and perspective projections

This image shows two different projections used to render the same scene - some dominoes on a checkerboard floor. On the left, we see an orthographic projection in action. Each domino is the same shape and size, and the squares on the floor are uniform.

Although this is a faithful representation of uniformity that is present in the 3D scene, it's not how such a scene would look to us in practice. Things that are far away look smaller than things that are nearby. This means it's inappropriate for the dominoes all to be rendered at the same size.

The image on the right hand side uses a perspective projection, which takes this effect into account. The domino at the back is considerably smaller than the one at the front. The squares on the floor become smaller in the distance. As a side-effect of this, parallel lines, such as those formed by the floor tiles, are not drawn parallel on the screen. This is consistent with what happens to parallel lines when you take a photograph with a normal camera. In this particular example the effect is somewhat exaggerated because the image was rendered with a fairly wide field of view - this is analogous to using a wide angle camera lens, which always tends to emphasize the effects of perspective. Such distortions always occur when using a camera, we just tend not to notice them because it's how things always look - I've inflated their effects here in order to make them more obvious.

Both styles of projection have pros and cons. The orthographic projection's preservation of certain characteristics can be useful for some kinds of diagrams. For example, when plotting 3D mathematical functions on a graph, it might be easier to read the graph accurately if we avoid the distorting effects of perspective. For applications where precision is less of an issue than the visual impression, the more natural look of a perspective transform is preferable. This is why the WPF offers both the OrthographicCamera and the PerspectiveCamera.

Copyright © 2002-2024, Interact Software Ltd. Content by Ian Griffiths. Please direct all Web site inquiries to webmaster@interact-sw.co.uk