ThreeDBasics.mesa
Copyright © 1984, 1986 by Xerox Corporation. All rights reserved.
Last Edited by: Crow, October 7, 1986 2:10:10 pm PDT
Bloomenthal, February 26, 1987 7:33:07 pm PST
DIRECTORY
Rope     USING [ ROPE ],
Atom     USING [ PropList ],
Imager    USING [ Rectangle ],
ImagerColor   USING [ RGB ],
Pixels     USING [ Extent, PixelBuffer ],
ScanConvert   USING [ IntPair, RealSequence ],
Vector3d    USING [ Pair, PairSequenceRep, Quad, Triple, TripleSequenceRep ],
Matrix3d    USING [ Matrix ];
ThreeDBasics: CEDAR DEFINITIONS
~ BEGIN
Basic Types
RGB: TYPE ~ ImagerColor.RGB;
RealSequence: TYPE ~ ScanConvert.RealSequence;
RECORD [length: NAT ← 0, s: SEQUENCE maxLength: NAT OF REAL];
IntegerSequence: TYPE ~ RECORD [length: NAT ← 0, s: SEQUENCE maxLength: NAT OF INTEGER];
NatSequence:  TYPE ~ RECORD [length: NAT ← 0, s: SEQUENCE maxLength: NAT OF NAT];
NatTable:   TYPE ~ RECORD [
          length: NAT ← 0,
          element: SEQUENCE maxLength: NAT OF REF NatSequence
          ];
Pair: TYPE ~ Vector3d.Pair;           -- RECORD [ x, y: REAL];
PairSequence: TYPE ~ Vector3d.PairSequenceRep;
IntPair: TYPE ~ ScanConvert.IntPair;       -- RECORD[x, y: INTEGER]
Triple: TYPE ~ Vector3d.Triple;        -- RECORD [ x, y, z: REAL];
TripleSequence: TYPE ~ Vector3d.TripleSequenceRep;
       
Quad: TYPE ~ Vector3d.Quad;         -- RECORD [ x, y, z, w: REAL];
Rectangle: TYPE ~ Pixels.Extent;
Xfm3D: TYPE ~ Matrix3d.Matrix; -- REF ARRAY [0..4) OF ARRAY [0..4) OF REAL
ScaleAndAddXfm: TYPE ~ RECORD[scaleX, scaleY, scaleZ, addX, addY, addZ: REAL];
Box: TYPE ~ RECORD[left, right, bottom, top: NAT];    -- bounding box for limit tests
SixSides: TYPE ~ {Left, Right, Bottom, Top, Near, Far};
OutCode: TYPE ~ RECORD[left, right, bottom, top, near, far: BOOLEAN];
NoneOut: OutCode ~ [FALSE, FALSE, FALSE, FALSE, FALSE, FALSE];
AllOut: OutCode ~ [TRUE, TRUE, TRUE, TRUE, TRUE, TRUE];
Vertex Definitions
Vertex: TYPE ~ RECORD[
x,y,z: REAL ← 0.0,     -- object coordinates
ex, ey, ez: REAL ← 0.0,   -- eyespace coordinates
sx, sy, sz: REAL ← 0.0,    -- screen coordinates
clip: OutCode ← NoneOut -- clip code
];
VertexSequence: TYPE ~ RECORD[SEQUENCE length: CARDINAL OF REF Vertex];
ShadingValue: TYPE ~ RECORD[
xn,yn,zn: REAL ← 0.0,   -- normal vector to surface
exn,eyn,ezn: REAL ← 0.0,   -- normal in eyespace
r,g,b: REAL ← 0.7,     -- original color (default grey)
t: REAL ← 0.0,     -- original transmittance
er,eg,eb,et: REAL ← 0.0 -- computed color and transmittance (for current lights, view, etc.)
];
ShadingSequence: TYPE ~ RECORD[SEQUENCE length: CARDINAL OF REF ShadingValue];
VertexInfo: TYPE ~ RECORD[coord: Vertex, shade: ShadingValue, props: Atom.PropList,
  aux: REF ANY];
VertexInfoSequence: TYPE ~ RECORD [SEQUENCE length: CARDINAL OF REF VertexInfo];
VertexInfoProc: TYPE ~ PROC[ context: REF Context, vtx: REF VertexInfo, data: REF ANYNIL ]
       RETURNS[REF VertexInfo];
VtxToRealSeqProc: TYPE ~ PROC[dest: REF RealSequence, source: VertexInfo]
        RETURNS[REF RealSequence];
Patch Definitions
FacingDir: TYPE ~ { front, back, undetermined };
Patch: TYPE ~ RECORD[type: ATOMNIL, oneSided: BOOLEANTRUE, nVtces: NAT ← 0,
       clipState: ClipState ← in, dir: FacingDir ← undetermined,
      props: Atom.PropList ← NIL, vtx: SEQUENCE maxLength: NAT OF VertexInfo];
ImplementedPatch types: $ConvexPolygon, $Bezier
PatchSequence: TYPE ~ RECORD [SEQUENCE length: CARDINAL OF REF Patch];
PtrPatch: TYPE ~ RECORD[type: ATOMNIL, oneSided: BOOLEANTRUE, nVtces: NAT ← 0,
        clipState: ClipState ← in, dir: FacingDir ← undetermined,
        props: Atom.PropList ← NIL, vtxPtr: REF NatSequence];
PtrPatchSequence: TYPE ~ RECORD[SEQUENCE length: CARDINAL OF REF PtrPatch];
PatchProc: TYPE ~ PROC[ context: REF Context, patch: REF Patch, data: REF ANYNIL ]
      RETURNS[REF Patch];
PtrPatchProc: TYPE ~ PROC[ context: REF Context, patch: REF PtrPatch, data: REF ANYNIL ]
       RETURNS[REF PtrPatch];
Shape Definitions (also used for lights)
ClipState: TYPE ~ { in, out, clipped };
ShapeInstance: TYPE ~ RECORD[
type: ATOMNIL,        -- eg. $ConvexPolygon, $Bezier, $Light, etc.
insideVisible: BOOLEANFALSE,    -- closed (or open) surface
name: Rope.ROPE ← NIL,       -- local name for Shape (allows instancing)
fileName: Rope.ROPENIL,      -- file name (should be on a server)
location: Triple ← [0.,0.,0.],      -- position in scene space (last transform)
orientation: Triple ← [0.,0.,1.],     -- vector defining orientation (second transform)
rotation: REAL ← 0.,        -- rotation about rotation axis (first transform)
axisBase: Triple ← [0.,0.,0.],      -- rotation axis: direction = End - Base
axisEnd: Triple ← [0.,0.,1.],      --     rotation is about base point
position: Xfm3D ← NIL,       -- transform from definition space to world space
positionInValid: BOOLEANTRUE,    -- location, orientation, or rotation changed
clipState: ClipState ← in,       -- { in, out, clipped }
shadingInValid: BOOLEANTRUE,    -- true if light or object changed
vtcesInValid: BOOLEANTRUE,    -- true if object or view changed
centroid: Vertex,         -- bounding sphere
boundingRadius: REAL ← 0.0,
screenExtent: Box ← [0, 0, 0, 0],    -- extent on screen (when position valid)
vertex: REF VertexSequence ← NIL,   -- location and clip codes for defining points
shade: REF ShadingSequence ← NIL,    -- shading at defining points
auxInfo: REF ANYNIL,      -- auxiliary info (usually per vertex)
numSurfaces: NAT ← 0,       -- number of surface elements
surface: REF ANYNIL,      -- surface definition using defining points
shadingProps: Atom.PropList ← NIL,   -- shading definition
props: Atom.PropList ← NIL      -- catchall
];
Uses for ShapeInstance.shadingProps:
- $Type - {$Faceted, $Smooth, $Lines, ShapeProc}
- $Color - {REF RGB}
- $Transmittance - {REF REAL}
- $Shininess - {REF REAL}
- $PatchColors - {ShadingValue for each Patch}
ShapeSequence: TYPE ~ RECORD[SEQUENCE length: CARDINAL OF REF ShapeInstance];
ShapeProc: TYPE ~ PROC[context: REF Context, shape: REF ShapeInstance, data: REF ANYNIL]
      RETURNS[REF ShapeInstance];
Context Definition
Context: TYPE ~ RECORD [
shapes: REF ShapeSequence ← NIL,   -- current collection of shapes in environment
lights: REF ShapeSequence ← NIL,    -- current light sources
environment: Atom.PropList ← NIL,   -- for reflection map, ambient light proc, etc.
eyePoint: Triple ← [1.0, -5.0, 2.0],  -- defines point from which view is seen
ptOfInterest: Triple ← [0.,0.,0.],    -- defines center of image and focus
rollAngle: REAL ← 0.,       -- rotational angle about direction of view
upDirection: Triple ← [0.,0.,1.],    -- defines "heads-up" direction (redundant)
fieldOfView: REAL ← 40.,      -- horizontal angle included in field of view
window: Imager.Rectangle ← [-1.,-1., 2., 2.], -- window clips field of view in eyespace
hitherLimit: REAL ← 1.,       -- anything closer to eyepoint is clipped
yonLimit: REAL ← 1000.,      -- anything further from eyepoint is clipped
clippingPlanes: ARRAY SixSides OF Quad,  -- computed clip planes
eyeSpaceXfm: Xfm3D ← NIL,    -- world space to eyespace
eyeToNDC: ScaleAndAddXfm ← [1.,1.,1., 0.,0.,0.], -- eyespace to normalized display coords
viewer: REF ANY,   -- often a QuickViewer or a ViewerClasses.viewer
display: Pixels.PixelBuffer,      -- display-specific info
viewPort: Imager.Rectangle,     -- viewport in floating pt. display coordinates
preferredViewPort: Imager.Rectangle ← [0.,0.,65536.,65536.],  -- maximum viewport size
extentCovered: Box ← [0, 0, 0, 0],    -- bounds area used (while building image)
renderMode: ATOMNIL,      -- {$Bitmap, $Dithered, $PseudoColor, $Grey,
preferredRenderMode: ATOMNIL,    -- $Dorado24, $FullColor }
alphaBuffer: BOOLEANFALSE,    -- buffer for matting and antialiasing
depthBuffer: BOOLEANFALSE,    -- buffer for cheap hidden-surface removal
lineDrawing: BOOLEANFALSE,    -- vector or shaded representation
depthResolution: NAT ← 8192,  -- number of buckets for depth sorting
sortSequence: REFNIL,      -- shapes or surfaces sorted for display
stopMe: BOOLEANFALSE,  -- stop flag for bailing out
suspendMe: BOOLEANFALSE,     -- flag for temporary halts (e.g. display changes)
halted: CONDITION,        -- asserted after stop or suspend acted on
props: Atom.PropList ← NIL-- catchall
];
END.