Draw3d.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, February 26, 1987 7:27:17 pm PST
DIRECTORY Draw2d, Imager, Rope, Matrix3d, Spline3d, ThreeDBasics, Vector3d;
Draw3d: CEDAR DEFINITIONS
~ BEGIN
Type Declarations
origin:    Triple ~ Vector3d.origin;
ROPE:     TYPE ~ Rope.ROPE;
Context:    TYPE ~ Imager.Context;
Pair:     TYPE ~ Vector3d.Pair;
Triple:    TYPE ~ Vector3d.Triple;
Quad:     TYPE ~ Vector3d.Quad;
Matrix:    TYPE ~ Matrix3d.Matrix;
Coeffs:    TYPE ~ Spline3d.Coeffs;
Bezier:    TYPE ~ Spline3d.Bezier;
PairSequence:  TYPE ~ Vector3d.PairSequence;
PairSequenceRep: TYPE ~ Vector3d.PairSequenceRep;
TripleSequence:  TYPE ~ Vector3d.TripleSequence;
TripleSequenceRep: TYPE ~ Vector3d.TripleSequenceRep;
NatTable:    TYPE ~ ThreeDBasics.NatTable;
NatSequence:   TYPE ~ ThreeDBasics.NatSequence;
DrawType:   TYPE ~ Draw2d.DrawType;    -- {solid, dashed, dotted}
MarkType:   TYPE ~ Draw2d.MarkType;    -- {cross, x, asterisk, dot, none}
PointProc:   TYPE ~ PROC [context: Context, pair: Pair];
Note
In the following procedures, if a matrix has perspective, then, before being drawn, any
transformed points are clipped against the viewing frustum.
Point Marking
Mark: PUBLIC PROC [
context: Context,
point: Triple,
matrix: Matrix,
label: ROPENIL,
markType: MarkType ← cross];
Place a mark and optional label at the transformed point.
DoWithPoint: PUBLIC PROC [
context: Context, point: Triple, matrix: Matrix, pointProc: PointProc];
Apply pointProc to the transformed point.
No op if the transformed point is clipped from the viewing frustum.
Straight Line Drawing
Segment: PUBLIC PROC [
context: Context,
point0, point1: Triple,
matrix: Matrix,
drawType: DrawType ← solid];
Draw segment point0-point1.
Vector: PUBLIC PROC [
context: Context,
base, vector: Triple,
matrix: Matrix,
label: ROPENIL,
scale: REAL ← 0.2,
markType: MarkType ← none,
drawType: DrawType ← solid];
Draw and optionally label vector. The base is marked with mark.
The label occurs about 6 pixels beyond the end of the vector, in the direction of the vector.
Axes: PUBLIC PROC [context: Context, matrix: Matrix];
Draw the coordinate axes.
Curve Drawing
Curve: PUBLIC PROC [context: Context, coeffs: Coeffs, matrix: Matrix ← NIL];
Draw the curve, first transforming it if matrix is non-nil
the number of curve segments is determined by Lane's formula.
DotCurve: PUBLIC PROC [context: Context, coeffs: Coeffs, matrix: Matrix ← NIL];
Draw the curve on the given context as above but as a series of dots.
BezierPolygon: PUBLIC PROC [
context: Context,
bezier: Bezier,
matrix: Matrix ← NIL,
drawType: DrawType ← solid,
close: BOOLFALSE];
Draw the traditional three sides of the Bezier polygon; if close is true, draw the fourth side.
Triangle Drawing
Triangle: PUBLIC PROC [
context: Context,
p0, p1, p2: Triple,
view: Matrix];
Draw the triangle.
FrontFacingTriangle: PUBLIC PROC [
context: Context,
p0, p1, p2: Triple,
view: Matrix,
normal: Triple ← origin];
Draw the triangle if it is front-facing.
Polygon Drawing
PolygonPairs: PUBLIC PROC [
triples: TripleSequence,
view: Matrix,
pairs: PairSequence ← NIL]
RETURNS [PairSequence];
Return sequence of vertices transformed into screen space by view; store in pairs if non-nil.
Polygon: PUBLIC PROC [
context: Context,
poly: REF NatSequence,
pairs: PairSequence ← NIL,
triples: TripleSequence ← NIL,
view: Matrix ← NIL];
Draw a single polygon. If pairs is NIL then transform the appropriate triples by view.
Either pairs must be non-NIL or both triples and view must be non-NIL.
FrontFacingPolygon: PUBLIC PROC [
context: Context,
poly: REF NatSequence,
view: Matrix,
normal: Triple ← origin,
pairs: PairSequence ← NIL,
triples: TripleSequence ← NIL];
Draw the polygon if it is back-facing; normal is the polygon normal.
if normal is the origin, compute it from triples; no-op if normal = origin and triples = NIL.
If pairs is NIL then transform the appropriate triples by view.
Polygons: PUBLIC PROC [
context: Context,
polygons: REF NatTable,
pairs: PairSequence ← NIL,
triples: TripleSequence ← NIL,
view: Matrix ← NIL];
Draw the polygon sequence. If pairs is NIL then transform the triples by view.
Either pairs must be non-NIL or both triples and view must be non-NIL.
FrontFacingPolygons: PUBLIC PROC [
context: Context,
polygons: REF NatTable,
view: Matrix,
normals: TripleSequence,
pairs: PairSequence ← NIL,
triples: TripleSequence ← NIL];
Draw the polygon sequence except for back-facing polygons.
If pairs is NIL then transform the triples by view.
normals are the polygon normals (one per polygon).
Labelling
Pendant: PUBLIC PROC [
context: Context,
view: Matrix,
size: REAL ← .07,
wPos, hPos: REAL ← .7,
names: ARRAY [0..6) OF ROPEALL[NIL]];
Produce a screen pendant showing the directions. Naming order is is x, y, z,-x, -y, -z.
LabelPairs: PUBLIC PROC [context: Context, pairs: PairSequence];
Print the pair number next to the pair.
END.