vrshoot

annotate libs/assimp/assimp/matrix4x4.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
rev   line source
nuclear@0 1 /*
nuclear@0 2 ---------------------------------------------------------------------------
nuclear@0 3 Open Asset Import Library (assimp)
nuclear@0 4 ---------------------------------------------------------------------------
nuclear@0 5
nuclear@0 6 Copyright (c) 2006-2012, assimp team
nuclear@0 7
nuclear@0 8 All rights reserved.
nuclear@0 9
nuclear@0 10 Redistribution and use of this software in source and binary forms,
nuclear@0 11 with or without modification, are permitted provided that the following
nuclear@0 12 conditions are met:
nuclear@0 13
nuclear@0 14 * Redistributions of source code must retain the above
nuclear@0 15 copyright notice, this list of conditions and the
nuclear@0 16 following disclaimer.
nuclear@0 17
nuclear@0 18 * Redistributions in binary form must reproduce the above
nuclear@0 19 copyright notice, this list of conditions and the
nuclear@0 20 following disclaimer in the documentation and/or other
nuclear@0 21 materials provided with the distribution.
nuclear@0 22
nuclear@0 23 * Neither the name of the assimp team, nor the names of its
nuclear@0 24 contributors may be used to endorse or promote products
nuclear@0 25 derived from this software without specific prior
nuclear@0 26 written permission of the assimp team.
nuclear@0 27
nuclear@0 28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 39 ---------------------------------------------------------------------------
nuclear@0 40 */
nuclear@0 41 /** @file matrix4x4.h
nuclear@0 42 * @brief 4x4 matrix structure, including operators when compiling in C++
nuclear@0 43 */
nuclear@0 44 #ifndef AI_MATRIX4X4_H_INC
nuclear@0 45 #define AI_MATRIX4X4_H_INC
nuclear@0 46
nuclear@0 47 #include "./Compiler/pushpack1.h"
nuclear@0 48
nuclear@0 49 #ifdef __cplusplus
nuclear@0 50
nuclear@0 51 template<typename TReal> class aiMatrix3x3t;
nuclear@0 52 template<typename TReal> class aiQuaterniont;
nuclear@0 53
nuclear@0 54 // ---------------------------------------------------------------------------
nuclear@0 55 /** @brief Represents a row-major 4x4 matrix, use this for homogeneous
nuclear@0 56 * coordinates.
nuclear@0 57 *
nuclear@0 58 * There's much confusion about matrix layouts (column vs. row order).
nuclear@0 59 * This is *always* a row-major matrix. Not even with the
nuclear@0 60 * #aiProcess_ConvertToLeftHanded flag, which absolutely does not affect
nuclear@0 61 * matrix order - it just affects the handedness of the coordinate system
nuclear@0 62 * defined thereby.
nuclear@0 63 */
nuclear@0 64 template<typename TReal>
nuclear@0 65 class aiMatrix4x4t
nuclear@0 66 {
nuclear@0 67 public:
nuclear@0 68
nuclear@0 69 /** set to identity */
nuclear@0 70 aiMatrix4x4t ();
nuclear@0 71
nuclear@0 72 /** construction from single values */
nuclear@0 73 aiMatrix4x4t ( TReal _a1, TReal _a2, TReal _a3, TReal _a4,
nuclear@0 74 TReal _b1, TReal _b2, TReal _b3, TReal _b4,
nuclear@0 75 TReal _c1, TReal _c2, TReal _c3, TReal _c4,
nuclear@0 76 TReal _d1, TReal _d2, TReal _d3, TReal _d4);
nuclear@0 77
nuclear@0 78
nuclear@0 79 /** construction from 3x3 matrix, remaining elements are set to identity */
nuclear@0 80 explicit aiMatrix4x4t( const aiMatrix3x3t<TReal>& m);
nuclear@0 81
nuclear@0 82 public:
nuclear@0 83
nuclear@0 84 // array access operators
nuclear@0 85 TReal* operator[] (unsigned int p_iIndex);
nuclear@0 86 const TReal* operator[] (unsigned int p_iIndex) const;
nuclear@0 87
nuclear@0 88 // comparison operators
nuclear@0 89 bool operator== (const aiMatrix4x4t m) const;
nuclear@0 90 bool operator!= (const aiMatrix4x4t m) const;
nuclear@0 91
nuclear@0 92 // matrix multiplication.
nuclear@0 93 aiMatrix4x4t& operator *= (const aiMatrix4x4t& m);
nuclear@0 94 aiMatrix4x4t operator * (const aiMatrix4x4t& m) const;
nuclear@0 95
nuclear@0 96 template <typename TOther>
nuclear@0 97 operator aiMatrix4x4t<TOther> () const;
nuclear@0 98
nuclear@0 99 public:
nuclear@0 100
nuclear@0 101 // -------------------------------------------------------------------
nuclear@0 102 /** @brief Transpose the matrix */
nuclear@0 103 aiMatrix4x4t& Transpose();
nuclear@0 104
nuclear@0 105 // -------------------------------------------------------------------
nuclear@0 106 /** @brief Invert the matrix.
nuclear@0 107 * If the matrix is not invertible all elements are set to qnan.
nuclear@0 108 * Beware, use (f != f) to check whether a TReal f is qnan.
nuclear@0 109 */
nuclear@0 110 aiMatrix4x4t& Inverse();
nuclear@0 111 TReal Determinant() const;
nuclear@0 112
nuclear@0 113
nuclear@0 114 // -------------------------------------------------------------------
nuclear@0 115 /** @brief Returns true of the matrix is the identity matrix.
nuclear@0 116 * The check is performed against a not so small epsilon.
nuclear@0 117 */
nuclear@0 118 inline bool IsIdentity() const;
nuclear@0 119
nuclear@0 120 // -------------------------------------------------------------------
nuclear@0 121 /** @brief Decompose a trafo matrix into its original components
nuclear@0 122 * @param scaling Receives the output scaling for the x,y,z axes
nuclear@0 123 * @param rotation Receives the output rotation as a hamilton
nuclear@0 124 * quaternion
nuclear@0 125 * @param position Receives the output position for the x,y,z axes
nuclear@0 126 */
nuclear@0 127 void Decompose (aiVector3t<TReal>& scaling, aiQuaterniont<TReal>& rotation,
nuclear@0 128 aiVector3t<TReal>& position) const;
nuclear@0 129
nuclear@0 130 // -------------------------------------------------------------------
nuclear@0 131 /** @brief Decompose a trafo matrix with no scaling into its
nuclear@0 132 * original components
nuclear@0 133 * @param rotation Receives the output rotation as a hamilton
nuclear@0 134 * quaternion
nuclear@0 135 * @param position Receives the output position for the x,y,z axes
nuclear@0 136 */
nuclear@0 137 void DecomposeNoScaling (aiQuaterniont<TReal>& rotation,
nuclear@0 138 aiVector3t<TReal>& position) const;
nuclear@0 139
nuclear@0 140
nuclear@0 141 // -------------------------------------------------------------------
nuclear@0 142 /** @brief Creates a trafo matrix from a set of euler angles
nuclear@0 143 * @param x Rotation angle for the x-axis, in radians
nuclear@0 144 * @param y Rotation angle for the y-axis, in radians
nuclear@0 145 * @param z Rotation angle for the z-axis, in radians
nuclear@0 146 */
nuclear@0 147 aiMatrix4x4t& FromEulerAnglesXYZ(TReal x, TReal y, TReal z);
nuclear@0 148 aiMatrix4x4t& FromEulerAnglesXYZ(const aiVector3t<TReal>& blubb);
nuclear@0 149
nuclear@0 150 public:
nuclear@0 151 // -------------------------------------------------------------------
nuclear@0 152 /** @brief Returns a rotation matrix for a rotation around the x axis
nuclear@0 153 * @param a Rotation angle, in radians
nuclear@0 154 * @param out Receives the output matrix
nuclear@0 155 * @return Reference to the output matrix
nuclear@0 156 */
nuclear@0 157 static aiMatrix4x4t& RotationX(TReal a, aiMatrix4x4t& out);
nuclear@0 158
nuclear@0 159 // -------------------------------------------------------------------
nuclear@0 160 /** @brief Returns a rotation matrix for a rotation around the y axis
nuclear@0 161 * @param a Rotation angle, in radians
nuclear@0 162 * @param out Receives the output matrix
nuclear@0 163 * @return Reference to the output matrix
nuclear@0 164 */
nuclear@0 165 static aiMatrix4x4t& RotationY(TReal a, aiMatrix4x4t& out);
nuclear@0 166
nuclear@0 167 // -------------------------------------------------------------------
nuclear@0 168 /** @brief Returns a rotation matrix for a rotation around the z axis
nuclear@0 169 * @param a Rotation angle, in radians
nuclear@0 170 * @param out Receives the output matrix
nuclear@0 171 * @return Reference to the output matrix
nuclear@0 172 */
nuclear@0 173 static aiMatrix4x4t& RotationZ(TReal a, aiMatrix4x4t& out);
nuclear@0 174
nuclear@0 175 // -------------------------------------------------------------------
nuclear@0 176 /** Returns a rotation matrix for a rotation around an arbitrary axis.
nuclear@0 177 * @param a Rotation angle, in radians
nuclear@0 178 * @param axis Rotation axis, should be a normalized vector.
nuclear@0 179 * @param out Receives the output matrix
nuclear@0 180 * @return Reference to the output matrix
nuclear@0 181 */
nuclear@0 182 static aiMatrix4x4t& Rotation(TReal a, const aiVector3t<TReal>& axis,
nuclear@0 183 aiMatrix4x4t& out);
nuclear@0 184
nuclear@0 185 // -------------------------------------------------------------------
nuclear@0 186 /** @brief Returns a translation matrix
nuclear@0 187 * @param v Translation vector
nuclear@0 188 * @param out Receives the output matrix
nuclear@0 189 * @return Reference to the output matrix
nuclear@0 190 */
nuclear@0 191 static aiMatrix4x4t& Translation( const aiVector3t<TReal>& v, aiMatrix4x4t& out);
nuclear@0 192
nuclear@0 193 // -------------------------------------------------------------------
nuclear@0 194 /** @brief Returns a scaling matrix
nuclear@0 195 * @param v Scaling vector
nuclear@0 196 * @param out Receives the output matrix
nuclear@0 197 * @return Reference to the output matrix
nuclear@0 198 */
nuclear@0 199 static aiMatrix4x4t& Scaling( const aiVector3t<TReal>& v, aiMatrix4x4t& out);
nuclear@0 200
nuclear@0 201 // -------------------------------------------------------------------
nuclear@0 202 /** @brief A function for creating a rotation matrix that rotates a
nuclear@0 203 * vector called "from" into another vector called "to".
nuclear@0 204 * Input : from[3], to[3] which both must be *normalized* non-zero vectors
nuclear@0 205 * Output: mtx[3][3] -- a 3x3 matrix in colum-major form
nuclear@0 206 * Authors: Tomas Möller, John Hughes
nuclear@0 207 * "Efficiently Building a Matrix to Rotate One Vector to Another"
nuclear@0 208 * Journal of Graphics Tools, 4(4):1-4, 1999
nuclear@0 209 */
nuclear@0 210 static aiMatrix4x4t& FromToMatrix(const aiVector3t<TReal>& from,
nuclear@0 211 const aiVector3t<TReal>& to, aiMatrix4x4t& out);
nuclear@0 212
nuclear@0 213 public:
nuclear@0 214
nuclear@0 215 TReal a1, a2, a3, a4;
nuclear@0 216 TReal b1, b2, b3, b4;
nuclear@0 217 TReal c1, c2, c3, c4;
nuclear@0 218 TReal d1, d2, d3, d4;
nuclear@0 219
nuclear@0 220 } PACK_STRUCT;
nuclear@0 221
nuclear@0 222 typedef aiMatrix4x4t<float> aiMatrix4x4;
nuclear@0 223
nuclear@0 224 #else
nuclear@0 225
nuclear@0 226 struct aiMatrix4x4 {
nuclear@0 227 float a1, a2, a3, a4;
nuclear@0 228 float b1, b2, b3, b4;
nuclear@0 229 float c1, c2, c3, c4;
nuclear@0 230 float d1, d2, d3, d4;
nuclear@0 231 };
nuclear@0 232
nuclear@0 233
nuclear@0 234 #endif // __cplusplus
nuclear@0 235
nuclear@0 236 #include "./Compiler/poppack1.h"
nuclear@0 237
nuclear@0 238 #endif // AI_MATRIX4X4_H_INC