DIRECTORY G2dMatrix, G3dBasic; G3dMatrix: CEDAR DEFINITIONS ~ BEGIN singular: ERROR; Matrix: TYPE ~ REF MatrixRep; MatrixRep: TYPE ~ ARRAY [0..4) OF ARRAY [0..4) OF REAL; MatrixSequence: TYPE ~ REF MatrixSequenceRep; MatrixSequenceRep: TYPE ~ RECORD [ length: CARDINAL ฌ 0, element: SEQUENCE maxLength: CARDINAL OF Matrix ]; TransformOrder: TYPE ~ {pre, post}; -- type of concatenation Viewport: TYPE ~ RECORD [ scale: Pair ฌ [1.0, 1.0], aspectRecip: REAL ฌ 1.0, translate: Pair ฌ [0.0, 0.0]]; Pair: TYPE ~ G3dBasic.Pair; Triple: TYPE ~ G3dBasic.Triple; Quad: TYPE ~ G3dBasic.Quad; Ray: TYPE ~ G3dBasic.Ray; Screen: TYPE ~ G3dBasic.Screen; origin: Triple ~ G3dBasic.origin; CopyMatrix: PROC [matrix: Matrix, out: Matrix ฌ NIL] RETURNS [Matrix]; Identity: PROC [out: Matrix ฌ NIL] RETURNS [Matrix]; MakeFromTriad: PROC [ v1, v2, v3: Triple, p: Triple ฌ origin, unitize: BOOL ฌ FALSE, out: Matrix ฌ NIL] RETURNS [Matrix]; MakeFromRows: PROC [r0, r1, r2, r3: Quad, out: Matrix ฌ NIL] RETURNS [Matrix]; MakeScale: PROC [s: Triple, out: Matrix ฌ NIL] RETURNS [Matrix]; MakeTranslate: PROC [p: Triple, out: Matrix ฌ NIL] RETURNS [Matrix]; MakeRotate: PROC [axis: Triple, theta: REAL, degrees: BOOL ฌ TRUE, out: Matrix ฌ NIL] RETURNS [Matrix]; MakeRotateAbout: PROC [ axis: Triple, theta: REAL, degrees: BOOL ฌ TRUE, base: Triple ฌ origin, out: Matrix ฌ NIL] RETURNS [Matrix]; MakePerspective: PROC [nInv, fInv, fov: REAL, out: Matrix ฌ NIL] RETURNS [Matrix]; HasPerspective: PROC [mat: Matrix] RETURNS [BOOL]; MakeVectorTransform: PROC [pointTransform: Matrix, out: Matrix ฌ NIL] RETURNS [Matrix]; 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]; TransformQuad: PROC [q: Quad, mat: Matrix] RETURNS [Quad]; TransformVec: PROC [vec: Triple, mat: Matrix] RETURNS [Triple]; TransformVecDiffS: PROC [vec: Triple, mat: Matrix] RETURNS [Triple]; TransformPlane: PROC [plane: Quad, mat: Matrix, matInverse: Matrix ฌ NIL] RETURNS [Quad]; PremultiplyPlaneByMatrix: PROC [plane: Quad, m: Matrix] RETURNS [Quad]; TransformByViewport: PROC [p: Pair, vp: Viewport] RETURNS [Pair]; 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]; ExtractRotate: PROC [m: Matrix] RETURNS [Triple]; InTermsOf: PROC [A, B: Matrix, out: Matrix ฌ NIL] RETURNS [Matrix]; CopyMatrixSequence: PROC [matrices: MatrixSequence] RETURNS [MatrixSequence]; AddToMatrixSequence: PROC [matrices: MatrixSequence, matrix: Matrix] RETURNS [MatrixSequence]; LengthenMatrixSequence: PROC [matrices: MatrixSequence, amount: REAL ฌ 1.3] RETURNS [MatrixSequence]; ObtainMatrix: PROC RETURNS [Matrix]; ReleaseMatrix: PROC [matrix: Matrix]; GetScreen: PROC [point: Triple, view: Matrix, hasPerspective: BOOL, viewport: Viewport] RETURNS [Screen]; TripleFromScreen: PROC [p: Pair, view: Matrix, viewInverse: Matrix ฌ NIL] RETURNS [Triple]; TripleFromScreenAndPlane: PROC [ p: Pair, plane: Quad, view: Matrix] RETURNS [Triple]; LineFromScreen: PROC [p: Pair, view: Matrix, viewInverse: Matrix ฌ NIL] RETURNS [Ray]; END. จ G3dMatrix.mesa Copyright ำ 1984, 1988, 1992 by Xerox Corporation. All rights reserved. Bloomenthal, July 15, 1992 6:27 pm PDT Ken Fishkin, November 6, 1991 1:08 pm PST Cf ``Principles of Interactive Computer Graphics,'' by Newman and Sproull. Left-handed eyespace coordinate system (right, up, depth = into screen); Right-handed world coordinate system. Rotation correspondences: vertical rotation: yaw <=> azimuth <=> longitude, horizontal rotation: pitch <=> elevation <=> latitude, longitudinal rotation: roll Where feasible, procedures use the argument "out," if given; if not a new MatrixRep is allocated. Type Declarations A three-dimensional affine transformation; an element is m[row][col]: Creation Operations Return a copy of the input matrix; use out if non-nil. Return the identity matrix. Return transformation to coordinate system defined by three orthonormal axes. v1, v2, v3 correspond to the x, y, and z axes. Makes a matrix with the given rows. 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 rotates by theta about the given axis (which goes through the origin). Rotation is right handed. Make matrix that is a pure rotation matrix by theta about the line given by base, axis. Rotation is right handed. Return the perspective transformation; f (=1/fInv) is distance the far clipping plane is along +zaxis; fInverse=0 for no far clipping. field-of-view (fov) is in degrees; it is the full field of view. nInv=fInv=0 or fov=0 yields an orthographic projection. nInv = 1/zNear, fInv = 1/zFar. Eye point is assumed at [0, 0, 0], viewing along +z axis. Return TRUE iff the matrix has a perspective element. Given a point tranform, create the tranform for transforming vectors; i.e., create a matrix for normals/direction vectors (homogeneous coordinate = 0). Use out if non-NIL. 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. Postmultiply a four element vector by mat, yielding a four element vector. 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). Transform the plane by mat. This amounts to a premultiplication by matInverse. If matInverse is not given as an argument, then the adjoint of mat must be computed. Return a plane premultiplied by a matrix. Transform the two dimensional point by the viewport. 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. Decompose a 3x3 rotation matrix m (within a 4x4 matrix) into m = [rotx(a)]*[roty(b)]*[rotz(c)]. Correct for right-handed coordinate system and right-handed rotations. cf: Ned Greene's Extracting Transformation Parameters from Transformation Matrices. return [a, b, c]; 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; Sequence Operations Return a copy of the input sequence of matrices. Add matrix to the sequence. Return a copy of the input sequence whose maxLength is amount*input.maxLength. Scratch Matrix Operations Obain a matrix from the scratch pool; using the pool mimizes storage allocation. Return the matrix to the scratch pool. Point Transformation and Visibility Testing Return a screen position and clip information (does not alter screen.fwdFacing). Three-dimensional Information Derived from the Screen Return a point that would transform to p. Return a point on the plane that would transform to p. Return the line through the eyepoint that would intersect the display at p. สฎ•NewlineDelimiter –"cedarcode" style™™Jšœ ฯeœ=™HJ™&J™)J™J™J™HJ™—J™%šฯo™Jšžœž™1Jšž6™6Jšžœ™—J™šœฯsœ Ÿœ ŸœŸœŸœŸœŸœŸœŸœŸœŸœŸœŸœ ŸœŸœ ™aJ™—Jšฯk œ˜J˜—Jšัbln œ œ  ˜šœ ˜J˜Jšœ  œ˜—headšฯl™J™EJšœ  œ œ ˜ Jš œ  œ œ œ œ œ œ˜9J˜Jšœ œ œ˜.šœ œ œ˜"Jšœ  œ˜Jšœ œ  œ œ˜4J˜J˜—šœ œฯc˜=J˜—šœ  œ œ˜JšœŸœŸœŸœ ˜Jšœ Ÿ ŸœŸœ˜Jšœ ŸœŸœŸœ ˜#J˜—Jšœ  œ˜Jšœ  œ˜"Jšœ  œ˜Jšœ  œ˜šœ  œ˜"J˜—J˜$—šข™šฯn œ œ  œ œ ˜FJ™6J™—šคœ œ œ œ ˜4J™J˜—šค œ œ˜Jšœ˜J˜Jšœ  œ œ˜Jšœ œ˜Jš œ ˜J™MJ™.J˜—šค œ œ& œ œ ˜NJ™#—J˜šค œ œ œ œ ˜@J™3J˜—šค œ œ œ œ ˜DJ™7J™—š ค œ œ œ  œ œ œ˜UJš œ ˜J™XJ™J˜—šคœ œ˜Jš œ œ  œ œ' œ˜ZJš œ ˜J™WJ™J˜—š คœ œ œ œ œ ˜RJ™&J™`J™@J™7J™J™9J™—šคœ œ œ œ˜2J™5J™—šคœ œ( œ œ ˜WJšœ[™[JšœLŸœ™P——šข™šค œ œ œ˜9J™DJ˜—J™bJ™e™.J™—šค œ œ œ ˜:J™EJ˜—šค œ œ œ˜9J™J™J™—šคœ œ œ œ ˜?J™J˜—šค œ œ œ œ ˜AJ™J˜—šค œ œ œ œ˜/J™J˜—šค œ œ œ œ ˜AJ™J˜—šค œ œ  œ ˜1J™_J™FJšœฯzAœ™SJ™J˜—š ค œ œคœ œ œ ˜CJ™J™\J™Z™YJ™,™ J™8J™&J™ J™————šข™šคœ œ œ˜M™0J™——šคœ œ+˜DJš œ˜™J™——šคœ œ$ œ˜KJš œ˜J™N——šข™šค œ œ œ ˜$J™PJ˜—šค œ œ˜%J™&——šข+™+šค œ œ/ œ˜WJš œ ˜J™P——šข5™5šคœ œ/ œ˜IJš œ ˜J™)J˜—šคœ œ˜ J˜J˜ J˜ Jš œ ˜™6J˜——šคœ œ/ œ œ˜VJ™K—J™—Jš œ˜—…—T0ช