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

panda/src/linmath/lmatrix3_src.h

Go to the documentation of this file.
00001 // Filename: lmatrix3_src.h
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 //       Class : LMatrix3
00021 // Description : This is a 3-by-3 transform matrix.  It typically will
00022 //               represent either a rotation-and-scale (no
00023 //               translation) matrix in 3-d, or a full affine matrix
00024 //               (rotation, scale, translation) in 2-d, e.g. for a
00025 //               texture matrix.
00026 ////////////////////////////////////////////////////////////////////
00027 class EXPCL_PANDA FLOATNAME(LMatrix3) {
00028 PUBLISHED:
00029   typedef const FLOATTYPE *iterator;
00030   typedef const FLOATTYPE *const_iterator;
00031 
00032   INLINE_LINMATH FLOATNAME(LMatrix3)();
00033   INLINE_LINMATH FLOATNAME(LMatrix3)(const FLOATNAME(LMatrix3) &other);
00034   INLINE_LINMATH FLOATNAME(LMatrix3) &operator = (const FLOATNAME(LMatrix3) &other);
00035   INLINE_LINMATH FLOATNAME(LMatrix3) &operator = (FLOATTYPE fill_value);
00036   INLINE_LINMATH FLOATNAME(LMatrix3)(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02,
00037                                      FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12,
00038                                      FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22);
00039 
00040   void fill(FLOATTYPE fill_value);
00041   INLINE_LINMATH void set(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e02,
00042                           FLOATTYPE e10, FLOATTYPE e11, FLOATTYPE e12,
00043                           FLOATTYPE e20, FLOATTYPE e21, FLOATTYPE e22);
00044 
00045   INLINE_LINMATH void set_row(int row, const FLOATNAME(LVecBase3) &v);
00046   INLINE_LINMATH void set_col(int col, const FLOATNAME(LVecBase3) &v);
00047 
00048   INLINE_LINMATH void set_row(int row, const FLOATNAME(LVecBase2) &v);
00049   INLINE_LINMATH void set_col(int col, const FLOATNAME(LVecBase2) &v);
00050 
00051   INLINE_LINMATH FLOATNAME(LVecBase3) get_row(int row) const;
00052   INLINE_LINMATH FLOATNAME(LVecBase3) get_col(int col) const;
00053 
00054   INLINE_LINMATH FLOATNAME(LVecBase2) get_row2(int row) const;
00055   INLINE_LINMATH FLOATNAME(LVecBase2) get_col2(int col) const;
00056 
00057   // these versions inline better
00058   INLINE_LINMATH void get_row(FLOATNAME(LVecBase3) &result_vec, int row) const;
00059 
00060   INLINE_LINMATH FLOATTYPE &operator () (int row, int col);
00061   INLINE_LINMATH FLOATTYPE operator () (int row, int col) const;
00062 
00063   INLINE_LINMATH bool is_nan() const;
00064 
00065   INLINE_LINMATH FLOATTYPE get_cell(int row, int col) const;
00066   INLINE_LINMATH void set_cell(int row, int col, FLOATTYPE value);
00067 
00068   INLINE_LINMATH const FLOATTYPE *get_data() const;
00069   INLINE_LINMATH int get_num_components() const;
00070 
00071 public:
00072   INLINE_LINMATH iterator begin();
00073   INLINE_LINMATH iterator end();
00074 
00075   INLINE_LINMATH const_iterator begin() const;
00076   INLINE_LINMATH const_iterator end() const;
00077 
00078 PUBLISHED:
00079   INLINE_LINMATH bool operator < (const FLOATNAME(LMatrix3) &other) const;
00080   INLINE_LINMATH bool operator == (const FLOATNAME(LMatrix3) &other) const;
00081   INLINE_LINMATH bool operator != (const FLOATNAME(LMatrix3) &other) const;
00082 
00083   INLINE_LINMATH int compare_to(const FLOATNAME(LMatrix3) &other) const;
00084   int compare_to(const FLOATNAME(LMatrix3) &other, FLOATTYPE threshold) const;
00085 
00086   INLINE_LINMATH FLOATNAME(LVecBase3)
00087   xform(const FLOATNAME(LVecBase3) &v) const;
00088 
00089   INLINE_LINMATH FLOATNAME(LVecBase2)
00090   xform_point(const FLOATNAME(LVecBase2) &v) const;
00091 
00092   INLINE_LINMATH FLOATNAME(LVecBase2)
00093   xform_vec(const FLOATNAME(LVecBase2) &v) const;
00094 
00095   // this = other1 * other2
00096   INLINE_LINMATH void multiply(const FLOATNAME(LMatrix3) &other1, const FLOATNAME(LMatrix3) &other2);
00097 
00098   INLINE_LINMATH FLOATNAME(LMatrix3) operator * (const FLOATNAME(LMatrix3) &other) const;
00099   INLINE_LINMATH FLOATNAME(LMatrix3) operator * (FLOATTYPE scalar) const;
00100   INLINE_LINMATH FLOATNAME(LMatrix3) operator / (FLOATTYPE scalar) const;
00101 
00102   // this = scale_mat(scale_vector) * other_mat, efficiently
00103   INLINE_LINMATH void scale_multiply(const FLOATNAME(LVecBase3) &scale_vector,const FLOATNAME(LMatrix3) &other_mat);
00104 
00105   INLINE_LINMATH FLOATNAME(LMatrix3) &operator += (const FLOATNAME(LMatrix3) &other);
00106   INLINE_LINMATH FLOATNAME(LMatrix3) &operator -= (const FLOATNAME(LMatrix3) &other);
00107 
00108   INLINE_LINMATH FLOATNAME(LMatrix3) &operator *= (const FLOATNAME(LMatrix3) &other);
00109 
00110   INLINE_LINMATH FLOATNAME(LMatrix3) &operator *= (FLOATTYPE scalar);
00111   INLINE_LINMATH FLOATNAME(LMatrix3) &operator /= (FLOATTYPE scalar);
00112 
00113   INLINE_LINMATH FLOATTYPE determinant() const;
00114 
00115   INLINE_LINMATH void transpose_from(const FLOATNAME(LMatrix3) &other);
00116   INLINE_LINMATH void transpose_in_place();
00117 
00118   INLINE_LINMATH bool invert_from(const FLOATNAME(LMatrix3) &other);
00119   INLINE_LINMATH bool invert_in_place();
00120 
00121   static INLINE_LINMATH const FLOATNAME(LMatrix3) &ident_mat();
00122 
00123   // A 3x3 matrix is likely to be used for one of two purposes.  In
00124   // 2-d coordinate space (e.g. texture or surface coordinates), it
00125   // can contain a full affine transform, with scale, rotate,
00126   // translate.  In 3-d coordinate space, it can contain only scale
00127   // and/or rotate; e.g., the upper 3x3 rectangle of a full 4x4
00128   // matrix.
00129 
00130   // The following named constructors return 3x3 matrices suitable for
00131   // affine transforms in 2-d coordinate space.
00132 
00133   static INLINE_LINMATH FLOATNAME(LMatrix3)
00134     translate_mat(const FLOATNAME(LVecBase2) &trans);
00135   static INLINE_LINMATH FLOATNAME(LMatrix3)
00136     translate_mat(FLOATTYPE tx, FLOATTYPE ty);
00137   static INLINE_LINMATH FLOATNAME(LMatrix3)
00138     rotate_mat(FLOATTYPE angle);
00139   static INLINE_LINMATH FLOATNAME(LMatrix3)
00140     scale_mat(const FLOATNAME(LVecBase2) &scale);
00141   static INLINE_LINMATH FLOATNAME(LMatrix3)
00142     scale_mat(FLOATTYPE sx, FLOATTYPE sy);
00143 
00144   // The following named constructors return 3x3 matrices suitable for
00145   // scale/rotate transforms in 3-d coordinate space.
00146   static INLINE_LINMATH FLOATNAME(LMatrix3)
00147     rotate_mat(FLOATTYPE angle,
00148                FLOATNAME(LVecBase3) axis,
00149                CoordinateSystem cs = CS_default);
00150   static INLINE_LINMATH FLOATNAME(LMatrix3)
00151     rotate_mat_normaxis(FLOATTYPE angle,
00152                         const FLOATNAME(LVecBase3) &axis,
00153                         CoordinateSystem cs = CS_default);
00154 
00155   static INLINE_LINMATH FLOATNAME(LMatrix3)
00156     scale_mat(const FLOATNAME(LVecBase3) &scale);
00157   static INLINE_LINMATH FLOATNAME(LMatrix3)
00158     scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz);
00159 
00160   static const FLOATNAME(LMatrix3) &convert_mat(CoordinateSystem from,
00161                                                 CoordinateSystem to);
00162 
00163   // We don't have a scale_mat() that takes a single uniform scale
00164   // parameter, because it would be ambiguous whether we mean a 2-d or
00165   // a 3-d scale.
00166 
00167   bool almost_equal(const FLOATNAME(LMatrix3) &other,
00168                     FLOATTYPE threshold) const;
00169 
00170   INLINE_LINMATH bool almost_equal(const FLOATNAME(LMatrix3) &other) const;
00171 
00172   void output(ostream &out) const;
00173   void write(ostream &out, int indent_level = 0) const;
00174 
00175 public:
00176   INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen) const;
00177   void generate_hash(ChecksumHashGenerator &hashgen, FLOATTYPE threshold) const;
00178 
00179 public:
00180   union {
00181     struct {
00182       FLOATTYPE  _00, _01, _02;
00183       FLOATTYPE  _10, _11, _12;
00184       FLOATTYPE  _20, _21, _22;
00185     } m;
00186     
00187     FLOATTYPE data[3 * 3];
00188   } _m;
00189 
00190 private:
00191   INLINE_LINMATH FLOATTYPE mult_cel(const FLOATNAME(LMatrix3) &other, int x, int y) const;
00192   INLINE_LINMATH FLOATTYPE det2(FLOATTYPE e00, FLOATTYPE e01, FLOATTYPE e10, FLOATTYPE e11) const;
00193 
00194   static const FLOATNAME(LMatrix3) _ident_mat;
00195   static const FLOATNAME(LMatrix3) _y_to_z_up_mat;
00196   static const FLOATNAME(LMatrix3) _z_to_y_up_mat;
00197   static const FLOATNAME(LMatrix3) _flip_y_mat;
00198   static const FLOATNAME(LMatrix3) _flip_z_mat;
00199   static const FLOATNAME(LMatrix3) _lz_to_ry_mat;
00200   static const FLOATNAME(LMatrix3) _ly_to_rz_mat;
00201 
00202   //Functionality for reading and writing from/to a binary source
00203 public:
00204   void write_datagram(Datagram& destination) const;
00205   void read_datagram(DatagramIterator& scan);
00206 
00207 public:
00208   static TypeHandle get_class_type() {
00209     return _type_handle;
00210   }
00211   static void init_type();
00212 
00213 private:
00214   static TypeHandle _type_handle;
00215 };
00216 
00217 
00218 INLINE_LINMATH ostream &operator << (ostream &out, const FLOATNAME(LMatrix3) &mat) {
00219   mat.output(out);
00220   return out;
00221 }
00222 
00223 INLINE_LINMATH FLOATNAME(LMatrix3) transpose(const FLOATNAME(LMatrix3) &a);
00224 INLINE_LINMATH FLOATNAME(LMatrix3) invert(const FLOATNAME(LMatrix3) &a);
00225 
00226 #include "lmatrix3_src.I"

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