miniassimp

diff include/miniassimp/matrix3x3.h @ 0:879c81d94345

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Jan 2019 18:19:26 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/miniassimp/matrix3x3.h	Mon Jan 28 18:19:26 2019 +0200
     1.3 @@ -0,0 +1,183 @@
     1.4 +/*
     1.5 +---------------------------------------------------------------------------
     1.6 +Open Asset Import Library (assimp)
     1.7 +---------------------------------------------------------------------------
     1.8 +
     1.9 +Copyright (c) 2006-2018, assimp team
    1.10 +
    1.11 +
    1.12 +
    1.13 +All rights reserved.
    1.14 +
    1.15 +Redistribution and use of this software in source and binary forms,
    1.16 +with or without modification, are permitted provided that the following
    1.17 +conditions are met:
    1.18 +
    1.19 +* Redistributions of source code must retain the above
    1.20 +  copyright notice, this list of conditions and the
    1.21 +  following disclaimer.
    1.22 +
    1.23 +* Redistributions in binary form must reproduce the above
    1.24 +  copyright notice, this list of conditions and the
    1.25 +  following disclaimer in the documentation and/or other
    1.26 +  materials provided with the distribution.
    1.27 +
    1.28 +* Neither the name of the assimp team, nor the names of its
    1.29 +  contributors may be used to endorse or promote products
    1.30 +  derived from this software without specific prior
    1.31 +  written permission of the assimp team.
    1.32 +
    1.33 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.34 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.35 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.36 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.37 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.38 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.39 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.40 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.41 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.42 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.43 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.44 +---------------------------------------------------------------------------
    1.45 +*/
    1.46 +
    1.47 +/** @file matrix3x3.h
    1.48 + *  @brief Definition of a 3x3 matrix, including operators when compiling in C++
    1.49 + */
    1.50 +#pragma once
    1.51 +#ifndef AI_MATRIX3X3_H_INC
    1.52 +#define AI_MATRIX3X3_H_INC
    1.53 +
    1.54 +#include "defs.h"
    1.55 +
    1.56 +#ifdef __cplusplus
    1.57 +
    1.58 +template <typename T> class aiMatrix4x4t;
    1.59 +template <typename T> class aiVector2t;
    1.60 +
    1.61 +// ---------------------------------------------------------------------------
    1.62 +/** @brief Represents a row-major 3x3 matrix
    1.63 + *
    1.64 + *  There's much confusion about matrix layouts (column vs. row order).
    1.65 + *  This is *always* a row-major matrix. Not even with the
    1.66 + *  #aiProcess_ConvertToLeftHanded flag, which absolutely does not affect
    1.67 + *  matrix order - it just affects the handedness of the coordinate system
    1.68 + *  defined thereby.
    1.69 + */
    1.70 +template <typename TReal>
    1.71 +class aiMatrix3x3t
    1.72 +{
    1.73 +public:
    1.74 +
    1.75 +    aiMatrix3x3t() AI_NO_EXCEPT :
    1.76 +        a1(static_cast<TReal>(1.0f)), a2(), a3(),
    1.77 +        b1(), b2(static_cast<TReal>(1.0f)), b3(),
    1.78 +        c1(), c2(), c3(static_cast<TReal>(1.0f)) {}
    1.79 +
    1.80 +    aiMatrix3x3t (  TReal _a1, TReal _a2, TReal _a3,
    1.81 +                    TReal _b1, TReal _b2, TReal _b3,
    1.82 +                    TReal _c1, TReal _c2, TReal _c3) :
    1.83 +        a1(_a1), a2(_a2), a3(_a3),
    1.84 +        b1(_b1), b2(_b2), b3(_b3),
    1.85 +        c1(_c1), c2(_c2), c3(_c3)
    1.86 +    {}
    1.87 +
    1.88 +public:
    1.89 +
    1.90 +    // matrix multiplication.
    1.91 +    aiMatrix3x3t& operator *= (const aiMatrix3x3t& m);
    1.92 +    aiMatrix3x3t  operator  * (const aiMatrix3x3t& m) const;
    1.93 +
    1.94 +    // array access operators
    1.95 +    TReal* operator[]       (unsigned int p_iIndex);
    1.96 +    const TReal* operator[] (unsigned int p_iIndex) const;
    1.97 +
    1.98 +    // comparison operators
    1.99 +    bool operator== (const aiMatrix4x4t<TReal>& m) const;
   1.100 +    bool operator!= (const aiMatrix4x4t<TReal>& m) const;
   1.101 +
   1.102 +    bool Equal(const aiMatrix4x4t<TReal>& m, TReal epsilon = 1e-6) const;
   1.103 +
   1.104 +    template <typename TOther>
   1.105 +    operator aiMatrix3x3t<TOther> () const;
   1.106 +
   1.107 +public:
   1.108 +
   1.109 +    // -------------------------------------------------------------------
   1.110 +    /** @brief Construction from a 4x4 matrix. The remaining parts
   1.111 +     *  of the matrix are ignored.
   1.112 +     */
   1.113 +    explicit aiMatrix3x3t( const aiMatrix4x4t<TReal>& pMatrix);
   1.114 +
   1.115 +    // -------------------------------------------------------------------
   1.116 +    /** @brief Transpose the matrix
   1.117 +     */
   1.118 +    aiMatrix3x3t& Transpose();
   1.119 +
   1.120 +    // -------------------------------------------------------------------
   1.121 +    /** @brief Invert the matrix.
   1.122 +     *  If the matrix is not invertible all elements are set to qnan.
   1.123 +     *  Beware, use (f != f) to check whether a TReal f is qnan.
   1.124 +     */
   1.125 +    aiMatrix3x3t& Inverse();
   1.126 +    TReal Determinant() const;
   1.127 +
   1.128 +public:
   1.129 +    // -------------------------------------------------------------------
   1.130 +    /** @brief Returns a rotation matrix for a rotation around z
   1.131 +     *  @param a Rotation angle, in radians
   1.132 +     *  @param out Receives the output matrix
   1.133 +     *  @return Reference to the output matrix
   1.134 +     */
   1.135 +    static aiMatrix3x3t& RotationZ(TReal a, aiMatrix3x3t& out);
   1.136 +
   1.137 +    // -------------------------------------------------------------------
   1.138 +    /** @brief Returns a rotation matrix for a rotation around
   1.139 +     *    an arbitrary axis.
   1.140 +     *
   1.141 +     *  @param a Rotation angle, in radians
   1.142 +     *  @param axis Axis to rotate around
   1.143 +     *  @param out To be filled
   1.144 +     */
   1.145 +    static aiMatrix3x3t& Rotation( TReal a,
   1.146 +        const aiVector3t<TReal>& axis, aiMatrix3x3t& out);
   1.147 +
   1.148 +    // -------------------------------------------------------------------
   1.149 +    /** @brief Returns a translation matrix
   1.150 +     *  @param v Translation vector
   1.151 +     *  @param out Receives the output matrix
   1.152 +     *  @return Reference to the output matrix
   1.153 +     */
   1.154 +    static aiMatrix3x3t& Translation( const aiVector2t<TReal>& v, aiMatrix3x3t& out);
   1.155 +
   1.156 +    // -------------------------------------------------------------------
   1.157 +    /** @brief A function for creating a rotation matrix that rotates a
   1.158 +     *  vector called "from" into another vector called "to".
   1.159 +     * Input : from[3], to[3] which both must be *normalized* non-zero vectors
   1.160 +     * Output: mtx[3][3] -- a 3x3 matrix in column-major form
   1.161 +     * Authors: Tomas Möller, John Hughes
   1.162 +     *          "Efficiently Building a Matrix to Rotate One Vector to Another"
   1.163 +     *          Journal of Graphics Tools, 4(4):1-4, 1999
   1.164 +     */
   1.165 +    static aiMatrix3x3t& FromToMatrix(const aiVector3t<TReal>& from,
   1.166 +        const aiVector3t<TReal>& to, aiMatrix3x3t& out);
   1.167 +
   1.168 +public:
   1.169 +    TReal a1, a2, a3;
   1.170 +    TReal b1, b2, b3;
   1.171 +    TReal c1, c2, c3;
   1.172 +};
   1.173 +
   1.174 +typedef aiMatrix3x3t<ai_real> aiMatrix3x3;
   1.175 +
   1.176 +#else
   1.177 +
   1.178 +struct aiMatrix3x3 {
   1.179 +    ai_real a1, a2, a3;
   1.180 +    ai_real b1, b2, b3;
   1.181 +    ai_real c1, c2, c3;
   1.182 +};
   1.183 +
   1.184 +#endif // __cplusplus
   1.185 +
   1.186 +#endif // AI_MATRIX3X3_H_INC