DIRECTORY Vector3d; Matrix3d: CEDAR DEFINITIONS ~ BEGIN Pair: TYPE ~ Vector3d.Pair; Triple: TYPE ~ Vector3d.Triple; Quad: TYPE ~ Vector3d.Quad; origin: Triple ~ Vector3d.origin; Row: TYPE ~ [0..4); Col: TYPE ~ [0..4); Matrix: TYPE ~ REF MatrixRep; MatrixRep: TYPE ~ ARRAY Col OF ARRAY Row OF REAL; MatrixSequence: TYPE ~ REF MatrixSequenceRep; MatrixSequenceRep: TYPE ~ RECORD [element: SEQUENCE maxLength: NAT OF Matrix]; singular: ERROR; CopyMatrix: PROC [in: Matrix, out: Matrix _ NIL] RETURNS [Matrix]; CopyMatrixSequence: PROC [in: MatrixSequence] RETURNS [MatrixSequence]; Identity: PROC [out: Matrix _ NIL] RETURNS [Matrix]; MakeFromTriad: PROC [v1, v2, v3: Triple, p: Triple _ origin, out: Matrix _ NIL] RETURNS [Matrix]; MakeScale: PROC [s: Triple, out: Matrix _ NIL] RETURNS [Matrix]; MakeTranslate: PROC [p: Triple, out: Matrix _ NIL] RETURNS [Matrix]; MakePureRotate: PROC [axis: Triple, theta: REAL, degrees: BOOL _ TRUE, out: Matrix _ NIL] RETURNS [Matrix]; MakeRotate: PROC [axis: Triple, theta: REAL, degrees: BOOL _ TRUE, base: Triple _ origin, out: Matrix _ NIL] RETURNS [Matrix]; MakePerspective: PROC [dInv, fInv, fov: REAL, out: Matrix _ NIL] RETURNS [Matrix]; HasPerspective: PROC [mat: Matrix] RETURNS [BOOL]; TransformH: PROC [p: Triple, mat: Matrix] RETURNS [Quad]; Transform: PROC [p: Triple, mat: Matrix] RETURNS [Triple]; TransformD: PROC [p: Triple, mat: Matrix] RETURNS [Pair]; TransformPair: PROC [p: Pair, mat: Matrix] RETURNS [Triple]; TransformPairD: PROC [p: Pair, mat: Matrix] RETURNS [Pair]; TransformVec: PROC [vec: Triple, mat: Matrix] RETURNS [Triple]; TransformVecDiffS: PROC [vec: Triple, mat: Matrix] RETURNS [Triple]; Scale: PROC [in: Matrix, s: REAL, out: Matrix _ NIL] RETURNS [Matrix]; DiffScale: PROC [in: Matrix, s: Triple, out: Matrix _ NIL] RETURNS [Matrix]; Rotate: PROC [in: Matrix, axis: Triple, theta: REAL, degrees: BOOL _ TRUE, base: Triple _ origin, out: Matrix _ NIL] RETURNS [Matrix]; Translate: PROC [in: Matrix, p: Triple, out: Matrix _ NIL] RETURNS [Matrix]; LocalScale: PROC [in: Matrix, s: REAL, out: Matrix _ NIL] RETURNS [Matrix]; LocalDiffScale: PROC [in: Matrix, s: Triple, out: Matrix _ NIL] RETURNS [Matrix]; LocalRotate: PROC [in: Matrix, axis: Triple, theta: REAL, degrees: BOOL _ TRUE, base: Triple _ origin, out: Matrix _ NIL] RETURNS [Matrix]; LocalTranslate: PROC [in: Matrix, p: Triple, out: Matrix _ NIL] RETURNS [Matrix]; Mul: PROC [left, rite: Matrix, out: Matrix _ NIL] RETURNS [Matrix]; Cat: PROC [m1, m2: Matrix, m3, m4, m5, m6, out: Matrix _ NIL] RETURNS [Matrix]; Invert: PROC [in: Matrix, out: Matrix _ NIL] RETURNS [Matrix]; Adjoint: PROC [in: Matrix, out: Matrix _ NIL] RETURNS [Matrix]; Cofactors: PROC [in: Matrix, out: Matrix _ NIL] RETURNS [Matrix]; Determinant: PROC [mat: Matrix] RETURNS [REAL]; Transpose: PROC [in: Matrix, out: Matrix _ NIL] RETURNS [Matrix]; InTermsOf: PROC [A, B: Matrix, out: Matrix _ NIL] RETURNS [Matrix]; Invert3x3: PROC [m: Matrix, out: Matrix _ NIL] RETURNS [Matrix]; ObtainMatrix: PROC RETURNS [Matrix]; ReleaseMatrix: PROC [matrix: Matrix]; END. °Matrix3d.mesa Copyright c 1984 by Xerox Corporation. All rights reserved. Bloomenthal, February 26, 1987 7:06:25 pm PST Cf ``Principles of Interactive Computer Graphics,'' by Newman and Sproull. Left-handed eyespace coordinate system (right, up, depth); right-handed world coordinate system (longitude, latitude, altitude). Wherever feasible, a procedure will use the argument "out," if provided, rather than allocate a new MatrixRep. A three-dimensional affine transformation, an element is m[row][col]: Creation Operations Return a copy of the input matrix. Return a copy of the input sequence of matrices. Return the identity matrix. Return transformation to coordinate system defined by three orthonormal axes. Make a matrix which only scales by [s.x, s.y, s.z]. Make a matrix which only translates by [p.x, p.y, p.z]. Make matrix which only rotates by theta about axis. Make matrix that only rotates by theta about line given by base, axis. Return the perspective transformation: d (=1/dInv) is the distance the eye is along the -zaxis; dInverse = 0 for orthographic projection. f (=1/fInv) is the distance the far clipping plane is along the +zaxis; fInverse = 0 for no far clipping. field-of-view (fov) is in degrees. dInv=fInv=0 or fov=0 yields an orthographic projection. Return TRUE iff the matrix has a perspective element. Transformation Operations Postmultiply by transformation matrix, yielding a homogeneous point. The following four transformation procedures test the transformation matrix for perspective (i.e., the matrix has perspective iff the last column is not [0, 0, 0, 1]. If a perspective element exists, the return coordinates are first divided by w. Postmultiply by transformation matrix, yielding non-homogenous point. Postmultiply by transformation matrix, yielding [x, y] pair. This is useful when transforming from object to screen space, in which z-screen is not used. Postmultiply a point in the xy plane by a transformation matrix. This is useful when transforming a planar contour into object space. Postmultiply a point in the xy plane by mat, yielding [x, y] pair. This is useful when transforming a planar contour into screen space. If no differential scaling exists within the transformation matrix, TransformVec may be used. Otherwise, use TransformVecDiffS. Postmultiply a vector by a transformation matrix, without the translation components. Postmultiply a vector by transform of cofactors of mat, in case mat has differential scaling (ie., the x, y, and z scale factors are not equal). Concatenation Operations The next 3 procs post-multiply the matrix, thus transforming in the reference coordinate space. Concatenate a scaling by s. Differential scaling: concatenate a scaling by [s.x, s.y, s.z]. Concatenate rotation of theta about the line given by base and axis. Concatenate a translation by [p.x, p.y, p.z]. The next 3 procs pre-multiply the matrix, thus transforming in the local coordinate space. Concatenate a local scaling by s. Differential scaling: concatenate a local scaling by [s.x, s.y, s.z]. Concatenate local rotation of theta radians about line given by base, axis. Concatenate a local translation. Mathematical Operations Returns matrix product left X right; Examples: a _ Multiply[a, b, a]; b _ Multiply[a, b, b]; c _ Multiply[a, b]. Return concatenation of input matrices. Can raise ERROR: singular. Return the adjoint of in. Return the cofactors of in. Return the determinant of mat. Return the transpose of in. Return B in terms of A. It is useful to be able to express one coordinate system in terms of another. Consider this example. Given an earth coordinate system and a moon coordinate system, both expressed in world coordinates, then displaying the moon rotating about the earth may be expressed as: MoonInTermsOfEarth _ InTermsOf[earth, moon]; FOREVER DO: MoonInTermsOfEarth _ YRotate[MoonInTermsOfEarth, theta]; moon _ Mul[earth, MoonInTermsOfEarth]; Draw[moon] ENDLOOP; Invert the 3 by 3 matrix formed from the first three columns and rows of m, and return in out; the last column and last row of out are unchanged. Miscellaneous Operations Obain a matrix from the scratch pool; using the pool mimizes storage allocation. Return the matrix to the scratch pool. ΚA˜codešœ ™ Kšœ Οmœ1™Kšœ™K™—š œžœžœžœ ˜?K™K˜—š  œžœžœžœ ˜AK™K˜—š  œžœžœžœ˜/K™K˜—š  œžœžœžœ ˜AK™K˜—š  œžœžœžœ ˜CK™K™Kšœ\™\KšœZ™ZšœY™YK™Kšœ,™,šœ ™ Kšœ8™8Kšœ&™&Kšœ ™ Kšœ™—K™——š  œžœžœžœ ˜@K™‘——šœ™š  œžœžœ ˜$J™PK˜—š  œžœ˜%K™&—K˜—Kšžœ˜—…— <#-