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

panda/src/linmath/lmatrix4_src.h

Go to the documentation of this file.
00001 // Filename: lmatrix4_src.h
00002 // Created by:  drose (15Jan99)
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 //       Class : LMatrix4
00022 // Description : This is a 4-by-4 transform matrix.
00023 ////////////////////////////////////////////////////////////////////
00024 class EXPCL_PANDA FLOATNAME(LMatrix4) {
00025 PUBLISHED:
00026   typedef const FLOATTYPE *iterator;
00027   typedef const FLOATTYPE *const_iterator;
00028 
00029   INLINE_LINMATH FLOATNAME(LMatrix4)();
00030   INLINE_LINMATH FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix4) &other);
00031   INLINE_LINMATH FLOATNAME(LMatrix4) &operator = (const FLOATNAME(LMatrix4) &other);
00032   INLINE_LINMATH FLOATNAME(LMatrix4) &operator = (FLOATTYPE fill_value);
00033 
00034   INLINE_LINMATH FLOATNAME(LMatrix4)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03,
00035                                      FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e13,
00036                                      FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22, FLOATTYPE e23,
00037                                      FLOATTYPE e30, FLOATTYPE e31, FLOATTYPE e32, FLOATTYPE e33);
00038 
00039   // Construct a 4x4 matrix given a 3x3 rotation matrix and an optional
00040   // translation component.
00041   INLINE_LINMATH FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3);
00042   INLINE_LINMATH FLOATNAME(LMatrix4)(const FLOATNAME(LMatrix3) &upper3,const FLOATNAME(LVecBase3) &trans);
00043 
00044   INLINE_LINMATH void fill(FLOATTYPE fill_value);
00045   INLINE_LINMATH void set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02, FLOATTYPE e03,
00046                   FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12, FLOATTYPE e13,
00047                   FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22, FLOATTYPE e23,
00048                   FLOATTYPE e30, FLOATTYPE e31, FLOATTYPE e32, FLOATTYPE e33);
00049 
00050   // Get and set the upper 3x3 rotation matrix.
00051   INLINE_LINMATH void set_upper_3(const FLOATNAME(LMatrix3) &upper3);
00052   INLINE_LINMATH FLOATNAME(LMatrix3) get_upper_3() const;
00053 
00054   INLINE_LINMATH void set_row(int row, const FLOATNAME(LVecBase4) &v);
00055   INLINE_LINMATH void set_col(int col, const FLOATNAME(LVecBase4) &v);
00056 
00057   INLINE_LINMATH void set_row(int row, const FLOATNAME(LVecBase3) &v);
00058   INLINE_LINMATH void set_col(int col, const FLOATNAME(LVecBase3) &v);
00059 
00060   INLINE_LINMATH FLOATNAME(LVecBase4) get_row(int row) const;
00061   INLINE_LINMATH FLOATNAME(LVecBase4) get_col(int col) const;
00062 
00063   INLINE_LINMATH FLOATNAME(LVecBase3) get_row3(int row) const;
00064 
00065   // these versions inline better
00066   INLINE_LINMATH void get_row(FLOATNAME(LVecBase4) &result_vec, int row) const;
00067   INLINE_LINMATH void get_row3(FLOATNAME(LVecBase3) &result_vec, int row) const;
00068 
00069   INLINE_LINMATH FLOATNAME(LVecBase3) get_col3(int col) const;
00070 
00071   INLINE_LINMATH FLOATTYPE &operator () (int row, int col);
00072   INLINE_LINMATH FLOATTYPE operator () (int row, int col) const;
00073 
00074   INLINE_LINMATH bool is_nan() const;
00075 
00076   INLINE_LINMATH FLOATTYPE get_cell(int row, int col) const;
00077   INLINE_LINMATH void set_cell(int row, int col, FLOATTYPE value);
00078 
00079   INLINE_LINMATH const FLOATTYPE *get_data() const;
00080   INLINE_LINMATH int get_num_components() const;
00081 
00082   INLINE_LINMATH iterator begin();
00083   INLINE_LINMATH iterator end();
00084 
00085   INLINE_LINMATH const_iterator begin() const;
00086   INLINE_LINMATH const_iterator end() const;
00087 
00088   INLINE_LINMATH bool operator < (const FLOATNAME(LMatrix4) &other) const;
00089   INLINE_LINMATH bool operator == (const FLOATNAME(LMatrix4) &other) const;
00090   INLINE_LINMATH bool operator != (const FLOATNAME(LMatrix4) &other) const;
00091 
00092   INLINE_LINMATH int compare_to(const FLOATNAME(LMatrix4) &other) const;
00093   int compare_to(const FLOATNAME(LMatrix4) &other, FLOATTYPE threshold) const;
00094 
00095   INLINE_LINMATH FLOATNAME(LVecBase4)
00096   xform(const FLOATNAME(LVecBase4) &v) const;
00097 
00098   INLINE_LINMATH FLOATNAME(LVecBase3)
00099   xform_point(const FLOATNAME(LVecBase3) &v) const;
00100 
00101   INLINE_LINMATH FLOATNAME(LVecBase3)
00102   xform_vec(const FLOATNAME(LVecBase3) &v) const;
00103 
00104   // this = other1 * other2
00105   INLINE_LINMATH void multiply(const FLOATNAME(LMatrix4) &other1, const FLOATNAME(LMatrix4) &other2);
00106 
00107         // this = scale_mat(scale_vector) * other_mat, efficiently
00108   INLINE_LINMATH void scale_multiply(const FLOATNAME(LVecBase3) &scale_vector,const FLOATNAME(LMatrix4) &other_mat);
00109 
00110   INLINE_LINMATH FLOATNAME(LMatrix4) operator * (const FLOATNAME(LMatrix4) &other) const;
00111 
00112   INLINE_LINMATH FLOATNAME(LMatrix4) operator * (FLOATTYPE scalar) const;
00113   INLINE_LINMATH FLOATNAME(LMatrix4) operator / (FLOATTYPE scalar) const;
00114 
00115   INLINE_LINMATH FLOATNAME(LMatrix4) &operator += (const FLOATNAME(LMatrix4) &other);
00116   INLINE_LINMATH FLOATNAME(LMatrix4) &operator -= (const FLOATNAME(LMatrix4) &other);
00117 
00118   INLINE_LINMATH FLOATNAME(LMatrix4) &operator *= (const FLOATNAME(LMatrix4) &other);
00119 
00120   INLINE_LINMATH FLOATNAME(LMatrix4) &operator *= (FLOATTYPE scalar);
00121   INLINE_LINMATH FLOATNAME(LMatrix4) &operator /= (FLOATTYPE scalar);
00122 
00123   INLINE_LINMATH void transpose_from(const FLOATNAME(LMatrix4) &other);
00124   INLINE_LINMATH void transpose_in_place();
00125 
00126   INLINE_LINMATH bool invert_from(const FLOATNAME(LMatrix4) &other);
00127   INLINE_LINMATH bool invert_affine_from(const FLOATNAME(LMatrix4) &other);
00128   INLINE_LINMATH bool invert_in_place();
00129 
00130   INLINE_LINMATH static const FLOATNAME(LMatrix4) &ident_mat();
00131   INLINE_LINMATH static FLOATNAME(LMatrix4)
00132     translate_mat(const FLOATNAME(LVecBase3) &trans);
00133   INLINE_LINMATH static FLOATNAME(LMatrix4)
00134     translate_mat(FLOATTYPE tx, FLOATTYPE ty, FLOATTYPE tz);
00135   INLINE_LINMATH static FLOATNAME(LMatrix4)
00136     rotate_mat(FLOATTYPE angle,
00137                FLOATNAME(LVecBase3) axis,
00138                CoordinateSystem cs = CS_default);
00139   INLINE_LINMATH static FLOATNAME(LMatrix4)
00140     rotate_mat_normaxis(FLOATTYPE angle,
00141                         const FLOATNAME(LVecBase3) &axis,
00142                         CoordinateSystem cs = CS_default);
00143   INLINE_LINMATH static void
00144     rotate_mat_normaxis(FLOATTYPE angle,
00145                         const FLOATNAME(LVecBase3) &axis,
00146                         FLOATNAME(LMatrix4) &result_mat,
00147                         CoordinateSystem cs = CS_default);
00148   INLINE_LINMATH static FLOATNAME(LMatrix4)
00149     scale_mat(const FLOATNAME(LVecBase3) &scale);
00150   INLINE_LINMATH static FLOATNAME(LMatrix4)
00151     scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz);
00152   INLINE_LINMATH static FLOATNAME(LMatrix4)
00153     scale_mat(FLOATTYPE scale);
00154 
00155   INLINE_LINMATH static const FLOATNAME(LMatrix4) &y_to_z_up_mat();
00156   INLINE_LINMATH static const FLOATNAME(LMatrix4) &z_to_y_up_mat();
00157 
00158   static const FLOATNAME(LMatrix4) &convert_mat(CoordinateSystem from,
00159                                                 CoordinateSystem to);
00160 
00161   bool almost_equal(const FLOATNAME(LMatrix4) &other,
00162                     FLOATTYPE threshold) const;
00163   INLINE_LINMATH bool almost_equal(const FLOATNAME(LMatrix4) &other) const;
00164 
00165   void output(ostream &out) const;
00166   void write(ostream &out, int indent_level = 0) const;
00167 
00168 public:
00169   INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen) const;
00170   void generate_hash(ChecksumHashGenerator &hashgen, FLOATTYPE scale) const;
00171 
00172 public:
00173   union {
00174     struct {
00175       FLOATTYPE  _00, _01, _02, _03;
00176       FLOATTYPE  _10, _11, _12, _13;
00177       FLOATTYPE  _20, _21, _22, _23;
00178       FLOATTYPE  _30, _31, _32, _33;
00179     } m;
00180     
00181     FLOATTYPE data[4 * 4];
00182   } _m;
00183 
00184 private:
00185   INLINE_LINMATH FLOATTYPE mult_cel(const FLOATNAME(LMatrix4) &other, int x, int y) const;
00186   bool decompose_mat(int index[4]);
00187   bool back_sub_mat(int index[4], FLOATNAME(LMatrix4) &inv, int row) const;
00188 
00189   static const FLOATNAME(LMatrix4) _ident_mat;
00190   static const FLOATNAME(LMatrix4) _y_to_z_up_mat;
00191   static const FLOATNAME(LMatrix4) _z_to_y_up_mat;
00192   static const FLOATNAME(LMatrix4) _flip_y_mat;
00193   static const FLOATNAME(LMatrix4) _flip_z_mat;
00194   static const FLOATNAME(LMatrix4) _lz_to_ry_mat;
00195   static const FLOATNAME(LMatrix4) _ly_to_rz_mat;
00196 
00197   //Functionality for reading and writing from/to a binary source
00198 public:
00199   void write_datagram(Datagram& destination) const;
00200   void read_datagram(DatagramIterator& scan);
00201 
00202 public:
00203   static TypeHandle get_class_type() {
00204     return _type_handle;
00205   }
00206   static void init_type();
00207 
00208 private:
00209   static TypeHandle _type_handle;
00210 };
00211 
00212 
00213 INLINE_LINMATH ostream &operator << (ostream &out, const FLOATNAME(LMatrix4) &mat) {
00214   mat.output(out);
00215   return out;
00216 }
00217 
00218 
00219 INLINE_LINMATH FLOATNAME(LMatrix4) transpose(const FLOATNAME(LMatrix4) &a);
00220 INLINE_LINMATH FLOATNAME(LMatrix4) invert(const FLOATNAME(LMatrix4) &a);
00221 
00222 #include "lmatrix4_src.I"

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