|
CS 371
|
Example: A sphere given by F(x,y,z) = (x-a)2 + (y-b)2 + (z-c)2 = r2 has gradient (2 (x-a), 2 (y-b), 2 (z-c)). Notice that in this case, the gradient vector points outward from the surface, of the sphere, which is the desired direction for our purposes.
The GraphicsWindow library (libCS371.a) provides windows which can be displayed on the screen, and the pixels of which can be individually set.
#include "GraphicsWindow.h"
GraphicsWindow myWin; // or GraphicsWindow myWin(rows,cols);where
rows and cols are the numbers of rows and columns of
pixels in (i.e., the dimensions of) the window.myWin.Show();
floats
in the range [0,1]):myWin.DrawPixel(row,col,r,g,b);
myWin.Erase();Note: The background and foreground colors are set to black and white, respectively.
myWin.Flush();
myWin.BigX();
See the program GraphicsWindowTest.cc for an example of using these windows.
/usr/cs-local/lib/cs371lib/ and is called libCS3y1.a.
To use libCS371.a with your own programs, you need to tell the compiler the
name of the library and where it can be found.
Library xyz is traditionally given the name libxyz.a in the
file system. The option -lxyz to g++ command instructs
the compiler to look for a file called libxyz.a.
The option -Ldirectoryname (e.g., -L/usr/cs-local/lib/cs371lib
to g++ tells the compiler to look in the specified directory for
libraries.
Because the GraphicsWindow library uses XWindows as well as a C++ library
and a math library, you will also have to tell
the compiler which of these libraries it will need, and where it can find them.
To do this, add -L/usr/X11R6/lib -lX11 -lm -lc to the g++
command. To tell the compiler where the header file GraphicsWindow.h
resides, add -I/usr/cs-local/include/cs371include.
To tell it where the include files needed for XWindows reside, add
-I/usr/cs-local/include/cs371include.
In summary, to compile, for example, the program GraphicsWindowTest.cc, you would give the following commands:
g++ -c GraphicsWindowTest.cc -I/usr/cs-local/include/cs371include \backslash -I/usr/X11R6/include g++ -o GraphicsWindowTest GraphicsWindowTest.o -L/usr/cs-local/lib/cs371lib \backslash -L/usr/X11R6/lib -lCS371 -lX11 -lm -lcThe backslash at the end of a command line allows you to continue a long command after hitting
Enter.
Of course you can just continue typing; I only used it to improve readability
of this document.
Suggestion: Copy the file GraphicsWindowTest.cc into your own directory and try this!
gmakegmake GraphicsWindowTestWasn't that better? See Lecture 4 for more about gmake.