PixelLightAPI  .
Matrix3x3.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: Matrix3x3.h                                    *
00003  *
00004  *  Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLMATH_MATRIX3X3_H__
00024 #define __PLMATH_MATRIX3X3_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include "PLMath/Vector2.h"
00032 #include "PLMath/Vector4.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLMath {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Classes                                               ]
00043 //[-------------------------------------------------------]
00044 /**
00045 *  @brief
00046 *    3x3 matrix
00047 *
00048 *  @remarks
00049 *    Matrices are stored in column major order like OpenGL does. (right-handed matrix)
00050 *    So, it's possible to give OpenGL the matrix data without transposing it first.
00051 *
00052 *  @note
00053 *    - Some symbols within the comments: T = transposed, I = identity
00054 */
00055 class Matrix3x3 {
00056 
00057 
00058     //[-------------------------------------------------------]
00059     //[ Public static data                                    ]
00060     //[-------------------------------------------------------]
00061     public:
00062         static PLMATH_API const Matrix3x3 Zero;     /**< Zero matrix */
00063         static PLMATH_API const Matrix3x3 Identity; /**< Identity matrix */
00064 
00065 
00066     //[-------------------------------------------------------]
00067     //[ Public data                                           ]
00068     //[-------------------------------------------------------]
00069     public:
00070         /**
00071         *  @brief
00072         *    Some direct matrix accesses
00073         */
00074         union {
00075             /**
00076             *  @brief
00077             *    One dimensional array representation
00078             *
00079             *  @remarks
00080             *    The entry of the matrix in row r (0 <= r <= 2) and column c (0 <= c <= 2) is
00081             *    stored at index i = r+3*c (0 <= i <= 8).\n
00082             *    Indices:
00083             *    @code
00084             *      | 0 3 6 |
00085             *      | 1 4 7 |
00086             *      | 2 5 8 |
00087             *    @endcode
00088             */
00089             float fM[9];
00090 
00091             /**
00092             *  @brief
00093             *    Direct element representation
00094             *
00095             *  @remarks
00096             *    Indices: (row/column)
00097             *    @code
00098             *      | xx xy xz |
00099             *      | yx yy yz |
00100             *      | zx zy zz |
00101             *    @endcode
00102             *    It's recommended to use this way to access the elements.
00103             */
00104             struct {
00105                 float xx, yx, zx;
00106                 float xy, yy, zy;
00107                 float xz, yz, zz;
00108             };
00109 
00110             /**
00111             *  @brief
00112             *    Two dimensional array representation
00113             *
00114             *  @remarks
00115             *    fM33[i][j] -> i=column, j=row\n
00116             *    Try to avoid this access mode. This can be a problem on a platform/console that
00117             *    chooses to store the data in column-major rather than row-major format.
00118             */
00119             struct {
00120                 float fM33[3][3];
00121             };
00122         };
00123 
00124 
00125     //[-------------------------------------------------------]
00126     //[ Public functions                                      ]
00127     //[-------------------------------------------------------]
00128     public:
00129         //[-------------------------------------------------------]
00130         //[ Constructor                                           ]
00131         //[-------------------------------------------------------]
00132         /**
00133         *  @brief
00134         *    Default constructor setting an identity matrix
00135         */
00136         inline Matrix3x3();
00137 
00138         inline Matrix3x3(const float fS[]);
00139         inline Matrix3x3(const Matrix3x3 &mM);
00140         PLMATH_API Matrix3x3(const Matrix3x4 &mM);
00141         PLMATH_API Matrix3x3(const Matrix4x4 &mM);
00142         inline Matrix3x3(float fXX, float fXY, float fXZ,
00143                          float fYX, float fYY, float fYZ,
00144                          float fZX, float fZY, float fZZ);
00145 
00146         //[-------------------------------------------------------]
00147         //[ Destructor                                            ]
00148         //[-------------------------------------------------------]
00149         inline ~Matrix3x3();
00150 
00151         //[-------------------------------------------------------]
00152         //[ Comparison                                            ]
00153         //[-------------------------------------------------------]
00154         PLMATH_API bool operator ==(const Matrix3x3 &mM) const;
00155         PLMATH_API bool operator !=(const Matrix3x3 &mM) const;
00156         // fEpsilon = epsilon environment (to take computation errors into account...)
00157         PLMATH_API bool CompareScale(const Matrix3x3 &mM, float fEpsilon = Math::Epsilon) const;
00158         PLMATH_API bool CompareRotation(const Matrix3x3 &mM, float fEpsilon = Math::Epsilon) const;
00159 
00160         //[-------------------------------------------------------]
00161         //[ Operators                                             ]
00162         //[-------------------------------------------------------]
00163         inline Matrix3x3     &operator =(const float fS[]);
00164         inline Matrix3x3     &operator =(const Matrix3x3 &mM);
00165         PLMATH_API Matrix3x3 &operator =(const Matrix3x4 &mM);
00166         PLMATH_API Matrix3x3 &operator =(const Matrix4x4 &mM);
00167         inline Matrix3x3      operator +(const Matrix3x3 &mM) const;
00168         inline void           operator +=(const Matrix3x3 &mM);
00169         inline Matrix3x3      operator -() const;
00170         inline Matrix3x3      operator -(const Matrix3x3 &mM) const;
00171         inline void           operator -=(const Matrix3x3 &mM);
00172         inline Matrix3x3      operator *(float fS) const;
00173         inline void           operator *=(float fS);
00174         inline Vector2        operator *(const Vector2 &vV) const;
00175         inline Vector3        operator *(const Vector3 &vV) const;
00176         PLMATH_API Vector4    operator *(const Vector4 &vV) const;
00177         PLMATH_API Matrix3x3  operator *(const Matrix3x3 &mM) const;
00178         inline void           operator *=(const Matrix3x3 &mM);
00179         inline Matrix3x3      operator /(float fS) const;
00180         inline void           operator /=(float fS);
00181         inline float          operator [](int nIndex) const;
00182         inline float         &operator [](int nIndex);
00183         inline float          operator ()(PLCore::uint32 nRow = 0, PLCore::uint32 nColumn = 0) const;
00184         inline float         &operator ()(PLCore::uint32 nRow = 0, PLCore::uint32 nColumn = 0);
00185         inline                operator float *();
00186         inline                operator const float *() const;
00187 
00188         //[-------------------------------------------------------]
00189         //[ Matrix operations                                     ]
00190         //[-------------------------------------------------------]
00191         /**
00192         *  @brief
00193         *    Returns whether or not this matrix is the zero matrix using an epsilon environment
00194         *
00195         *  @return
00196         *    'true' if this matrix is the zero matrix, else 'false'
00197         */
00198         inline bool IsZero() const;
00199 
00200         /**
00201         *  @brief
00202         *    Returns whether or not this matrix is truly the zero matrix
00203         *
00204         *  @remarks
00205         *    All components MUST be exactly 0. Floating point inaccuracy
00206         *    is not taken into account.
00207         *
00208         *  @return
00209         *    'true' if this matrix is truly the zero matrix, else 'false'
00210         */
00211         inline bool IsTrueZero() const;
00212 
00213         /**
00214         *  @brief
00215         *    Sets a zero matrix
00216         *
00217         *  @remarks
00218         *    @code
00219         *    | 0 0 0 |
00220         *    | 0 0 0 |
00221         *    | 0 0 0 |
00222         *    @endcode
00223         */
00224         inline void SetZero();
00225 
00226         /**
00227         *  @brief
00228         *    Returns whether or not this matrix is the identity matrix using an epsilon environment
00229         *
00230         *  @return
00231         *    'true' if this matrix is the identity matrix, else 'false'
00232         */
00233         inline bool IsIdentity() const;
00234 
00235         /**
00236         *  @brief
00237         *    Returns whether or not this matrix is truly the identity matrix
00238         *
00239         *  @remarks
00240         *    All components MUST be exactly either 0 or 1. Floating point inaccuracy
00241         *    is not taken into account.
00242         *
00243         *  @return
00244         *    'true' if this matrix is truly the identity matrix, else 'false'
00245         */
00246         inline bool IsTrueIdentity() const;
00247 
00248         /**
00249         *  @brief
00250         *    Sets an identity matrix
00251         *
00252         *  @remarks
00253         *    @code
00254         *    | 1 0 0 |
00255         *    | 0 1 0 |
00256         *    | 0 0 1 |
00257         *    @endcode
00258         */
00259         inline void SetIdentity();
00260 
00261         /**
00262         *  @brief
00263         *    Sets the elements of the matrix
00264         */
00265         inline void Set(float fXX, float fXY, float fXZ,
00266                         float fYX, float fYY, float fYZ,
00267                         float fZX, float fZY, float fZZ);
00268 
00269         /**
00270         *  @brief
00271         *    Returns a requested row
00272         *
00273         *  @param[in] nRow
00274         *    Index of the row to return (0-2)
00275         *
00276         *  @return
00277         *    The requested row (null vector on error)
00278         *
00279         *  @remarks
00280         *    @code
00281         *    | x y z | <- Row 0
00282         *    | 0 0 0 |
00283         *    | 0 0 0 |
00284         *    @endcode
00285         */
00286         inline Vector3 GetRow(PLCore::uint8 nRow) const;
00287 
00288         /**
00289         *  @brief
00290         *    Sets a row
00291         *
00292         *  @param[in] nRow
00293         *    Index of the row to set (0-2)
00294         *  @param[in] vRow
00295         *    Row vector
00296         *
00297         *  @see
00298         *    - GetRow()
00299         */
00300         inline void SetRow(PLCore::uint8 nRow, const Vector3 &vRow);
00301 
00302         /**
00303         *  @brief
00304         *    Returns a requested column
00305         *
00306         *  @param[in] nColumn
00307         *    Index of the column to return (0-2)
00308         *
00309         *  @return
00310         *    The requested column (null vector on error)
00311         *
00312         *  @remarks
00313         *    @code
00314         *    | x 0 0 |
00315         *    | y 0 0 |
00316         *    | z 0 0 |
00317         *      ^
00318         *      |
00319         *      Column 0
00320         *    @endcode
00321         */
00322         inline Vector3 GetColumn(PLCore::uint8 nColumn) const;
00323 
00324         /**
00325         *  @brief
00326         *    Sets a column
00327         *
00328         *  @param[in] nColumn
00329         *    Index of the column to set (0-2)
00330         *  @param[in] vColumn
00331         *    Column vector
00332         *
00333         *  @see
00334         *    - GetColumn()
00335         */
00336         inline void SetColumn(PLCore::uint8 nColumn, const Vector3 &vColumn);
00337 
00338         /**
00339         *  @brief
00340         *    Returns true if the matrix is symmetric
00341         *
00342         *  @return
00343         *    'true' if the matrix is symmetric, else 'false'
00344         *
00345         *  @remarks
00346         *    A matrix is symmetric if it is equal to it's transposed matrix.\n
00347         *    A = A^T  ->  a(i, j) = a(j, i)
00348         */
00349         inline bool IsSymmetric() const;
00350 
00351         /**
00352         *  @brief
00353         *    Returns true if this matrix is orthogonal
00354         *
00355         *  @return
00356         *    'true' if the matrix is orthogonal, else 'false'
00357         *
00358         *  @remarks
00359         *    A matrix is orthogonal if it's transposed matrix is equal to it's inversed matrix.\n
00360         *    A^T = A^-1  or  A*A^T = A^T*A = I
00361         *
00362         *  @note
00363         *    - An orthogonal matrix is always nonsingular (invertible) and it's inverse is equal to it's transposed
00364         *    - The transpose and inverse of the matrix is orthogonal, too
00365         *    - Products of orthogonal matrices are orthogonal, too
00366         *    - The determinant of a orthogonal matrix is +/- 1
00367         *    - The row and column vectors of an orthogonal matrix form an orthonormal basis,
00368         *      that is, these vectors are unit-length and they are mutually perpendicular
00369         */
00370         inline bool IsOrthogonal() const;
00371 
00372         /**
00373         *  @brief
00374         *    Returns true if this matrix is a rotation matrix
00375         *
00376         *  @return
00377         *    'true' if this matrix is a rotation matrix, else 'false'
00378         *
00379         *  @remarks
00380         *    A rotation matrix is orthogonal and it's determinant is 1 to rule out reflections.
00381         *
00382         *  @see
00383         *    - IsOrthogonal()
00384         */
00385         inline bool IsRotationMatrix() const;
00386 
00387         /**
00388         *  @brief
00389         *    Returns the trace of the matrix
00390         *
00391         *  @return
00392         *    The trace of the matrix
00393         *
00394         *  @remarks
00395         *    The trace of the matrix is the sum of the main diagonal elements:\n
00396         *      xx+yy+zz
00397         */
00398         inline float GetTrace() const;
00399 
00400         /**
00401         *  @brief
00402         *    Returns the determinant of the matrix
00403         *
00404         *  @return
00405         *    Determinant of the matrix
00406         *
00407         *  @remarks
00408         *    The determinant is calculated using the Sarrus diagram:
00409         *    @code
00410         *      | xx   xy   xz  |  xx   xy |
00411         *      |     \   /\   /\     /    |
00412         *      | yx   yy   yz  |  yx   yy | =  xx*yy*zz + xy*yz*zx + xz*yx*zy -
00413         *      |    /    /\   /\      \   |   (zx*yy*xz + zy*yz*xx + zz*yx*xy)
00414         *      | zx   zy   zz  |  zx   zy |
00415         *    @endcode
00416         *
00417         *  @note
00418         *    - If the determinant is non-zero, then an inverse matrix exists
00419         *    - If the determinant is 0, the matrix is called singular, else nonsingular (invertible) matrix
00420         *    - If the determinant is 1, the inverse matrix is equal to the transpose of the matrix
00421         */
00422         inline float GetDeterminant() const;
00423 
00424         /**
00425         *  @brief
00426         *    Transpose this matrix
00427         *
00428         *  @remarks
00429         *    The transpose of matrix is the matrix generated when every element in
00430         *    the matrix is swapped with the opposite relative to the major diagonal
00431         *    This can be expressed as the mathematical operation:
00432         *    @code
00433         *      M'   = M
00434         *        ij    ji
00435         *
00436         *     | xx xy xz |                    | xx yx zx |
00437         *     | yx yy yz |  the transpose is  | xy yy zy |
00438         *     | zx zy zz |                    | xz yz zz |
00439         *    @endcode
00440         *
00441         *  @note
00442         *    - If the matrix is a rotation matrix (= isotropic matrix = determinant is 1),
00443         *      then the transpose is guaranteed to be the inverse of the matrix
00444         */
00445         inline void Transpose();
00446 
00447         /**
00448         *  @brief
00449         *    Returns the transposed matrix
00450         *
00451         *  @return
00452         *    Transposed matrix
00453         *
00454         *  @see
00455         *    - Transpose()
00456         */
00457         inline Matrix3x3 GetTransposed() const;
00458 
00459         /**
00460         *  @brief
00461         *    Inverts the matrix
00462         *
00463         *  @return
00464         *    'true' if all went fine, else 'false' (maybe the determinant is null?)
00465         *
00466         *  @remarks
00467         *    Providing that the determinant is non-zero, then the inverse is calculated
00468         *    using Kramer's rule as:
00469         *    @code
00470         *     -1     1     |   yy*zz-yz*zy  -(xy*zz-zy*xz)   xy*yz-yy*xz  |
00471         *    M   = ----- . | -(yx*zz-yz*zx)   xx*zz-zx*xz  -(xx*yz-yx*xz) |
00472         *          det M   |   yx*zy-zx*yy  -(xx*zy-zx*xy)   xx*yy-xy*yx  |
00473         *    @endcode
00474         *
00475         *  @note
00476         *    - If the determinant is 1, the inversed matrix is equal to the transposed one
00477         */
00478         PLMATH_API bool Invert();
00479 
00480         /**
00481         *  @brief
00482         *    Returns the inverse of the matrix
00483         *
00484         *  @return
00485         *    Inverse of the matrix, if the determinant is null, an identity matrix is returned
00486         */
00487         PLMATH_API Matrix3x3 GetInverted() const;
00488 
00489         /**
00490         *  @brief
00491         *    Rotates a vector
00492         *
00493         *  @param[in] fX
00494         *    X component of the vector to rotate
00495         *  @param[in] fY
00496         *    Y component of the vector to rotate
00497         *  @param[in] fZ
00498         *    Z component of the vector to rotate
00499         *  @param[in] bUniformScale
00500         *    Is this a uniform scale matrix? (all axis are scaled equally)
00501         *    If you know EXACTLY it's one, set this to 'true' to gain some more speed, else DON'T set to 'true'!
00502         *
00503         *  @return
00504         *    The rotated vector
00505         *
00506         *  @remarks
00507         *    This function is similar to a matrix * vector operation - except that it
00508         *    can also deal with none uniform scale. So, this function can for instance be
00509         *    used to rotate a direction vector. (matrix * direction vector)
00510         *
00511         *  @note
00512         *    - You can't assume that the resulting vector is normalized
00513         *    - Use this function to rotate for example a normal vector
00514         */
00515         PLMATH_API Vector3 RotateVector(float fX, float fY, float fZ, bool bUniformScale = false) const;
00516 
00517         /**
00518         *  @brief
00519         *    Rotates a vector
00520         *
00521         *  @param[in] vV
00522         *    Vector to rotate
00523         *  @param[in] bUniformScale
00524         *    Is this a uniform scale matrix? (all axis are scaled equally)
00525         *    If you know EXACTLY it's one, set this to 'true' to gain some more speed, else DON'T set to 'true'!
00526         *
00527         *  @return
00528         *    The rotated vector
00529         *
00530         *  @see
00531         *    - RotateVector(float, float, float) above
00532         */
00533         PLMATH_API Vector3 RotateVector(const Vector3 &vV, bool bUniformScale = false) const;
00534 
00535         //[-------------------------------------------------------]
00536         //[ Scale                                                 ]
00537         //[-------------------------------------------------------]
00538         /**
00539         *  @brief
00540         *    Sets a scale matrix
00541         *
00542         *  @param[in] fX
00543         *    X scale
00544         *  @param[in] fY
00545         *    Y scale
00546         *  @param[in] fZ
00547         *    Z scale
00548         *
00549         *  @remarks
00550         *    @code
00551         *    | x 0 0 |
00552         *    | 0 y 0 |
00553         *    | 0 0 z |
00554         *    @endcode
00555         */
00556         inline void SetScaleMatrix(float fX, float fY, float fZ);
00557         inline void SetScaleMatrix(const Vector3 &vV);
00558 
00559         /**
00560         *  @brief
00561         *    Extracts the scale vector from the matrix as good as possible
00562         *
00563         *  @param[out] fX
00564         *    Receives the x scale
00565         *  @param[out] fY
00566         *    Receives the y scale
00567         *  @param[out] fZ
00568         *    Receives the z scale
00569         *
00570         *  @note
00571         *    - This function will not work correctly if one or two components are negative while
00572         *      another is/are not (we can't figure out WHICH axis are negative!)
00573         */
00574         PLMATH_API void GetScale(float &fX, float &fY, float &fZ) const;
00575         inline Vector3 GetScale() const;
00576         inline void GetScale(float fV[]) const;
00577 
00578         //[-------------------------------------------------------]
00579         //[ Rotation                                              ]
00580         //[-------------------------------------------------------]
00581         /**
00582         *  @brief
00583         *    Sets an x axis rotation matrix by using one given Euler angle
00584         *
00585         *  @param[in] fAngleX
00586         *    Rotation angle around the x axis (in radian, between [0, Math::Pi2])
00587         *
00588         *  @remarks
00589         *    @code
00590         *         |    1       0       0    |
00591         *    RX = |    0     cos(a) -sin(a) |
00592         *         |    0     sin(a)  cos(a) |
00593         *    @endcode
00594         *    where a > 0 indicates a counterclockwise rotation in the yz-plane (if you look along -x)
00595         */
00596         PLMATH_API void FromEulerAngleX(float fAngleX);
00597 
00598         /**
00599         *  @brief
00600         *    Sets an y axis rotation matrix by using one given Euler angle
00601         *
00602         *  @param[in] fAngleY
00603         *    Rotation angle around the y axis (in radian, between [0, Math::Pi2])
00604         *
00605         *  @remarks
00606         *    @code
00607         *         |  cos(a)    0     sin(a) |
00608         *    RY = |    0       1       0    |
00609         *         | -sin(a)    0     cos(a) |
00610         *    @endcode
00611         *    where a > 0 indicates a counterclockwise rotation in the zx-plane (if you look along -y)
00612         */
00613         PLMATH_API void FromEulerAngleY(float fAngleY);
00614 
00615         /**
00616         *  @brief
00617         *    Sets an z axis rotation matrix by using one given Euler angle
00618         *
00619         *  @param[in] fAngleZ
00620         *    Rotation angle around the z axis (in radian, between [0, Math::Pi2])
00621         *
00622         *  @remarks
00623         *    @code
00624         *         |  cos(a) -sin(a)    0    |
00625         *    RZ = |  sin(a)  cos(a)    0    |
00626         *         |    0       0       1    |
00627         *    @endcode
00628         *    where a > 0 indicates a counterclockwise rotation in the xy-plane (if you look along -z)
00629         */
00630         PLMATH_API void FromEulerAngleZ(float fAngleZ);
00631 
00632         /**
00633         *  @brief
00634         *    Returns a rotation matrix as a selected axis and angle
00635         *
00636         *  @param[out] fX
00637         *    Will receive the x component of the selected axis
00638         *  @param[out] fY
00639         *    Will receive the y component of the selected axis
00640         *  @param[out] fZ
00641         *    Will receive the z component of the selected axis
00642         *  @param[out] fAngle
00643         *    Will receive the rotation angle around the selected axis (in radian, between [0, Math::Pi])
00644         */
00645         PLMATH_API void ToAxisAngle(float &fX, float &fY, float &fZ, float &fAngle) const;
00646 
00647         /**
00648         *  @brief
00649         *    Sets a rotation matrix by using a selected axis and angle
00650         *
00651         *  @param[in] fX
00652         *    X component of the selected axis
00653         *  @param[in] fY
00654         *    Y component of the selected axis
00655         *  @param[in] fZ
00656         *    Z component of the selected axis
00657         *  @param[in] fAngle
00658         *    Rotation angle around the selected axis (in radian, between [0, Math::Pi])
00659         *
00660         *  @note
00661         *    - The given selected axis must be normalized!
00662         */
00663         PLMATH_API void FromAxisAngle(float fX, float fY, float fZ, float fAngle);
00664 
00665         /**
00666         *  @brief
00667         *    Returns the x (left) axis
00668         *
00669         *  @return
00670         *    The x (left) axis
00671         *
00672         *  @remarks
00673         *    @code
00674         *    | x 0 0 |
00675         *    | y 0 0 |
00676         *    | z 0 0 |
00677         *    @endcode
00678         *
00679         *  @note
00680         *    - It's possible that the axis vector is not normalized because for instance
00681         *      the matrix was scaled
00682         */
00683         inline Vector3 GetXAxis() const;
00684 
00685         /**
00686         *  @brief
00687         *    Returns the y (up) axis
00688         *
00689         *  @return
00690         *    The y (up) axis
00691         *
00692         *  @remarks
00693         *    @code
00694         *    | 0 x 0 |
00695         *    | 0 y 0 |
00696         *    | 0 z 0 |
00697         *    @endcode
00698         *
00699         *  @see
00700         *    - GetXAxis()
00701         */
00702         inline Vector3 GetYAxis() const;
00703 
00704         /**
00705         *  @brief
00706         *    Returns the z (forward) axis
00707         *
00708         *  @return
00709         *    The z (forward) axis
00710         *
00711         *  @remarks
00712         *    @code
00713         *    | 0 0 x |
00714         *    | 0 0 y |
00715         *    | 0 0 z |
00716         *    @endcode
00717         *
00718         *  @see
00719         *    - GetXAxis()
00720         */
00721         inline Vector3 GetZAxis() const;
00722 
00723         /**
00724         *  @brief
00725         *    Returns the three axis of a rotation matrix (not normalized)
00726         *
00727         *  @param[out] vX
00728         *    Will receive the x axis
00729         *  @param[out] vY
00730         *    Will receive the y axis
00731         *  @param[out] vZ
00732         *    Will receive the z axis
00733         *
00734         *  @remarks
00735         *    @code
00736         *    | vX.x vY.x vZ.x |
00737         *    | vX.y vY.y vZ.y |
00738         *    | vX.z vY.z vZ.z |
00739         *    @endcode
00740         */
00741         PLMATH_API void ToAxis(Vector3 &vX, Vector3 &vY, Vector3 &vZ) const;
00742 
00743         /**
00744         *  @brief
00745         *    Sets a rotation matrix by using three given axis
00746         *
00747         *  @param[in] vX
00748         *    X axis
00749         *  @param[in] vY
00750         *    Y axis
00751         *  @param[in] vZ
00752         *    Z axis
00753         *
00754         *  @see
00755         *    - ToAxis()
00756         */
00757         PLMATH_API void FromAxis(const Vector3 &vX, const Vector3 &vY, const Vector3 &vZ);
00758 
00759         /**
00760         *  @brief
00761         *    Builds a look-at matrix
00762         *
00763         *  @param[in] vEye
00764         *    Eye position
00765         *  @param[in] vAt
00766         *    Camera look-at target
00767         *  @param[in] vUp
00768         *    Current world's up, usually [0, 1, 0]
00769         *
00770         *  @return
00771         *    This instance
00772         */
00773         PLMATH_API Matrix3x3 &LookAt(const Vector3 &vEye, const Vector3 &vAt, const Vector3 &vUp);
00774 
00775         //[-------------------------------------------------------]
00776         //[ Misc                                                  ]
00777         //[-------------------------------------------------------]
00778         /**
00779         *  @brief
00780         *    Sets a shearing matrix
00781         *
00782         *  @param[in] fShearXY
00783         *    Shear X by Y
00784         *  @param[in] fShearXZ
00785         *    Shear X by Z
00786         *  @param[in] fShearYX
00787         *    Shear Y by X
00788         *  @param[in] fShearYZ
00789         *    Shear Y by Z
00790         *  @param[in] fShearZX
00791         *    Shear Z by X
00792         *  @param[in] fShearZY
00793         *    Shear Z by Y
00794         *
00795         *  @return
00796         *    This instance
00797         *
00798         *  @remarks
00799         *    A shearing matrix can be used to for instance make a 3D model appear to slant
00800         *    sideways. Here's a table showing how a combined shearing matrix looks like:
00801         *    @code
00802         *    | 1        fShearYX  fShearZX  |
00803         *    | fShearXY 1         fShearZY  |
00804         *    | fShearXZ fShearYZ  1         |
00805         *    @endcode
00806         *    If you only want to shear one axis it's recommended to construct the matrix by yourself.
00807         */
00808         inline Matrix3x3 &SetShearing(float fShearXY, float fShearXZ, float fShearYX, float fShearYZ,
00809                                       float fShearZX, float fShearZY);
00810 
00811 
00812 };
00813 
00814 
00815 //[-------------------------------------------------------]
00816 //[ Namespace                                             ]
00817 //[-------------------------------------------------------]
00818 } // PLMath
00819 
00820 
00821 //[-------------------------------------------------------]
00822 //[ Implementation                                        ]
00823 //[-------------------------------------------------------]
00824 #include "PLMath/Matrix3x3.inl"
00825 
00826 
00827 #endif // __PLMATH_MATRIX3X3_H__


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:08:57
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported