G3dView.mesa
Copyright Ó 1988, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 14, 1992 1:51 pm PDT
DIRECTORY G3dBasic, G3dMatrix, Imager, Rope, ViewerClasses;
Types and Constants
Pair: TYPE ~ G3dBasic.Pair;
Triple: TYPE ~ G3dBasic.Triple;
PairSequence: TYPE ~ G3dBasic.PairSequence;
TripleSequence: TYPE ~ G3dBasic.TripleSequence;
Matrix: TYPE ~ G3dMatrix.Matrix;
Viewport: TYPE ~ G3dMatrix.Viewport;
ROPE: TYPE ~ Rope.ROPE;
Viewer:
TYPE ~ ViewerClasses.Viewer;
origin: Triple ~ G3dBasic.origin;
xAxis: Triple ~ G3dBasic.xAxis;
yAxis: Triple ~ G3dBasic.yAxis;
zAxis: Triple ~ G3dBasic.zAxis;
Camera: TYPE ~ REF CameraRep;
CameraRep:
TYPE ~
RECORD [
move, rotate: Triple ¬ [],
scale: REAL ¬ 1.0,
fieldOfView: REAL ¬ 60.0,
roll: REAL ¬ 0.0,
eyePoint, lookAt, up: Triple ¬ [],
matrix: Matrix ¬ NIL
];
PairClip:
TYPE ~
RECORD [pair: Pair, clipped:
BOOL];
GetViewport:
PROC [viewer: Viewer ¬
NIL, context: Imager.Context ¬
NIL]
RETURNS [Viewport];
Return viewport to fit [-1..1] (in x, y) image to context or viewer (whichever is non-NIL).
If viewer = NIL and context is for an Interpress master, viewport is set to 8-1/2 by 11 inches.
Transformation
TransformAndClipInZ:
PROC [point: Triple, view: Matrix, viewport: Viewport ¬ []]
RETURNS [PairClip];
Transform the point and test if it's clipped in z only (let Imager clip in x and y).
PairsFromTriples:
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.
Transformation Creation and Translation
TransformByViewport:
PROC [viewer: Viewer, in: Matrix, out: Matrix ¬
NIL]
RETURNS [Matrix];
Transform in by the viewer's viewport; use out if non-NIL.
Use of this procedure is discouraged, as it will cause clipping errors.
MakeCameraMatrix:
PUBLIC
PROC [
worIncr: Matrix ¬ NIL,
scale: REAL ¬ 1.0,
move: Triple ¬ [0.0, 0.0, 0.0],
rotate: Triple ¬ [0.0, 0.0, 0.0],
eyeIncr: Matrix ¬ NIL,
fieldOfView: REAL ¬ 0.0,
swapYZ: BOOL ¬ TRUE,
out: Matrix ¬ NIL]
RETURNS [Matrix];
Return the world to view transformation matrix, using out if non-NIL. This transforms world
space coordinates into view space. The canonical transformation sequence used here is:
(world) WiSTRXEi (eye) P (view),
where S=scale, T=translate, R=RxRyRz=rotate about x, y, and z axes, X=swap y and z, P=perspective; the parenthesized coordinate systems are only labels.
World space is right-handed, generally having x=right, y=away ("into" the screen), z=up,
Eye and view spaces are left-handed with x=right, y=up, z=away.
swapYZ true if changing from right-handed world space to left-handed view space.
If fieldOfView # 0, view space is a perspective space; the other spaces are orthogonal.
WorldToViewFromVectors:
PROC [
eyePoint: Triple ¬ origin,
lookAt: Triple ¬ zAxis,
upDirection: Triple ¬ yAxis,
fieldOfView: REAL ¬ 40.0,
out: Matrix ¬ NIL]
RETURNS [Matrix];
Compute a camera matrix, using out if non-nil.
FromScaleMovesRots:
PROC [scale:
REAL, moves, rotates: Triple]
RETURNS [eyePoint, lookAt, upDirection: Triple];
Return the camera position and orientation given the standard moves and rotates in x, y, z.
FromEyeLookUp:
PROC [eyePoint, lookAt, upDirection: Triple, fieldOfView:
REAL]
RETURNS [moves, rotates: Triple];
Return the standard moves and rotates in x, y, z given the camera position and orientation.