left-icon

Direct2D Succinctly®
by Chris Rose

Previous
Chapter

of
A
A
A

CHAPTER 16

Starting a Direct3D Project

Starting a Direct3D Project


To begin a new Direct3D app, click File > New Project in the main menu of Visual Studio. You will be presented with the New Project screen. Click Visual C++ on the left panel, and then click Direct3D App on the middle panel. Give your new project a name. Mine is called Direct3DTesting, as shown in Figure 41.

Creating a Direct3D App

  1. Creating a Direct3D App

Once Visual Studio has created the project you can click Start Debugging and you should see a spinning colored cube (as depicted in the preview pane of Figure 41).

Terms and Concepts

3-D Coordinates

We will describe points in our 3-D examples using a standard Cartesian x, y, and z system. Each of the x, y, and z values refers to a point in 3-D space. Each axis can be thought of as an infinite plane perpendicular to the other two axes. They are often summarized as three lines, as shown in Figure 42.

3-D Axes

We will use the x value of a coordinate to represent how far left or right a point is, the y value to represent how high or low the coordinate is, and the z value to represent how far into or out of the screen the coordinate is. In addition, as an object's x value increases, the object moves rightward. As the object's y value increases, it moves upward. As the object's z value increases, the object moves closer to the camera (or out of the screen).

Vertices

A vertex is a point in 3-D space used to represent the corner of an object, shape, or the end of a line. To specify a 3-D vertex, we need to supply the three coordinates mentioned previously. The coordinates are almost always 32-bit floating point values. Each element (x, y, or z) specifies a position along the dimension, and collectively they describe an exact and unique point in 3-D space.

Note: I will be using x, y, then z as the order for my elements when describing vertices. So something like (9.0f, 8.0f, 5.0f) means 9 along the x-axis, 8 along the y-axis and 5 along the z-axis.

In Figure 43 the yellow ball represents a vertex. In reality, the vertex does not have a physical form; it represents an infinitely small point. The vertex is at position (1.2f, 0.4f, 0.7f). This means it is 1.2 units right of the blue x-axis origin, 0.4 units above the origin of the green y-axis, and 0.7 units away from the origin of the red z-axis.

A Point

In Direct3D, vertices are far more flexible than simple points in space. A vertex can carry lighting and coloring information about a point, as well as any other information required. In their most basic form (and the way we will be using them, they consist of a position and color, each described with three or four floating point values.

Lines

A 3-D line can be formed from any two vertices. They are exactly the same as lines in 2-D space, only the points which define the ends each have 3 dimensions. Lines are important in DirectX, because three of them makes a triangle (and as we shall see, 3-D graphics is almost nothing but rendering massive numbers of triangles). Lines also allow us to render 3-D objects as wire frames, so we can easily see the triangles from which the objects are made.

Triangle

Instead of describing 3-D objects with billions of points, objects are usually summarized and are described as a collection of small triangles. The triangles collectively form a mesh, which is a net-like structure. Each triangle is made up of three vertices and three lines. Any three distinct vertices can be used to form a triangle, and if there are enough triangles almost any imaginable shape can be approximated. Modern graphics cards are staggeringly efficient at rendering triangles.

Matrices

Everything from scaling, placement, and the rotation of objects is controlled by matrices in Direct3D. Displaying 3-D graphics consists of multiplying large data sets of vertices and triangles by transformation matrices. There are some matrices which are almost always used; they have a special purpose in 3-D graphics and they have come to be known as the world matrix, the view matrix, and the projection matrix.

  • World Matrix: When we define objects in 3-D, we usually define them individually with their own origins, scale, and rotation. For instance, when we create a model using a 3-D modeling program, we will probably use the origin and define the model with respect to its own local coordinates. When the model is added to a virtual 3-D world, it will probably not be placed at the origin. Maybe it is moving around in the virtual world. It has its own coordinate system, but when we place it into a scene these coordinates must be translated to world space. That is, the position in the world that the object resides. The world matrix performs this operation.
  • View Matrix: Once the world matrix has positioned all the objects that may (or may not) need to be rendered, we have to position an eye or camera in the scene. By placing a camera into the scene, we are defining another origin of sorts. The world matrix with all of its objects must be rotated, scaled, and translated to appear as though the camera has been placed at some point among the 3-D objects, and is looking at the virtual world. The view matrix accomplishes this operation.
  • Projection Matrix: Once the world and its 3-D objects are positioned with respect to some camera, the whole scene can be translated from 3-D coordinates and color vectors to pixels to be displayed on a 2-D monitor. This involves working out which objects appear in front of other objects with respect to the camera, which objects are too near or behind the camera to see, and which objects are too far away. The projection matrix is the final matrix involved in turning a scene into pixels.
Scroll To Top
Disclaimer
DISCLAIMER: Web reader is currently in beta. Please report any issues through our support system. PDF and Kindle format files are also available for download.

Previous

Next



You are one step away from downloading ebooks from the Succinctly® series premier collection!
A confirmation has been sent to your email address. Please check and confirm your email subscription to complete the download.