CAP5937 - Realtime Graphics for Simulation and Games

Lecture 3: Introduction to Direct3D

J. Michael Moshell

Professor of Computer Science

Direct3D is part of the DirectX family of software resources that provide device independence for Microsoft Windows applications. This chapter provides a (rather jumbled) conceptual overview of Direct3D's components, without really telling you how to use them. But you gotta start somewhere, so let's go.

Read Chapter 3 and write down your answers these queries.

The text does not make a careful distinction between 'object' as in software (C++) object, and 'object' as a recognizable aggregaged chunk of graphics primitives (e. g. a cube.) So we will try to use the word 'object' for software and 'graphical object' for a visible thing, like a cube. But I bet that I will slip up, too.
COM - Component Object Model.

You can learn all about COM at http://www.microsoft.com/com/default.asp.

Query 3.1. The text points out that COM objects are not C++ objects, and vice versa. Develop some reasons why the system was designed in this manner. What is a "wrapper" and how does it make COM objects useful within an object oriented context?

Some Perspective on Direct3D

When you read Chapter 3 of the Trujillo text, you may get the feeling that the author is telling you all the details without really telling you what Direct3D is or does. So here it is in Moshell-speak:

1) Direct3D is a sophisticated software mechanism for making all kinds of different computer graphics hardware look alike to the game (or application) developer. COM establishes the basic rules about how the modules work together.

2) Each graphics board manufacturer must write their own Direct3D drivers and have them certified by Microsoft.

3) The roles of a graphics package like Direct3D have three basic components:

a) Selecting an optimal combination of hardware and software, based on what is found in your machine;
b) Constructing a scene consisting of graphical objects and lights
c) Displaying them for the user via a "synthetic camera" or set of viewing specifications
If your machine doesn't have some particular hardware capability (like a perspective texture warper function) then Direct3D will link to a generic software solution.

4) The two ways in which tasks b and c can be done are

a) Immediate mode - Set up a viewing specification and a lighting situation, then draw the objects by successively calling primitive functions ("draw this polygon"). If you then enter a loop in which you repeatedly change the object or the lighting, or change the viewing specification and wish to see the changes, you clear the screen and re-execute all the primitives for each pass through the loop.

b) Retained mode - Establish the lighting and viewing conditions.. Either draw the objects by calling primitives, or load files containing descriptions of the objects. Then set up your loop to transform models and change the viewing specifications - but your program doesn't have to re-execute the primitive functions. It just calls TICK() which automatically re-renders the scene.
 

This text only covers the retained mode. That's why we see the initials RM scattered throughout the symbolic names.

The Main Chunks

There's a famous psychological law (Stephen's Law, maybe?) which says that people can hold at most about 7 things in short term memory at any time. So no hierarchy should have more than that number of elements in it, without introducing clear sub-levels. Here are the Level 1 chunks of the Direct3D hierarchy. The book jumps around, so I've rearranged them in a more logical order.

Here's an overview of the main interfaces defined by Direct3D. We will work through the actual chapter using Queries, after the overview.

Setting up the Viewing System

Direct3dRMdevice or Direct3dWinDevice- one of these is used and sets up some aspects of the virtual camera.

Direct3dRMviewport - determines the location and orientation of the virtual camera.

Building the Scene: Essentials

Direct3dRM - the master interface. Used to start a session and set up the scene.

Direct3dRMframe - the scene graph system. A hierarchy of coordinate systems, related by transformations. We'll discuss this in class.

Direct3dRMmeshBuilder - a mesh is an efficient way to store multiple polygons. This tool-object constructs them at a high level, relatively easy to use by the programmer. However, if you want fine-grained control there is also the Direct3dRMmesh interface, which is messier and more fine-grained.

Direct3dRMtexture and Direct3dRMtextureWrap - tools for including textures into graphical objects.

Direct3dRMmaterial - tools for specifying the surface materials of graphical objects

Direct3dRMlight - specify and position the light sources within the scene.

Building the Scene: Extra Stuff

(Did you notice how I managed to stick with my 'rule of 7' by demoting these topics to 'extra stuff'?)

Direct3dRMshadow - plays tricks with a light source and a projection plane to 'fake' a shadow.

Direct3dRManimation and Direct3dRManimationSet - supports walking cycles of humans, birds that flap their wings, etc. In a Retained-Mode system, if you didn't have this capability you would have to model a bird as three objects and continually change the scene graph to flap the wings.

Now let's ask a few questions to make sure you read the chapter.

Query 3.2: Think about how a triangle mesh works. You feed in a sequence of vertices; the first three define a triangle. The next one (call it p4) defines the triangle p2 p3 p4; the next one (p5) defines triangle p3 p4 p5. Draw a triangle mesh that produces a strip of 5 triangles. Now draw some arrangement of connected triangles that CANNOT be produced as a single mesh.

Query 3.3. Think about shadows. The Direct3D shadow system computes a shadow polygon from a given graphical object, a projection plane and a single light source. How would you use this system (notionally, of course; we aren't ready to program it yet) to make a shadow appears to run across the floor and up the wall, as the graphical object approaches the wall?

Query 3.4. Direct3D uses a variety of terms differently than the rest of the graphics community. But then, it was defined by Microsoft, right? Describe the Direct3D concepts below in terms of more common graphical terminology (which you might know from having had a prerequisite graphics class, or just because you're into this stuff.)

Decal - what does the rest of the graphical world call this concept? What does the rest of the world mean by a decal?
Viewport - same two questions.
Frame - same two questions.
D3DrmBox. Hint: the common term for this concept begins with an E. Obviously the second question doesn't apply.

Query 3.5. Look up the concept of a Quaternion in your reference textbooks (if you have any) or in the library. What is a competing system for representing rotation? Describe quaternions' alleged advantages. How does one mathematically combine quaternions A and B (represented as four reals (as, ax, ay, az) etc.) to represent the result of a rotation by A followed by a rotation by B?

To the syllabus
To lecture 2
To lecture 4