Graphics Reference
In-Depth Information
If we chose to discuss corner cutting for polylines rather than closed polylines,
you would have to determine what to do with the starting and ending segments as
you write the code; such boundary cases are often the source of both complexity
and understanding, as well as errors.
We could have opted to explain how to draw individual points, and then how to
draw lines, detect mouse clicks, and create menus and buttons and associate them
with actions in your program, all of which are interesting and valuable topics.
But we want you to be able to start learning graphics visually right away. To do
that requires that we give you some tools whose inner workings you won't yet
understand.
With this goal in mind—providing easy-to-modify programs in which you can
experiment with various ideas in graphics—the remainder of this chapter presents
our 2D test bed.
Following the introduction of the 2D program, we show how to use it to imple-
ment corner cutting in 2D, and provide some exercises in which you can conduct
some experiments that will prepare you for the ideas presented in later chapters.
The test-bed program itself is meant to isolate you, at this point, from under-
standing many of the details of a graphics program. All on-screen graphics
eventually involve setting the color values for individual pixels on the screen. In
Chapter 38 we discuss the underlying software and hardware that work at this low
level. For now, we are letting that hardware and software do the heavy lifting for
us so that we can work at a higher level of abstraction: We assume that we can
create high-level shapes and images and that WPF and Direct3D will take care of
making the pixels look the way we indirectly said they should.
4.2 Details of the Test Bed
As we said, our program is based on WPF, a subject to which entire topics and
thousands of web pages are devoted. In our experience, it is always easier to mod-
ify an existing program than to start from scratch. We therefore built the 2D test
bed and included a sample program with it that does a number of things. You'll
typically use the test bed by copying this sample, deleting most of it, and then mod-
ifying the remainder. The sample displays things such as a photographic image, an
image created in software, a polygon, a mesh, and a quiver of arrows (a collection
of arrows specified by their basepoints and directions). It also has some buttons
(one of which changes which software image is displayed) and a slider (which can
be used to move one vertex of a polygon). From these examples, it should be easy
for you to generalize and add your own interaction elements to the program.
Note that this program is constantly under development; we anticipate aug-
menting it as students indicate ways in which they would like to see it enhanced.
Because those augmentations may cause minor changes to the program, we will
include notes about any such changes on the topic's website. The website also
includes more thorough documentation of the entities included in the test bed;
this chapter is an introduction to the test bed and its use, not the complete docu-
mentation.
4.2.1 Using the 2D Test Bed
At this point in reading this chapter, you should pause, visit the topic's web-
site, and download the 2D test bed as directed there. You should also prepare a
 
 
 
Search WWH ::




Custom Search