15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1032 ❘ ChaPTer 35 cOre wpf<br />

Cameras<br />

A camera is needed with a 3-D model to see something. The example uses the PerspectiveCamera that<br />

has a position <strong>and</strong> a direction to look into. Changing the camera position to the left moves the model to the<br />

right <strong>and</strong> vice versa. Changing the y position of the camera, the model appears larger or smaller. With this<br />

camera, the further away the model is, the smaller it becomes:<br />

<br />

<br />

<br />

code snippet 3DDemo/MainWindow.xaml<br />

WPF also has an OrtographicCamera that doesn’t have a horizon on the scene, so the size of the element<br />

doesn’t change if it is further away. With MatrixCamera, the behavior of the camera can be exactly<br />

specified.<br />

lights<br />

Without a light it is dark. A 3-D scene requires a light to make the model visible. There are different<br />

lights that can be used. The AmbientLight lights the scene uniformly. DirectionalLight is a light that<br />

shines in one direction, similar to sunlight. PointLight has a position in space <strong>and</strong> lights in all directions.<br />

SpotLight has a position as well but uses a cone for its lighting.<br />

The example code uses a SpotLight with a position, a direction, <strong>and</strong> cone angles:<br />

rotation<br />

<br />

<br />

<br />

<br />

<br />

To get a 3-D look from the model, it should be able to be rotated. For rotation, the RotateTransform3D<br />

element is used to define the center of the rotation <strong>and</strong> the rotation angle:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

To run a rotation from the completed model, an animation is started by an event trigger. The animation<br />

changes the Angle property of the AxisAngleRotation3D element continuously:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!