home *** CD-ROM | disk | FTP | other *** search
-
-
-
-
-
-
-
-
-
- TRI_D.TPU
-
- A library for 3 dimensional graphics
-
- by Gus Smedstad
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Table of Contents
- Introduction 1
- Statement of purpose 1
- Registration 1
- 3DEMO 1
- Types 2
- Procedures 2
- Definition of viewing conditions 2
- Drawing primitives 3
- Object operations 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Introduction
-
- Statement of purpose
-
- TRI_D.TPU is a toolkit for drawing and manipulating three
- dimensional objects. The intent is to be fast, yet accurate, and to
- keep the actual mechanics out of the way of the user.
- For example, each point within an object is stored only once,
- regardless of how many polygons share that point, and transformed only
- once when object or the viewpoint moves. Similiarly, when drawing
- wireframes, edges which two polygons share are stored (and drawn) only
- once. None of this requires any explicit effort on the part of the
- user.
- Registration
-
- TRI_D.TPU is distributed as shareware. In order to use it
- legally, receive support, and future updates, you must send $30
- to:
- NoGate Consulting
- #13 DesIsle Ave
- Bar Harbor, Maine 04609
- (207)288-4723
-
- Make checks payable to Gus Smedstad.
-
- Future improvements may include an assembler version (for speed),
- a Turbo C library, and hidden edge removal for concave polygons or
- polygons with holes. However, such improvements will ONLY be
- distributed to registered users, and not as shareware.
-
- Source is available for $100.
-
-
- 3DEMO
-
- As part of this ARC, you should have a copy of 3DEMO.PAS, which
- is a fair demonstration of the power of TRI_D.TPU. To compile it, you
- will need GRAPH.TPU and TRI_D.TPU.
- Once 3DEMO is running, you will see 5 objects - a cylinder, a
- hemisphere, a pyramid, a house, and a plane. You can move and rotate
- any of them, or the viewpoint, and remove the hidden edges at any
- time. Simply select an object by typing a number from 1 to 5, and use
- the arrow keys to move or rotate it. The <Page Up> and <Page Down>
- keys will move the object on the Z axis.
- Note that when the viewpoint is rotated to (say) look down the X
- axis, moving an object with the <Right Arrow> and <Left Arrow> will
- move it closer or farther from the viewpoint. Rotation of the
- viewpoint, however, stays relative to the current viewing direction,
- so the <Up Arrow> key will always appear to make the objects on the
- screen rotate down.
- Type H to remove the hidden edges, and then press any key to
- return to the wireframe drawings.
-
-
-
-
-
- - 1 -
-
-
-
-
-
-
-
-
- Some suggestions: try moving very close to the objects, or make
- the objects intersect and try removing the edges. Note that every
- polygon has two separate sides, with separate colors.
-
- When you're done, type Q or the <ESC> key.
-
-
- Types
- TRI_D only defines one type:
-
- VECTOR = array[0..2] of real;
-
- The VECTOR type is used extensively by TRI_D to hold 3-d points
- (the term vector is used in the mathematical, rather than geometric,
- sense). The [0] element holds the X coordinate, [1] the Y coordinate,
- and [2] the Z coordinate.
-
- For ease and speed of manipulation, lines, points, and polygons
- can be grouped into objects. Objects are simply of type POINTER -
- when MakeObject creates an object, it actually creates a more complex
- internal data type, and returns the address, so that actual
- implementation details don't intrude on the programmer.
- All points and polygons are considered to be part of the last
- object created with MakeObject or opened with OpenObject, or part of
- the background.
-
- Procedures
- The following is a list of the procedures provided by the unit
- TRI_D.TPU.
-
-
- Definition of viewing conditions
-
- procedure SetViewpoint(x, y, z : real);
- - The location of the "observer."
-
- procedure SetViewDirection(ThetaX, ThetaY, ThetaZ : real);
- - Set the direction of viewing, relative to the negative Z
- direction, with the Y axis being vertical, in terms of the angle
- rotated about the X, Y, and Z axis. If this does not seem very
- clear, think of ThetaY as rotation, ThetaX as inclination, and
- ThetaZ as yaw. For example, SetViewDirection(pi/2,0,0) will look
- along the Y axis, with the Z axis being 'up' on the screen, and
- SetViewDirection(0,0,pi/2) will look along the Z axis, with the
- negative X axis being 'up.'
-
- procedure RotateViewDirection(ThetaX, ThetaY, ThetaZ : real);
- - Rotate the direction of viewing, relative to the current view
- direction. To keep subjective rotations consistent, ThetaZ
- rotates around the current view direction, ThetaY rotates around
- the current 'up' direction, and ThetaX rotates around the line
- perpendicular to them both, instead of around the X, Y, and Z
- axes as SetViewDirection does.
-
-
-
-
- - 2 -
-
-
-
-
-
-
-
-
- procedure SetCenter(x, y : integer);
- - position of viewpoint on screen, in screen coordinates. May be
- off-screen, if desired.
-
- procedure SetScale(s : real);
- - width of the viewport in world coordinates.
-
- procedure SetDrawMode(HideEdges, Perspective : boolean);
- - Set hidden plane removal and perspective or parallel views. Note
- that the drawing primitives (below) do not produce any immediate
- output when edges are being removed. Use the Regenerate
- procedure to see the objects. When Perspective is TRUE, objects
- are scaled and foreshortened by distance. A caveat - objects
- will be much smaller, so set the scale appropriately.
-
-
- Drawing primitives
-
- procedure MakePoint(x, y, z : real; color : byte);
- - Create a point. Not very meaningful when hiding edges.
-
- procedure SetPolyColors(pattern1, color1, pattern2, color2 : byte);
- - Define colors and fill patterns for polygons. Polygons drawn
- after this command will have (Color1,pattern1) on one side and
- (color2,pattern2) on the other. See the GRAPH unit from color
- and pattern definitions. Only color1 is used for drawing lines,
- and when not hiding edges.
-
- procedure MakePolygon(var pts; numpts : word);
- - pts is assumed to be an array[1..numpts] of VECTOR. This version
- requires that Polygons be convex (that is, no interior angle >=
- 180 degrees) for hidden-edge removal to work perfectly, though
- later versions may eliminate this restriction.
-
- procedure MakeLine(x1, y1, z1, x2, y2, z2 : real);
- - Make a line from the first point to the second. Same as
- MakePolygon(pts,2), where pts = array[1..2] of VECTOR.
-
- procedure MakeTriangle(var pt1, pt2, pt3 : vector);
- - Make a triangle with points pt1, pt2, pt3.
-
- procedure MakeSurface(var pointlist; rows, cols : word;
- steps : integer);
- - Perform a Bspline curve-fit on an array[1..rows,1..cols] of
- VECTOR. The curve is created in STEPS increments.
-
-
-
-
-
-
-
-
-
-
-
-
- - 3 -
-
-
-
-
-
-
-
-
- Object operations
-
- procedure Makeobject(var object : pointer);
- - Creates an object.
-
- procedure DeleteObject(var object : pointer);
- - Deletes an object (but doesn't erase it from the screen).
- Selects the background for further drawing.
-
- procedure OpenObject(object : pointer);
- - Start adding polygons/points to an OBJECT previously created with
- MakeObject. Closes any previous object. Note that objects may
- be switched as many times as you like. If given an uninitialized
- object, the background is selected instead.
-
- procedure CloseObject;
- - Select the background for drawing.
-
- procedure CopyObject(object : pointer);
- - Copies all the polygons of an object into the current object.
-
- procedure DrawObject(Object : pointer);
- - Draw a single object. Note that other objects on the screen are
- ignored when hiding edges, so Regenerate is more useful in that
- mode.
-
- procedure EraseObject(Object : pointer);
- - Erases a single object. When drawing wireframes, other images
- will be quickly redrawn where they overlap the erased object.
-
- procedure Regenerate;
- - Draw ALL objects, including the background object. Does NOT
- clear the screen/viewport.
-
- procedure ObjectColors(Object : pointer;
- pattern1, color1, pattern2, color2 : byte);
- - Changes all of the polygons in the object to a color/pattern set.
-
- procedure ObjectStyle(Object : pointer;
- LineStyle, pattern, thickness : byte);
- - Changes the linestyle of the object (when drawn as a wireframe).
-
- procedure MoveObject(object : pointer; dx, dy, dz : real);
- - Move an object by dx, dy, and dz.
-
- procedure RotateObject(object : pointer; theta,
- center, delta : vector);
- - A more general object-moving procedure. Rotate an object
- Theta[0] radians about its X axis, Theta[1] about its Y axis, and
- Theta[2] about its Z axis. Center defines the center point to
- rotate about, and Delta is the amount to move the object after
- the rotation.
-
-
-
-
-
- - 4 -
-
-
-