Graphics Reference
In-Depth Information
The scene is rendered to the display device via the pipeline represented at a
very high level in Figure 6.1. The camera is positioned in the modeled world using
world coordinates, and it is configured by specification of several parameters (e.g.,
field of view) that together describe a view volume —the pyramid-shaped object
shown in the middle subfigure. (You'll learn a great deal about camera specifica-
tion and view volumes in Chapter 13, and we'll examine the camera specification
from the OpenGL perspective in Chapter 16.) The portion of the scene captured
in the view volume is then projected to 2D, resulting in the rendering shown in the
viewport, which will appear in the application's window.
World
coordinate
system
Camera
setup
As is the case in WPF 2D, the platform automatically keeps the rendering in
sync with the modeled world. For example, making a change to the scene or to
the camera's configuration automatically causes an update to the rendering in the
viewport. Thus, animation is performed by editing the scene at runtime, perform-
ing actions such as the following:
• Adding or removing objects
• Changing the geometry of an object (e.g., editing its mesh specification)
• Transforming (e.g., scaling, rotating, or translating) objects, the camera, or
geometric (in-scene) light sources
• Changing the properties of a material
• Changing the characteristics of the camera or lights
Projection to
2D/transform
to viewport
6.2 Introducing Mesh and Lighting
Specification
In this section, we will use XAML to build a four-sided, solid-color pyramid,
depicted atop a sandy desert floor in Figure 6.2 from the point of view of a low-
flying helicopter. In this section, we focus on the construction and lighting of just
the pyramid (ignoring the sky and desert floor).
Figure 6.1: Very high-level
overview of WPF's 3D geometry
pipeline.
6.2.1 Planning the Scene
Let's assume our desert floor is coplanar with the xz ground plane of the right-
handed 3D coordinate system, as shown in Figure 6.3. To honor the great
Mesoamerican Pyramid of the Sun (75 meters in height) near Mexico City, we'll
give our pyramid that height, with a base of 100m 2 . As such, we'll choose meters
as our unit of measurement. We will place our pyramid so that its base is on the xz
ground plane, with its center located at the origin ( 0, 0, 0 ) , its four corners located
at (
±
50, 0,
±
50 ) , and its apex located at ( 0, 75, 0 ) .
6.2.1.1 Preparing a Viewport for Content
To be visible, the viewport must live inside a WPF 2D structure such as a window
or a canvas. For this example, we chose to use a WPF Page as the 2D container
for the viewport, as it simplifies the use of interpreted development environments
such as Kaxaml. Here we create a Page and populate it with a viewport of size
640
Figure
6.2:
Overhead
view
of
pyramid.
×
480 (measured in WPF canvas coordinates, as described in Chapter 2):
 
 
 
Search WWH ::




Custom Search