/* * vliutils.cpp * * $Id: vliutils.cpp,v 1.9 2000/01/18 15:18:27 vesper Exp $ * * Module to implement various utilities * * Copyright, Mitsubishi Electric Information Technology Center * America, Inc., 1999, All rights reserved. */ #include "vliutils.h" VLIMatrix VLIUtCompose(VLIMatrix& inRotation, // Rotation. double inScale[3], // X, Y, and Z Scales. double inTranslation[3], // X, Y, and Z Translations. double inShear[3]) // XY, XZ, and YZ shear. { VLIMatrix shear; shear[0][1] = inShear[0]; shear[0][2] = inShear[1]; shear[1][2] = inShear[2]; return (VLIMatrix::Translate (inTranslation[0], inTranslation[1], inTranslation[2]) * inRotation * shear * VLIMatrix::Scale (inScale[0], inScale[1], inScale[2])); } // This is from Graphics Gems II. Adaptation of the Decomposition of // a matrix by Spencer W. Thomas. // void VLIUtDecompose (const VLIMatrix& inMatrix, // Matrix to decompose VLIMatrix& outRotation, // Rotation. double outScale[3], // X, Y, and Z Scales. double outTranslation[3], // X, Y, and Z Translations. double outShear[3]) // XY, XZ, and YZ shear. { // The translation part of the Matrix // outTranslation[0] = inMatrix[0][3]; outTranslation[1] = inMatrix[1][3]; outTranslation[2] = inMatrix[2][3]; // Get the scale and shear. Doing it column based as we // are column major // VLIVector3D c0, c1, c2; c0.Assign (inMatrix[0][0], inMatrix[1][0], inMatrix[2][0]); c1.Assign (inMatrix[0][1], inMatrix[1][1], inMatrix[2][1]); c2.Assign (inMatrix[0][2], inMatrix[1][2], inMatrix[2][2]); // Compute the X-Scale and normalize first column // outScale[0] = c0.Length (); c0.Normalize (); // Compute XY shear and make second column orthogonal to first // outShear[0] = VLIDot (c0, c1); c1 = c1 + (c0 * (-outShear[0])); // Compute the Y-Scale and normalize 2nd column // outScale[1] = c1.Length (); c1.Normalize (); outShear[0] /= outScale[1]; // Compute XZ and YZ shears, orthogonalize 3rd column // outShear[1] = VLIDot (c0, c2); c2 = c2 + (c0 * (-outShear[1])); outShear[2] = VLIDot (c1, c2); c2 = c2 + (c1 * (-outShear[2])); // Next, get Z scale and normalize 3rd column // outScale[2] = c2.Length (); c2.Normalize (); outShear[1] /= outScale[2]; outShear[2] /= outScale[2]; /* At this point, the matrix (in c*) is orthonormal. * Check for a coordinate system flip. If the determinant * is -1, then negate the matrix and the scaling factors. */ if (VLIDot (c0, VLICross (c1, c2)) < 0) { outScale[0] *= -1.0; outScale[1] *= -1.0; outScale[2] *= -1.0; c0 *= -1.0; c1 *= -1.0; c2 *= -1.0; } // The c0, c1, c2 should be the remaining rotation matrix // outRotation .Assign (c0[0], c1[0], c2[0], 0.0, c0[1], c1[1], c2[1], 0.0, c0[2], c1[2], c2[2], 0.0, 0.0, 0.0, 0.0, 1.0); } // TBD: better descriptions needed. const char *VLIUtGetErrorString(VLIStatus status) { unsigned int index; static const char *errStrings[] = { "kVLIOK - no error.", "kVLIMultiPass - no error, however, multiple renderings will occur.", "kVLITimeout - no error, timeout happened before event.", "kVLIErrAlloc - some resource required for this operation could not be allocated.", "kVLIErrVolumeInvalid - the volume was invalid: format or layout mismatch, or no data available.", "kVLIErrMath - divide by zero or similar error.", "kVLIErrArgument - bad input, check sizes and formats.", "kVLIErrUnimplemented - obsolete error. write a bug report.", "kVLIErrTooMany - too many objects (cut planes) being added to a VLIContext.", "kVLIErrTooLarge - volume is too large to be mapped or locked.", "kVLIErrDuplicate - it is already in the list.", "kVLIErrNoHardware - no VGB board was detected.", "kVLIErrReadOnly - trying to modify read only volume.", "kVLIErrAccess - could not satisfy access request at this time because of current access usage.", "kVLIErrAborted - baseplane is not available because the rendering was aborted.", "kVLIErrBasePlaneAllocation - no pixel buffers available.", "kVLIErrBasePlaneTooLarge - BasePlane is too large for graphics board.", "kVLIErrHardware - undetermined hardware error.", "kVLIErrInternal - internal error; please write a bug report.", "kVLIErrIDRollover - internal IDs have maxed out. Exit all VLI apps and try again.", "kVLIErrVersion - application built against a different version of VLI.", "kVLIErrMaxAngleDeviation - view angle workaround failed.", "not a valid VLI status in VLI 1.0." }; if ((status >= kVLIErrAlloc) && (status <= kVLIErrMaxAngleDeviation)) index = status + kVLITimeout - kVLIErrAlloc + 1; else if ((status >= kVLIOK) && (status <= kVLITimeout)) index = status; else index = sizeof(errStrings)/sizeof(const char *) - 1; return errStrings[index]; }