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

panda/src/linmath/lmatrix3_src.I

Go to the documentation of this file.
00001 // Filename: lmatrix3_src.I
00002 // Created by:  drose (29Jan99)
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 //     Function: LMatrix3::ident_mat
00021 //       Access: Public, Static
00022 //  Description: Returns an identity matrix.
00023 //
00024 //               This function definition must appear first, since
00025 //               some inline functions below take advantage of it.
00026 ////////////////////////////////////////////////////////////////////
00027 INLINE_LINMATH const FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00028 ident_mat() {
00029   return _ident_mat;
00030 }
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //     Function: LMatrix3::Default Constructor
00034 //       Access: Public
00035 //  Description:
00036 ////////////////////////////////////////////////////////////////////
00037 INLINE_LINMATH FLOATNAME(LMatrix3)::
00038 FLOATNAME(LMatrix3)() {
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: LMatrix3::Copy Constructor
00043 //       Access: Public
00044 //  Description:
00045 ////////////////////////////////////////////////////////////////////
00046 INLINE_LINMATH FLOATNAME(LMatrix3)::
00047 FLOATNAME(LMatrix3)(const FLOATNAME(LMatrix3) &copy) {
00048         memcpy(_m.data,copy._m.data,sizeof(_m.data));
00049 //  (*this) = copy;
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: LMatrix3::Copy Assignment Operator
00054 //       Access: Public
00055 //  Description:
00056 ////////////////////////////////////////////////////////////////////
00057 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00058 operator = (const FLOATNAME(LMatrix3) &copy) {
00059   memcpy(_m.data,copy._m.data,sizeof(_m.data));
00060 //  set(copy(0, 0), copy(0, 1), copy(0, 2),
00061 //      copy(1, 0), copy(1, 1), copy(1, 2),
00062 //      copy(2, 0), copy(2, 1), copy(2, 2));
00063   return *this;
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: LMatrix3::Fill Assignment Operator
00068 //       Access: Public
00069 //  Description:
00070 ////////////////////////////////////////////////////////////////////
00071 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00072 operator = (FLOATTYPE fill_value) {
00073   fill(fill_value);
00074   return *this;
00075 }
00076 
00077 ////////////////////////////////////////////////////////////////////
00078 //     Function: LMatrix3::Constructor
00079 //       Access: Public
00080 //  Description:
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE_LINMATH FLOATNAME(LMatrix3)::
00083 FLOATNAME(LMatrix3)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02,
00084                     FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12,
00085                     FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22) {
00086   _m.m._00 = e00;
00087   _m.m._01 = e01;
00088   _m.m._02 = e02;
00089   _m.m._10 = e10;
00090   _m.m._11 = e11;
00091   _m.m._12 = e12;
00092   _m.m._20 = e20;
00093   _m.m._21 = e21;
00094   _m.m._22 = e22;
00095 
00096 //  set(e00, e01, e02,
00097 //      e10, e11, e12,
00098 //      e20, e21, e22);
00099 }
00100 
00101 ////////////////////////////////////////////////////////////////////
00102 //     Function: LMatrix3::set
00103 //       Access: Public
00104 //  Description:
00105 ////////////////////////////////////////////////////////////////////
00106 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00107 set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02,
00108     FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12,
00109     FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22) {
00110   _m.m._00 = e00;
00111   _m.m._01 = e01;
00112   _m.m._02 = e02;
00113   _m.m._10 = e10;
00114   _m.m._11 = e11;
00115   _m.m._12 = e12;
00116   _m.m._20 = e20;
00117   _m.m._21 = e21;
00118   _m.m._22 = e22;
00119   /*
00120   _m.m._00 = e00;
00121   _m.m._01 = e01;
00122   _m.m._02 = e02;
00123   _m.m._10 = e10;
00124   _m.m._11 = e11;
00125   _m.m._12 = e12;
00126   _m.m._20 = e20;
00127   _m.m._21 = e21;
00128   _m.m._22 = e22;
00129   */
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////
00133 //     Function: LMatrix3::set_row
00134 //       Access: Public
00135 //  Description: Replaces the indicated row of the matrix from a
00136 //               three-component vector.
00137 ////////////////////////////////////////////////////////////////////
00138 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00139 set_row(int row, const FLOATNAME(LVecBase3) &v) {
00140   (*this)(row, 0) = v._v.v._0;
00141   (*this)(row, 1) = v._v.v._1;
00142   (*this)(row, 2) = v._v.v._2;
00143 }
00144 
00145 ////////////////////////////////////////////////////////////////////
00146 //     Function: LMatrix3::set_column
00147 //       Access: Public
00148 //  Description: Replaces the indicated column of the matrix from a
00149 //               three-component vector.
00150 ////////////////////////////////////////////////////////////////////
00151 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00152 set_col(int col, const FLOATNAME(LVecBase3) &v) {
00153   (*this)(0, col) = v._v.v._0;
00154   (*this)(1, col) = v._v.v._1;
00155   (*this)(2, col) = v._v.v._2;
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: LMatrix3::set_row
00160 //       Access: Public
00161 //  Description: Replaces the indicated row of the matrix from a
00162 //               two-component vector, ignoring the last column.
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00165 set_row(int row, const FLOATNAME(LVecBase2) &v) {
00166   (*this)(row, 0) = v._v.v._0;
00167   (*this)(row, 1) = v._v.v._1;
00168 }
00169 
00170 ////////////////////////////////////////////////////////////////////
00171 //     Function: LMatrix3::set_column
00172 //       Access: Public
00173 //  Description: Replaces the indicated column of the matrix from a
00174 //               two-component vector, ignoring the last row.
00175 ////////////////////////////////////////////////////////////////////
00176 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00177 set_col(int col, const FLOATNAME(LVecBase2) &v) {
00178   (*this)(0, col) = v._v.v._0;
00179   (*this)(1, col) = v._v.v._1;
00180 }
00181 
00182 ////////////////////////////////////////////////////////////////////
00183 //     Function: LMatrix3::get_row
00184 //       Access: Public
00185 //  Description: Returns the indicated row of the matrix as a
00186 //               three-component vector.
00187 ////////////////////////////////////////////////////////////////////
00188 INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix3)::
00189 get_row(int row) const {
00190   return FLOATNAME(LVecBase3)((*this)(row, 0), (*this)(row, 1), (*this)(row, 2));
00191 }
00192 
00193 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00194 get_row(FLOATNAME(LVecBase3) &result_vec,int row) const {
00195   result_vec._v.v._0 = (*this)(row, 0);
00196   result_vec._v.v._1 = (*this)(row, 1);
00197   result_vec._v.v._2 = (*this)(row, 2);
00198 }
00199 
00200 ////////////////////////////////////////////////////////////////////
00201 //     Function: LMatrix3::get_col
00202 //       Access: Public
00203 //  Description: Returns the indicated column of the matrix as a
00204 //               three-component vector.
00205 ////////////////////////////////////////////////////////////////////
00206 INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix3)::
00207 get_col(int col) const {
00208   return FLOATNAME(LVecBase3)((*this)(0, col), (*this)(1, col), (*this)(2, col));
00209 }
00210 
00211 ////////////////////////////////////////////////////////////////////
00212 //     Function: LMatrix3::get_row2
00213 //       Access: Public
00214 //  Description: Returns the indicated row of the matrix as a
00215 //               two-component vector, ignoring the last column.
00216 ////////////////////////////////////////////////////////////////////
00217 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3)::
00218 get_row2(int row) const {
00219   return FLOATNAME(LVecBase2)((*this)(row, 0), (*this)(row, 1));
00220 }
00221 
00222 ////////////////////////////////////////////////////////////////////
00223 //     Function: LMatrix3::get_col2
00224 //       Access: Public
00225 //  Description: Returns the indicated column of the matrix as a
00226 //               two-component vector, ignoring the last row.
00227 ////////////////////////////////////////////////////////////////////
00228 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3)::
00229 get_col2(int col) const {
00230   return FLOATNAME(LVecBase2)((*this)(0, col), (*this)(1, col));
00231 }
00232 
00233 ////////////////////////////////////////////////////////////////////
00234 //     Function: LMatrix3::Indexing operator
00235 //       Access: Public
00236 //  Description:
00237 ////////////////////////////////////////////////////////////////////
00238 INLINE_LINMATH FLOATTYPE &FLOATNAME(LMatrix3)::
00239 operator () (int row, int col) {
00240   nassertr(row >= 0 && row < 3 && col >= 0 && col < 3, _m.data[0]);
00241   return _m.data[row * 3 + col];
00242 }
00243 
00244 ////////////////////////////////////////////////////////////////////
00245 //     Function: LMatrix3::Indexing operator
00246 //       Access: Public
00247 //  Description:
00248 ////////////////////////////////////////////////////////////////////
00249 INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3)::
00250 operator () (int row, int col) const {
00251   nassertr(row >= 0 && row < 3 && col >= 0 && col < 3, 0.0);
00252   return _m.data[row * 3 + col];
00253 }
00254 
00255 ////////////////////////////////////////////////////////////////////
00256 //     Function: LMatrix3::is_nan
00257 //       Access: Public
00258 //  Description: Returns true if any component of the matrix is
00259 //               not-a-number, false otherwise.
00260 ////////////////////////////////////////////////////////////////////
00261 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00262 is_nan() const {
00263   return
00264     cnan(_m.data[0]) || cnan(_m.data[1]) || cnan(_m.data[2]) ||
00265     cnan(_m.data[3]) || cnan(_m.data[4]) || cnan(_m.data[5]) ||
00266     cnan(_m.data[6]) || cnan(_m.data[7]) || cnan(_m.data[8]);
00267 }
00268 
00269 ////////////////////////////////////////////////////////////////////
00270 //     Function: LMatrix3::get_cell
00271 //       Access: Public
00272 //  Description: Returns a particular element of the matrix.
00273 ////////////////////////////////////////////////////////////////////
00274 INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3)::
00275 get_cell(int row, int col) const {
00276   nassertr(row >= 0 && row < 3 && col >= 0 && col < 3, 0.0);
00277   return _m.data[row * 3 + col];
00278 }
00279 
00280 ////////////////////////////////////////////////////////////////////
00281 //     Function: LMatrix3::set_cell
00282 //       Access: Public
00283 //  Description: Changes a particular element of the matrix.
00284 ////////////////////////////////////////////////////////////////////
00285 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00286 set_cell(int row, int col, FLOATTYPE value) {
00287   nassertv(row >= 0 && row < 3 && col >= 0 && col < 3);
00288   _m.data[row * 3 + col] = value;
00289 }
00290 
00291 ////////////////////////////////////////////////////////////////////
00292 //     Function: LMatrix3::get_data
00293 //       Access: Public
00294 //  Description: Returns the address of the first of the nine data
00295 //               elements in the matrix.  The remaining elements
00296 //               occupy the next eight positions in row-major order.
00297 ////////////////////////////////////////////////////////////////////
00298 INLINE_LINMATH const FLOATTYPE *FLOATNAME(LMatrix3)::
00299 get_data() const {
00300   return _m.data;
00301 }
00302 
00303 ////////////////////////////////////////////////////////////////////
00304 //     Function: LMatrix3::get_num_components
00305 //       Access: Public
00306 //  Description: Returns the number of elements in the matrix, nine.
00307 ////////////////////////////////////////////////////////////////////
00308 INLINE_LINMATH int FLOATNAME(LMatrix3)::
00309 get_num_components() const {
00310   return 9;
00311 }
00312 
00313 ////////////////////////////////////////////////////////////////////
00314 //     Function: LMatrix3::begin
00315 //       Access: Public
00316 //  Description: Returns an iterator that may be used to traverse the
00317 //               elements of the matrix, STL-style.
00318 ////////////////////////////////////////////////////////////////////
00319 INLINE_LINMATH FLOATNAME(LMatrix3)::iterator FLOATNAME(LMatrix3)::
00320 begin() {
00321   return _m.data;
00322 }
00323 
00324 ////////////////////////////////////////////////////////////////////
00325 //     Function: LMatrix3::end
00326 //       Access: Public
00327 //  Description: Returns an iterator that may be used to traverse the
00328 //               elements of the matrix, STL-style.
00329 ////////////////////////////////////////////////////////////////////
00330 INLINE_LINMATH FLOATNAME(LMatrix3)::iterator FLOATNAME(LMatrix3)::
00331 end() {
00332   return begin() + get_num_components();
00333 }
00334 
00335 ////////////////////////////////////////////////////////////////////
00336 //     Function: LMatrix3::begin
00337 //       Access: Public
00338 //  Description: Returns an iterator that may be used to traverse the
00339 //               elements of the matrix, STL-style.
00340 ////////////////////////////////////////////////////////////////////
00341 INLINE_LINMATH FLOATNAME(LMatrix3)::const_iterator FLOATNAME(LMatrix3)::
00342 begin() const {
00343   return _m.data;
00344 }
00345 
00346 ////////////////////////////////////////////////////////////////////
00347 //     Function: LMatrix3::end
00348 //       Access: Public
00349 //  Description: Returns an iterator that may be used to traverse the
00350 //               elements of the matrix, STL-style.
00351 ////////////////////////////////////////////////////////////////////
00352 INLINE_LINMATH FLOATNAME(LMatrix3)::const_iterator FLOATNAME(LMatrix3)::
00353 end() const {
00354   return begin() + get_num_components();
00355 }
00356 
00357 ////////////////////////////////////////////////////////////////////
00358 //     Function: LMatrix3::Ordering Operator
00359 //       Access: Public
00360 //  Description: This performs a lexicographical comparison.  It's of
00361 //               questionable mathematical meaning, but sometimes has
00362 //               a practical purpose for sorting unique vectors,
00363 //               especially in an STL container.  Also see
00364 //               compare_to().
00365 ////////////////////////////////////////////////////////////////////
00366 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00367 operator < (const FLOATNAME(LMatrix3) &other) const {
00368   return compare_to(other) < 0;
00369 }
00370 
00371 ////////////////////////////////////////////////////////////////////
00372 //     Function: LMatrix3::Equality Operator
00373 //       Access: Public
00374 //  Description:
00375 ////////////////////////////////////////////////////////////////////
00376 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00377 operator == (const FLOATNAME(LMatrix3) &other) const {
00378   return compare_to(other) == 0;
00379 }
00380 
00381 ////////////////////////////////////////////////////////////////////
00382 //     Function: LMatrix3::Inequality Operator
00383 //       Access: Public
00384 //  Description:
00385 ////////////////////////////////////////////////////////////////////
00386 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00387 operator != (const FLOATNAME(LMatrix3) &other) const {
00388   return !operator == (other);
00389 }
00390 
00391 ////////////////////////////////////////////////////////////////////
00392 //     Function: LMatrix3::compare_to
00393 //       Access: Public
00394 //  Description: This flavor of compare_to uses a default threshold
00395 //               value based on the numeric type.
00396 ////////////////////////////////////////////////////////////////////
00397 INLINE_LINMATH int FLOATNAME(LMatrix3)::
00398 compare_to(const FLOATNAME(LMatrix3) &other) const {
00399   return compare_to(other, NEARLY_ZERO(FLOATTYPE));
00400 }
00401 
00402 #define VECTOR3_MATRIX3_PRODUCT(v_res, v, mat)                                              \
00403 v_res._v.v._0 = v._v.v._0*mat._m.m._00 + v._v.v._1*mat._m.m._10 + v._v.v._2*mat._m.m._20;   \
00404 v_res._v.v._1 = v._v.v._0*mat._m.m._01 + v._v.v._1*mat._m.m._11 + v._v.v._2*mat._m.m._21;   \
00405 v_res._v.v._2 = v._v.v._0*mat._m.m._02 + v._v.v._1*mat._m.m._12 + v._v.v._2*mat._m.m._22;
00406 
00407 // bugbug:  need 2 check if this is correct, or reversed from previous implementation
00408 //          before checkin
00409 
00410 ////////////////////////////////////////////////////////////////////
00411 //     Function: LMatrix3::xform
00412 //       Access: Public
00413 //  Description: 3-component vector or point times matrix.  This is a
00414 //               fully general operation.
00415 ////////////////////////////////////////////////////////////////////
00416 INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LMatrix3)::
00417 xform(const FLOATNAME(LVecBase3) &v) const {
00418     FLOATNAME(LVecBase3) v_res;
00419 
00420 
00421 
00422         VECTOR3_MATRIX3_PRODUCT(v_res, v,(*this));
00423 
00424 
00425 
00426         return v_res;
00427 
00428 //  return FLOATNAME(LVecBase3)(v.dot(get_col(0)),
00429 //                          v.dot(get_col(1)),
00430 //                          v.dot(get_col(2)));
00431 }
00432 
00433 ////////////////////////////////////////////////////////////////////
00434 //     Function: LMatrix3::xform_point
00435 //       Access: Public
00436 //  Description: The matrix transforms a 2-component point (including
00437 //               translation component) and returns the result.  This
00438 //               assumes the matrix is an affine transform.
00439 ////////////////////////////////////////////////////////////////////
00440 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3)::
00441 xform_point(const FLOATNAME(LVecBase2) &v) const {
00442 
00443         FLOATNAME(LVecBase2) v_res;
00444 
00445         // v._v.v._2 == 1.0f for this case
00446 
00447         v_res._v.v._0 = v._v.v._0*_m.m._00 + v._v.v._1*_m.m._10 + _m.m._20;
00448         v_res._v.v._1 = v._v.v._0*_m.m._01 + v._v.v._1*_m.m._11 + _m.m._21;
00449 
00450         return v_res;
00451 
00452 //  return FLOATNAME(LVecBase2)(v.dot(get_col2(0)) + _m.m._20,
00453 //                          v.dot(get_col2(1)) + _m.m._21);
00454 }
00455 
00456 ////////////////////////////////////////////////////////////////////
00457 //     Function: LMatrix3::xform_vec
00458 //       Access: Public
00459 //  Description: The matrix transforms a 2-component vector (without
00460 //               translation component) and returns the result.  This
00461 //               assumes the matrix is an affine transform.
00462 ////////////////////////////////////////////////////////////////////
00463 INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LMatrix3)::
00464 xform_vec(const FLOATNAME(LVecBase2) &v) const {
00465 
00466         FLOATNAME(LVecBase2) v_res;
00467 
00468         // v._v.v._2 == 0.0f for this case
00469 
00470         v_res._v.v._0 = v._v.v._0*_m.m._00 + v._v.v._1*_m.m._10;
00471         v_res._v.v._1 = v._v.v._0*_m.m._01 + v._v.v._1*_m.m._11;
00472 
00473         return v_res;
00474 
00475 //  return FLOATNAME(LVecBase2)(v.dot(get_col2(0)),
00476 //                          v.dot(get_col2(1)));
00477 }
00478 
00479 ////////////////////////////////////////////////////////////////////
00480 //     Function: LMatrix3::mult_cel
00481 //       Access: Private
00482 //  Description: Returns one cell of the result of a matrix-matrix
00483 //               multiplication operation.
00484 ////////////////////////////////////////////////////////////////////
00485 INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3)::
00486 mult_cel(const FLOATNAME(LMatrix3) &other, int row, int col) const {
00487     return get_row(row).dot(other.get_col(col));
00488 }
00489 
00490 
00491 #define MATRIX3_PRODUCT(res, a, b)                   \
00492 res._m.m._00 = a._m.m._00*b._m.m._00 + a._m.m._01*b._m.m._10 + a._m.m._02*b._m.m._20;   \
00493 res._m.m._01 = a._m.m._00*b._m.m._01 + a._m.m._01*b._m.m._11 + a._m.m._02*b._m.m._21;   \
00494 res._m.m._02 = a._m.m._00*b._m.m._02 + a._m.m._01*b._m.m._12 + a._m.m._02*b._m.m._22;   \
00495 res._m.m._10 = a._m.m._10*b._m.m._00 + a._m.m._11*b._m.m._10 + a._m.m._12*b._m.m._20;   \
00496 res._m.m._11 = a._m.m._10*b._m.m._01 + a._m.m._11*b._m.m._11 + a._m.m._12*b._m.m._21;   \
00497 res._m.m._12 = a._m.m._10*b._m.m._02 + a._m.m._11*b._m.m._12 + a._m.m._12*b._m.m._22;   \
00498 res._m.m._20 = a._m.m._20*b._m.m._00 + a._m.m._21*b._m.m._10 + a._m.m._22*b._m.m._20;   \
00499 res._m.m._21 = a._m.m._20*b._m.m._01 + a._m.m._21*b._m.m._11 + a._m.m._22*b._m.m._21;   \
00500 res._m.m._22 = a._m.m._20*b._m.m._02 + a._m.m._21*b._m.m._12 + a._m.m._22*b._m.m._22;
00501 
00502 
00503 ////////////////////////////////////////////////////////////////////
00504 //     Function: LMatrix3::matrix * matrix
00505 //       Access: Public
00506 //  Description:
00507 ////////////////////////////////////////////////////////////////////
00508 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00509 operator * (const FLOATNAME(LMatrix3) &other) const {
00510         FLOATNAME(LMatrix3) t;
00511 
00512         MATRIX3_PRODUCT(t,(*this),other);
00513 /*
00514 typedef union {
00515         struct {
00516             FLOATTYPE     _m.m._11, _m.m._12, _m.m._13;
00517             FLOATTYPE     _m.m._21, _m.m._22, _m.m._23;
00518             FLOATTYPE     _m.m._31, _m.m._32, _m.m._33;
00519         };
00520 
00521                 FLOATTYPE m[3][3];
00522     } MYMATRIX3;
00523 
00524         FLOATNAME(LMatrix3) t;
00525 
00526         MYMATRIX3 *result_ptr=(MYMATRIX3 *)t.get_m.data();
00527         MYMATRIX3 *mat1_ptr=(MYMATRIX3 *)this->get_m.data();
00528         MYMATRIX3 *mat2_ptr=(MYMATRIX3 *)other.get_m.data();
00529 
00530         MATRIX3_PRODUCT(result_ptr,mat1_ptr,mat2_ptr);
00531 */
00532 /*
00533   t(0, 0) = mult_cel(other, 0, 0);
00534   t(0, 1) = mult_cel(other, 0, 1);
00535   t(0, 2) = mult_cel(other, 0, 2);
00536 
00537   t(1, 0) = mult_cel(other, 1, 0);
00538   t(1, 1) = mult_cel(other, 1, 1);
00539   t(1, 2) = mult_cel(other, 1, 2);
00540 
00541   t(2, 0) = mult_cel(other, 2, 0);
00542   t(2, 1) = mult_cel(other, 2, 1);
00543   t(2, 2) = mult_cel(other, 2, 2);
00544 */
00545   return t;
00546 }
00547 
00548 // this = other1 * other2
00549 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00550 multiply(const FLOATNAME(LMatrix3) &other1, const FLOATNAME(LMatrix3) &other2) {
00551 // faster than operator * since it writes result in place, avoiding extra copying
00552 // this will fail if you try to mat.multiply(mat,other_mat)
00553 
00554   #ifdef _DEBUG
00555      assert((&other1 != this) && (&other2 != this));
00556   #endif
00557 
00558   MATRIX3_PRODUCT((*this),other1,other2);
00559 }
00560 
00561 // this = scale_mat(scale_vector) * other_mat, efficiently
00562 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00563 scale_multiply(const FLOATNAME(LVecBase3) &scale_vector,const FLOATNAME(LMatrix3) &other_mat) {
00564   #ifdef _DEBUG
00565      assert(&other_mat != this);
00566   #endif
00567 
00568    // optimize for 0.0 or 1.0 factors?
00569 
00570   _m.m._00 = other_mat._m.m._00 * scale_vector._v.v._0;
00571   _m.m._01 = other_mat._m.m._01 * scale_vector._v.v._0;
00572   _m.m._02 = other_mat._m.m._02 * scale_vector._v.v._0;
00573 
00574   _m.m._10 = other_mat._m.m._10 * scale_vector._v.v._1;
00575   _m.m._11 = other_mat._m.m._11 * scale_vector._v.v._1;
00576   _m.m._12 = other_mat._m.m._12 * scale_vector._v.v._1;
00577 
00578   _m.m._20 = other_mat._m.m._20 * scale_vector._v.v._2;
00579   _m.m._21 = other_mat._m.m._21 * scale_vector._v.v._2;
00580   _m.m._22 = other_mat._m.m._22 * scale_vector._v.v._2;
00581 }
00582 
00583 ////////////////////////////////////////////////////////////////////
00584 //     Function: LMatrix3::matrix * scalar
00585 //       Access: Public
00586 //  Description:
00587 ////////////////////////////////////////////////////////////////////
00588 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00589 operator * (FLOATTYPE scalar) const {
00590   FLOATNAME(LMatrix3) t;
00591 
00592   t._m.m._00 = _m.m._00 * scalar;
00593   t._m.m._01 = _m.m._01 * scalar;
00594   t._m.m._02 = _m.m._02 * scalar;
00595 
00596   t._m.m._10 = _m.m._10 * scalar;
00597   t._m.m._11 = _m.m._11 * scalar;
00598   t._m.m._12 = _m.m._12 * scalar;
00599 
00600   t._m.m._20 = _m.m._20 * scalar;
00601   t._m.m._21 = _m.m._21 * scalar;
00602   t._m.m._22 = _m.m._22 * scalar;
00603 
00604   return t;
00605 }
00606 
00607 ////////////////////////////////////////////////////////////////////
00608 //     Function: LMatrix3::matrix / scalar
00609 //       Access: Public
00610 //  Description:
00611 ////////////////////////////////////////////////////////////////////
00612 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00613 operator / (FLOATTYPE scalar) const {
00614   FLOATTYPE recip_scalar = 1.0f/scalar;
00615   return (*this) * recip_scalar;
00616 }
00617 
00618 ////////////////////////////////////////////////////////////////////
00619 //     Function: LMatrix3::matrix += matrix
00620 //       Access: Public
00621 //  Description: Performs a memberwise addition between two matrices.
00622 ////////////////////////////////////////////////////////////////////
00623 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00624 operator += (const FLOATNAME(LMatrix3) &other) {
00625   _m.m._00 += other._m.m._00;
00626   _m.m._01 += other._m.m._01;
00627   _m.m._02 += other._m.m._02;
00628 
00629   _m.m._10 += other._m.m._10;
00630   _m.m._11 += other._m.m._11;
00631   _m.m._12 += other._m.m._12;
00632 
00633   _m.m._20 += other._m.m._20;
00634   _m.m._21 += other._m.m._21;
00635   _m.m._22 += other._m.m._22;
00636 
00637   return *this;
00638 }
00639 
00640 ////////////////////////////////////////////////////////////////////
00641 //     Function: LMatrix3::matrix -= matrix
00642 //       Access: Public
00643 //  Description: Performs a memberwise subtraction between two matrices.
00644 ////////////////////////////////////////////////////////////////////
00645 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00646 operator -= (const FLOATNAME(LMatrix3) &other) {
00647   _m.m._00 -= other._m.m._00;
00648   _m.m._01 -= other._m.m._01;
00649   _m.m._02 -= other._m.m._02;
00650 
00651   _m.m._10 -= other._m.m._10;
00652   _m.m._11 -= other._m.m._11;
00653   _m.m._12 -= other._m.m._12;
00654 
00655   _m.m._20 -= other._m.m._20;
00656   _m.m._21 -= other._m.m._21;
00657   _m.m._22 -= other._m.m._22;
00658 
00659   return *this;
00660 }
00661 
00662 ////////////////////////////////////////////////////////////////////
00663 //     Function: LMatrix3::matrix *= matrix
00664 //       Access: Public
00665 //  Description:
00666 ////////////////////////////////////////////////////////////////////
00667 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00668 operator *= (const FLOATNAME(LMatrix3) &other) {
00669   (*this) = (*this) * other;
00670 
00671   // bugbug can we do any optimization here?
00672   return *this;
00673 }
00674 
00675 ////////////////////////////////////////////////////////////////////
00676 //     Function: LMatrix3::matrix *= scalar
00677 //       Access: Public
00678 //  Description: Performs a memberwise scale.
00679 ////////////////////////////////////////////////////////////////////
00680 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00681 operator *= (FLOATTYPE scalar) {
00682   _m.m._00 *= scalar;
00683   _m.m._01 *= scalar;
00684   _m.m._02 *= scalar;
00685 
00686   _m.m._10 *= scalar;
00687   _m.m._11 *= scalar;
00688   _m.m._12 *= scalar;
00689 
00690   _m.m._20 *= scalar;
00691   _m.m._21 *= scalar;
00692   _m.m._22 *= scalar;
00693 
00694   return *this;
00695 }
00696 
00697 ////////////////////////////////////////////////////////////////////
00698 //     Function: LMatrix3::matrix /= scalar
00699 //       Access: Public
00700 //  Description: Performs a memberwise scale.
00701 ////////////////////////////////////////////////////////////////////
00702 INLINE_LINMATH FLOATNAME(LMatrix3) &FLOATNAME(LMatrix3)::
00703 operator /= (FLOATTYPE scalar) {
00704   FLOATTYPE recip_scalar = 1.0f/scalar;
00705   _m.m._00 *= recip_scalar;
00706   _m.m._01 *= recip_scalar;
00707   _m.m._02 *= recip_scalar;
00708 
00709   _m.m._10 *= recip_scalar;
00710   _m.m._11 *= recip_scalar;
00711   _m.m._12 *= recip_scalar;
00712 
00713   _m.m._20 *= recip_scalar;
00714   _m.m._21 *= recip_scalar;
00715   _m.m._22 *= recip_scalar;
00716 
00717   return *this;
00718 }
00719 
00720 ////////////////////////////////////////////////////////////////////
00721 //     Function: LMatrix3::transpose_from
00722 //       Access: Public
00723 //  Description:
00724 ////////////////////////////////////////////////////////////////////
00725 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00726 transpose_from(const FLOATNAME(LMatrix3) &other) {
00727   _m.m._00 = other._m.m._00;
00728   _m.m._01 = other._m.m._10;
00729   _m.m._02 = other._m.m._20;
00730 
00731   _m.m._10 = other._m.m._01;
00732   _m.m._11 = other._m.m._11;
00733   _m.m._12 = other._m.m._21;
00734 
00735   _m.m._20 = other._m.m._02;
00736   _m.m._21 = other._m.m._12;
00737   _m.m._22 = other._m.m._22;
00738 }
00739 
00740 
00741 ////////////////////////////////////////////////////////////////////
00742 //     Function: LMatrix3::transpose_in_place
00743 //       Access: Public
00744 //  Description:
00745 ////////////////////////////////////////////////////////////////////
00746 INLINE_LINMATH void FLOATNAME(LMatrix3)::
00747 transpose_in_place() {
00748 //  FLOATNAME(LMatrix3) temp = (*this);
00749 //  transpose_from(temp);
00750 
00751   #define SWAP__(x,y) { FLOATTYPE temp = (x);  (x) = (y);  (y) = temp;}
00752   SWAP__(_m.m._01,_m.m._10);
00753   SWAP__(_m.m._02,_m.m._20);
00754   SWAP__(_m.m._12,_m.m._21);
00755   #undef SWAP__
00756 }
00757 
00758 // Matrix inversion code from Numerical Recipes in C.
00759 
00760 // dont trust compilers to inline these
00761 #define DET2(E00,E01,E10,E11) ((E00)*(E11) - (E10)*(E01))
00762 #define MATRIX3_DETERMINANT(mat)                                  \
00763    ( (mat)._00 * DET2((mat)._11,(mat)._12,(mat)._21,(mat)._22)    \
00764     -(mat)._01 * DET2((mat)._10,(mat)._12,(mat)._20,(mat)._22)    \
00765     +(mat)._02 * DET2((mat)._10,(mat)._11,(mat)._20,(mat)._21))
00766 
00767 
00768 ////////////////////////////////////////////////////////////////////
00769 //     Function: LMatrix3::det2
00770 //       Access: Private, Static
00771 //  Description: Returns the determinant of a 2x2 matrix.
00772 ////////////////////////////////////////////////////////////////////
00773 INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3)::
00774 det2(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e10, FLOATTYPE e11) const {
00775 //  return (e00 * e11 - e10 * e01);
00776         return DET2(e00,e01,e10,e11);
00777 }
00778 
00779 ////////////////////////////////////////////////////////////////////
00780 //     Function: LMatrix3::determinant
00781 //       Access: Public
00782 //  Description: Returns the determinant of the matrix.
00783 ////////////////////////////////////////////////////////////////////
00784 INLINE_LINMATH FLOATTYPE FLOATNAME(LMatrix3)::
00785 determinant() const {
00786 /*
00787   return
00788     (*this)(0,0) * det2((*this)(1,1),(*this)(1,2),(*this)(2,1),(*this)(2,2))
00789     -(*this)(0,1) * det2((*this)(1,0),(*this)(1,2),(*this)(2,0),(*this)(2,2))
00790     +(*this)(0,2) * det2((*this)(1,0),(*this)(1,1),(*this)(2,0),(*this)(2,1));
00791 */
00792 
00793  return MATRIX3_DETERMINANT(_m.m);
00794 }
00795 
00796 ////////////////////////////////////////////////////////////////////
00797 //     Function: LMatrix3::invert_from
00798 //       Access: Public
00799 //  Description: Computes the inverse of the other matrix, and stores
00800 //               the result in this matrix.  This is a fully general
00801 //               operation and makes no assumptions about the type of
00802 //               transform represented by the matrix.
00803 //
00804 //               The other matrix must be a different object than this
00805 //               matrix.  However, if you need to invert a matrix in
00806 //               place, see invert_in_place.
00807 //
00808 //               The return value is true if the matrix was
00809 //               successfully inverted, false if the was a
00810 //               singularity.
00811 ////////////////////////////////////////////////////////////////////
00812 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00813 invert_from(const FLOATNAME(LMatrix3) &other) {
00814 
00815   FLOATTYPE other_det = MATRIX3_DETERMINANT(other._m.m);
00816 
00817   // We throw the value out only if it's smaller than our "small"
00818   // threshold squared.  This helps reduce overly-sensitive
00819   // rejections.
00820   if (IS_THRESHOLD_ZERO(other_det, (NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE)))) {
00821     //    if (IS_NEARLY_ZERO(other_det)) {
00822 #ifdef NOTIFY_DEBUG
00823     linmath_cat.warning() << "Tried to invert singular LMatrix3.\n";
00824 #endif
00825     (*this) = ident_mat();
00826     return false;
00827   }
00828 
00829   other_det = 1.0f / other_det;
00830   _m.m._00 =  other_det * DET2(other._m.m._11, other._m.m._12, other._m.m._21, other._m.m._22);
00831   _m.m._10 = -other_det * DET2(other._m.m._10, other._m.m._12, other._m.m._20, other._m.m._22);
00832   _m.m._20 =  other_det * DET2(other._m.m._10, other._m.m._11, other._m.m._20, other._m.m._21);
00833 
00834   _m.m._01 = -other_det * DET2(other._m.m._01, other._m.m._02, other._m.m._21, other._m.m._22);
00835   _m.m._11 =  other_det * DET2(other._m.m._00, other._m.m._02, other._m.m._20, other._m.m._22);
00836   _m.m._21 = -other_det * DET2(other._m.m._00, other._m.m._01, other._m.m._20, other._m.m._21);
00837 
00838   _m.m._02 =  other_det * DET2(other._m.m._01, other._m.m._02, other._m.m._11, other._m.m._12);
00839   _m.m._12 = -other_det * DET2(other._m.m._00, other._m.m._02, other._m.m._10, other._m.m._12);
00840   _m.m._22 =  other_det * DET2(other._m.m._00, other._m.m._01, other._m.m._10, other._m.m._11);
00841 
00842   return true;
00843 }
00844 
00845 ////////////////////////////////////////////////////////////////////
00846 //     Function: LMatrix3::invert_in_place
00847 //       Access: Public
00848 //  Description: Inverts the current matrix.  Returns true if the
00849 //               inverse is successful, false if the matrix was
00850 //               singular.
00851 ////////////////////////////////////////////////////////////////////
00852 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
00853 invert_in_place() {
00854   FLOATNAME(LMatrix3) temp = (*this);
00855   return invert_from(temp);
00856 }
00857 
00858 ////////////////////////////////////////////////////////////////////
00859 //     Function: LMatrix::translate_mat
00860 //       Access: Public, Static
00861 //  Description: Returns a matrix that applies the indicated
00862 //               translation.
00863 ////////////////////////////////////////////////////////////////////
00864 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00865 translate_mat(const FLOATNAME(LVecBase2) &trans) {
00866   return FLOATNAME(LMatrix3)(1.0f, 0.0f, 0.0f,
00867                            0.0f, 1.0f, 0.0f,
00868                            trans._v.v._0, trans._v.v._1, 1.0f);
00869 }
00870 
00871 ////////////////////////////////////////////////////////////////////
00872 //     Function: LMatrix::translate_mat
00873 //       Access: Public, Static
00874 //  Description: Returns a matrix that applies the indicated
00875 //               translation.
00876 ////////////////////////////////////////////////////////////////////
00877 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00878 translate_mat(FLOATTYPE tx, FLOATTYPE ty) {
00879   return FLOATNAME(LMatrix3)(1.0f, 0.0f, 0.0f,
00880                            0.0f, 1.0f, 0.0f,
00881                            tx, ty, 1.0f);
00882 }
00883 
00884 ////////////////////////////////////////////////////////////////////
00885 //     Function: LMatrix::rotate_mat
00886 //       Access: Public, Static
00887 //  Description: Returns a matrix that rotates by the given angle in
00888 //               degrees counterclockwise.
00889 ////////////////////////////////////////////////////////////////////
00890 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00891 rotate_mat(FLOATTYPE angle) {
00892   FLOATTYPE angle_rad=deg_2_rad(angle);
00893   FLOATTYPE s,c;
00894   csincos(angle_rad,&s,&c);
00895   return FLOATNAME(LMatrix3)(  c,    s,  0.0f,
00896                               -s,    c,  0.0f,
00897                              0.0f,  0.0f,  1.0f);
00898 }
00899 
00900 ////////////////////////////////////////////////////////////////////
00901 //     Function: LMatrix::scale_mat
00902 //       Access: Public, Static
00903 //  Description: Returns a matrix that applies the indicated
00904 //               scale in each of the two axes.
00905 ////////////////////////////////////////////////////////////////////
00906 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00907 scale_mat(const FLOATNAME(LVecBase2) &scale) {
00908   return FLOATNAME(LMatrix3)(scale._v.v._0, 0.0f, 0.0f,
00909                              0.0f, scale._v.v._1, 0.0f,
00910                              0.0f, 0.0f, 1.0f);
00911 }
00912 
00913 ////////////////////////////////////////////////////////////////////
00914 //     Function: LMatrix::scale_mat
00915 //       Access: Public, Static
00916 //  Description: Returns a matrix that applies the indicated
00917 //               scale in each of the two axes.
00918 ////////////////////////////////////////////////////////////////////
00919 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00920 scale_mat(FLOATTYPE sx, FLOATTYPE sy) {
00921   return FLOATNAME(LMatrix3)(sx, 0.0f, 0.0f,
00922                              0.0f, sy, 0.0f,
00923                              0.0f, 0.0f, 1.0f);
00924 }
00925 
00926 ////////////////////////////////////////////////////////////////////
00927 //     Function: LMatrix::rotate_mat
00928 //       Access: Public, Static
00929 //  Description: Returns a matrix that rotates by the given angle in
00930 //               degrees counterclockwise about the indicated vector.
00931 ////////////////////////////////////////////////////////////////////
00932 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
00933 rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) axis,
00934            CoordinateSystem cs) {
00935   if (cs == CS_default) {
00936     cs = default_coordinate_system;
00937   }
00938   FLOATNAME(LMatrix3) mat;
00939 
00940   if(IS_LEFT_HANDED_COORDSYSTEM(cs)) {
00941     // In a left-handed coordinate system, counterclockwise is the
00942     // other direction.
00943     angle = -angle;
00944   }
00945 
00946   FLOATTYPE axis_0 = axis._v.v._0;
00947   FLOATTYPE axis_1 = axis._v.v._1;
00948   FLOATTYPE axis_2 = axis._v.v._2;
00949 
00950   // Normalize the axis.
00951   FLOATTYPE length_sq = axis_0 * axis_0 + axis_1 * axis_1 + axis_2 * axis_2;
00952 #ifdef _DEBUG
00953   nassertr(length_sq != 0.0f, ident_mat());
00954 #endif
00955   FLOATTYPE recip_length = 1.0f/csqrt(length_sq);
00956 
00957   axis_0 *= recip_length;
00958   axis_1 *= recip_length;
00959   axis_2 *= recip_length;
00960 
00961   FLOATTYPE angle_rad=deg_2_rad(angle);
00962   FLOATTYPE s,c;
00963   csincos(angle_rad,&s,&c);
00964   FLOATTYPE t = 1.0f - c;
00965 
00966   FLOATTYPE t0,t1,t2,s0,s1,s2;
00967 
00968   t0 = t * axis_0;
00969   t1 = t * axis_1;
00970   t2 = t * axis_2;
00971   s0 = s * axis_0;
00972   s1 = s * axis_1;
00973   s2 = s * axis_2;
00974 
00975   mat._m.m._00 = t0 * axis_0 + c;
00976   mat._m.m._01 = t0 * axis_1 + s2;
00977   mat._m.m._02 = t0 * axis_2 - s1;
00978 
00979   mat._m.m._10 = t1 * axis_0 - s2;
00980   mat._m.m._11 = t1 * axis_1 + c;
00981   mat._m.m._12 = t1 * axis_2 + s0;
00982 
00983   mat._m.m._20 = t2 * axis_0 + s1;
00984   mat._m.m._21 = t2 * axis_1 - s0;
00985   mat._m.m._22 = t2 * axis_2 + c;
00986 
00987 /*
00988   mat._m.m._00 = t * axis._v.v._0 * axis._v.v._0 + c;
00989   mat._m.m._01 = t * axis._v.v._0 * axis._v.v._1 + s * axis._v.v._2;
00990   mat._m.m._02 = t * axis._v.v._0 * axis._v.v._2 - s * axis._v.v._1;
00991 
00992   mat._m.m._10 = t * axis._v.v._1 * axis._v.v._0 - s * axis._v.v._2;
00993   mat._m.m._11 = t * axis._v.v._1 * axis._v.v._1 + c;
00994   mat._m.m._12 = t * axis._v.v._1 * axis._v.v._2 + s * axis._v.v._0;
00995 
00996   mat._m.m._20 = t * axis._v.v._2 * axis._v.v._0 + s * axis._v.v._1;
00997   mat._m.m._21 = t * axis._v.v._2 * axis._v.v._1 - s * axis._v.v._0;
00998   mat._m.m._22 = t * axis._v.v._2 * axis._v.v._2 + c;
00999 */
01000 
01001   return mat;
01002 }
01003 
01004 ////////////////////////////////////////////////////////////////////
01005 //     Function: LMatrix::rotate_mat_normaxis
01006 //       Access: Public, Static
01007 //  Description: Returns a matrix that rotates by the given angle in
01008 //               degrees counterclockwise about the indicated vector.
01009 //               Assumes axis has been normalized.
01010 ////////////////////////////////////////////////////////////////////
01011 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
01012 rotate_mat_normaxis(FLOATTYPE angle, const FLOATNAME(LVecBase3) &axis,
01013            CoordinateSystem cs) {
01014   if (cs == CS_default) {
01015     cs = default_coordinate_system;
01016   }
01017   FLOATNAME(LMatrix3) mat;
01018 
01019   if(IS_LEFT_HANDED_COORDSYSTEM(cs)) {
01020     // In a left-handed coordinate system, counterclockwise is the
01021     // other direction.
01022     angle = -angle;
01023   }
01024 
01025   FLOATTYPE axis_0 = axis._v.v._0;
01026   FLOATTYPE axis_1 = axis._v.v._1;
01027   FLOATTYPE axis_2 = axis._v.v._2;
01028 
01029   FLOATTYPE angle_rad=deg_2_rad(angle);
01030   FLOATTYPE s,c;
01031   csincos(angle_rad,&s,&c);
01032   FLOATTYPE t = 1.0f - c;
01033 
01034   FLOATTYPE t0,t1,t2,s0,s1,s2;
01035 
01036   t0 = t * axis_0;
01037   t1 = t * axis_1;
01038   t2 = t * axis_2;
01039   s0 = s * axis_0;
01040   s1 = s * axis_1;
01041   s2 = s * axis_2;
01042 
01043   mat._m.m._00 = t0 * axis_0 + c;
01044   mat._m.m._01 = t0 * axis_1 + s2;
01045   mat._m.m._02 = t0 * axis_2 - s1;
01046 
01047   mat._m.m._10 = t1 * axis_0 - s2;
01048   mat._m.m._11 = t1 * axis_1 + c;
01049   mat._m.m._12 = t1 * axis_2 + s0;
01050 
01051   mat._m.m._20 = t2 * axis_0 + s1;
01052   mat._m.m._21 = t2 * axis_1 - s0;
01053   mat._m.m._22 = t2 * axis_2 + c;
01054 
01055 /*
01056   mat._m.m._00 = t * axis._v.v._0 * axis._v.v._0 + c;
01057   mat._m.m._01 = t * axis._v.v._0 * axis._v.v._1 + s * axis._v.v._2;
01058   mat._m.m._02 = t * axis._v.v._0 * axis._v.v._2 - s * axis._v.v._1;
01059 
01060   mat._m.m._10 = t * axis._v.v._1 * axis._v.v._0 - s * axis._v.v._2;
01061   mat._m.m._11 = t * axis._v.v._1 * axis._v.v._1 + c;
01062   mat._m.m._12 = t * axis._v.v._1 * axis._v.v._2 + s * axis._v.v._0;
01063 
01064   mat._m.m._20 = t * axis._v.v._2 * axis._v.v._0 + s * axis._v.v._1;
01065   mat._m.m._21 = t * axis._v.v._2 * axis._v.v._1 - s * axis._v.v._0;
01066   mat._m.m._22 = t * axis._v.v._2 * axis._v.v._2 + c;
01067 */
01068 
01069   return mat;
01070 }
01071 
01072 ////////////////////////////////////////////////////////////////////
01073 //     Function: LMatrix::scale_mat
01074 //       Access: Public, Static
01075 //  Description: Returns a matrix that applies the indicated
01076 //               scale in each of the three axes.
01077 ////////////////////////////////////////////////////////////////////
01078 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
01079 scale_mat(const FLOATNAME(LVecBase3) &scale) {
01080   return FLOATNAME(LMatrix3)(scale[0], 0.0f, 0.0f,
01081                              0.0f, scale._v.v._1, 0.0f,
01082                              0.0f, 0.0f, scale._v.v._2);
01083 }
01084 
01085 ////////////////////////////////////////////////////////////////////
01086 //     Function: LMatrix::scale_mat
01087 //       Access: Public, Static
01088 //  Description: Returns a matrix that applies the indicated
01089 //               scale in each of the three axes.
01090 ////////////////////////////////////////////////////////////////////
01091 INLINE_LINMATH FLOATNAME(LMatrix3) FLOATNAME(LMatrix3)::
01092 scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz) {
01093   return FLOATNAME(LMatrix3)(sx, 0.0f, 0.0f,
01094                              0.0f, sy, 0.0f,
01095                              0.0f, 0.0f, sz);
01096 }
01097 
01098 ////////////////////////////////////////////////////////////////////
01099 //     Function: LMatrix3::almost_equal
01100 //       Access: Public
01101 //  Description: Returns true if two matrices are memberwise equal
01102 //               within a default tolerance based on the numeric type.
01103 ////////////////////////////////////////////////////////////////////
01104 INLINE_LINMATH bool FLOATNAME(LMatrix3)::
01105 almost_equal(const FLOATNAME(LMatrix3) &other) const {
01106   return almost_equal(other, NEARLY_ZERO(FLOATTYPE));
01107 }
01108 
01109 ////////////////////////////////////////////////////////////////////
01110 //     Function: LMatrix3::generate_hash
01111 //       Access: Public
01112 //  Description: Adds the vector to the indicated hash generator.
01113 ////////////////////////////////////////////////////////////////////
01114 INLINE_LINMATH void FLOATNAME(LMatrix3)::
01115 generate_hash(ChecksumHashGenerator &hashgen) const {
01116   generate_hash(hashgen, NEARLY_ZERO(FLOATTYPE));
01117 }
01118 
01119 
01120 ////////////////////////////////////////////////////////////////////
01121 //     Function: transpose
01122 //  Description: Transposes the given matrix and returns it.
01123 ////////////////////////////////////////////////////////////////////
01124 INLINE_LINMATH FLOATNAME(LMatrix3)
01125 transpose(const FLOATNAME(LMatrix3) &a) {
01126   FLOATNAME(LMatrix3) result;
01127   result.transpose_from(a);
01128   return result;
01129 }
01130 
01131 ////////////////////////////////////////////////////////////////////
01132 //     Function: invert
01133 //  Description: Inverts the given matrix and returns it.
01134 ////////////////////////////////////////////////////////////////////
01135 INLINE_LINMATH FLOATNAME(LMatrix3)
01136 invert(const FLOATNAME(LMatrix3) &a) {
01137   FLOATNAME(LMatrix3) result;
01138   bool nonsingular = result.invert_from(a);
01139   nassertr(nonsingular, FLOATNAME(LMatrix3)::ident_mat());
01140   return result;
01141 }

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