CS 455 Lecture Notes
Week Three, Tuesday: Abstract Data Types and C++ Classes (cont.)
Classes and Parameters
Functions and parameters are illustrated with some classes from a 3D geometry
library. These classes have some similarity to the example code from the text
but were created especially for use at USC. You should download and compile
the following three files:
This source code compiles without errors or warnings in Microsoft Visual C++ (VC++)
version 6.
To compile with g++ (or some other Unix compiler), put the three files in some directory
and compile and link GeomDemo.cpp and Geometry3D.cpp as described in appendix D of MS.
To compile with VC++, do "File, New, Project" and create a new "Win32 Console Application" project
named, say, "GeometryDemo." VC++ will create a subdirectory named GeometryDemo. Copy the
three source files to the directory and then "add" them to the project using the "Project, Add to Project"
dialog. Then from the "Build" menu do "Rebuild All" and you should get the executable file GeometryDemo.exe
created in the "Debug" subdirectory. You can run this program from the Build menu or start a DOS session
and type GeometryDemo at the DOS prompt from the directory containing the executable file.
Geometry libraries are
useful for computer graphics, computer aided design, computational geometry, and
scientific simulation and visualization. OpenGL includes a 3D geometry library written
in C (so it's not object oriented). Java3D includes an excellent object oriented geometry library.
USC's own Prof. Ari Requicha created a C++ geometry library called Geometric Toolkit (GTK)
which he and his research team use. I created this Geometry3D library to be easy to
understand and use, but to have full power and to be extensible for sophisticated 3D
geometric applications. Features of the library include:
- Single precision floating point arithmetic is used throughout for good performance
in graphic animation or dynamic simulation applications.
- Operator overloading functions are duplicated by named member functions for
portability to Java.
- Classes are consistently structured for maximal ease of use.
Class Point3D
This class is for an atomic object in 3D and is similar to the "Point" class described in the
text except that it is for three dimensions (instead of just two) and contains (or will
contain as it is developed) more useful and realistic member functions. Examine the
source code to see examples of constructors, accessors, mutators, and other member
and non-member functions.
Class Direction3D
This class is a unit direction vector in 3D and is the second atomic object of the
Geometry3D library.
Future versions of Geometry3D will build more complex classes from these two atomic classes.
Operator Overloading
Creating new operator functions provides a programming convenience, but adds complexity
to the code. Java does not allow operator overloading, so to maintain portability of your
code to Java you should also create named member functions equivalent to the overloaded operator
functions. Then to port the code, just delete the overloaded operator functions and combine
the declarations and definitions (Java does not separately declare and define functions).
This page established September 12, 1999; last updated September 15, 1999.