Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/linmath/compose_matrix_src.I

Go to the documentation of this file.
00001 // Filename: compose_matrix_src.I
00002 // Created by:  drose (21Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: compose_matrix
00022 //  Description: Computes the 4x4 matrix according to scale, rotation,
00023 //               and translation.
00024 ////////////////////////////////////////////////////////////////////
00025 INLINE_LINMATH void
00026 compose_matrix(FLOATNAME(LMatrix4) &mat,
00027                const FLOATNAME(LVecBase3) &scale,
00028                const FLOATNAME(LVecBase3) &hpr,
00029                const FLOATNAME(LVecBase3) &translate,
00030                CoordinateSystem cs) {
00031   FLOATNAME(LMatrix3) upper3;
00032   compose_matrix(upper3, scale, hpr, cs);
00033   mat = FLOATNAME(LMatrix4)(upper3, translate);
00034 }
00035 
00036 INLINE_LINMATH void
00037 compose_matrix(FLOATNAME(LMatrix4) &mat,
00038                const FLOATTYPE components[9],
00039                CoordinateSystem cs) {
00040   FLOATNAME(LVector3) scale(components[0],
00041                             components[1],
00042                             components[2]);
00043   FLOATNAME(LVector3) hpr(components[3],
00044                           components[4],
00045                           components[5]);
00046   FLOATNAME(LVector3) translate(components[6],
00047                                 components[7],
00048                                 components[8]);
00049   compose_matrix(mat, scale, hpr, translate, cs);
00050 }
00051 
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: decompose_matrix
00055 //  Description: Extracts out the components of an affine matrix.
00056 //               Returns true if the scale, hpr, translate
00057 //               completely describe the matrix, or false if there is
00058 //               also a shear component or if the matrix is not
00059 //               affine.
00060 ////////////////////////////////////////////////////////////////////
00061 INLINE_LINMATH bool
00062 decompose_matrix(const FLOATNAME(LMatrix4) &mat,
00063                  FLOATNAME(LVecBase3) &scale,
00064                  FLOATNAME(LVecBase3) &hpr,
00065                  FLOATNAME(LVecBase3) &translate,
00066                  CoordinateSystem cs) {
00067   // Get the translation first.
00068   mat.get_row3(translate,3);
00069   return decompose_matrix(mat.get_upper_3(), scale, hpr, cs);
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: decompose_matrix
00074 //  Description: Extracts out the components of an affine matrix.
00075 //               Returns true if the scale, hpr, translate
00076 //               completely describe the matrix, or false if there is
00077 //               also a shear component or if the matrix is not
00078 //               affine.
00079 //
00080 //               This flavor of the function accepts an expected roll
00081 //               amount.  This amount will be used as the roll
00082 //               component, rather than attempting to determine roll
00083 //               by examining the matrix; this helps alleviate roll
00084 //               instability due to roundoff errors or gimbal lock.
00085 ////////////////////////////////////////////////////////////////////
00086 INLINE_LINMATH bool
00087 decompose_matrix(const FLOATNAME(LMatrix4) &mat,
00088                  FLOATNAME(LVecBase3) &scale,
00089                  FLOATNAME(LVecBase3) &hpr,
00090                  FLOATNAME(LVecBase3) &translate,
00091                  FLOATTYPE roll,
00092                  CoordinateSystem cs) {
00093   // Get the translation first.
00094   mat.get_row3(translate,3);
00095   return decompose_matrix(mat.get_upper_3(), scale, hpr, roll, cs);
00096 }
00097 
00098 INLINE_LINMATH bool
00099 decompose_matrix(const FLOATNAME(LMatrix4) &mat,
00100                  FLOATTYPE components[9],
00101                  CoordinateSystem cs) {
00102   FLOATNAME(LVector3) scale, hpr, translate;
00103   if (!decompose_matrix(mat, scale, hpr, translate, cs)) {
00104     return false;
00105   }
00106   components[0] = scale[0];
00107   components[1] = scale[1];
00108   components[2] = scale[2];
00109   components[3] = hpr[0];
00110   components[4] = hpr[1];
00111   components[5] = hpr[2];
00112   components[6] = translate[0];
00113   components[7] = translate[1];
00114   components[8] = translate[2];
00115   return true;
00116 }

Generated on Fri May 2 00:40:03 2003 for Panda by doxygen1.3