⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xquaternion.inl

📁 XMathLib是一个通用的3D图形数学库。 其中包含两个部分: XMathLib和XGeomLib。分别处理数学和几何运算。 数学部分包含向量、矩阵、四元数的运算。以及其它的运算。 几何部分
💻 INL
字号:
#ifndef __XQUATERNION_INLINE_INCLUDE__ 
#define __XQUATERNION_INLINE_INCLUDE__ 

#ifndef IN_MATHLIB_NAMESPACE
#error   You cann't include this file out the XMathLib  namespace
#endif


    class  _MATH_LIB_EXPORT_ XQuaternion
    {
    public:
        XQuaternion(float _x,float _y,float _z,float _w):x(_x),y(_y),z(_z),w(_w){};
        XQuaternion(){x = 0.0f; y = 0.0f ; z = 0.0f;w = 1.0f;}
        float      magnitude(){return sqrt(x*x + y*y + z*z + w*w);}
        void       conjugate(){x = -x ; y = -y ; z =-z;}
        void       conjuagte(XQuaternion& out){out.x =-x; out.y = -y ; out.z = -z;}

        XQuaternion(XVector& axis,float angle = 0.0f)
        {
            angle = XM_Deg2Rad(angle);
            float angle2 = angle/2.0f;
            float sinangle2 = XM_SinR(angle2);
            float cosangle2 = XM_CosR(angle2);
            x = axis.x * sinangle2;
            y = axis.y * sinangle2;
            z = axis.z * sinangle2;

            w = axis.w * cosangle2;
        }
        XQuaternion& normalize()
        {
            float len = magnitude();
            x /= len;
            y /= len;
            z /= len;
            w /= len;
            return *this;
        }

        void normalize(XQuaternion& out)
        {
            float len = magnitude();
            out.x /= len;
            out.y /= len;
            out.z /= len;
            out.w /= len;
        }

        XQuaternion& XQuaternion::Inverse()
        {
            float n = x * x + y * y + z * z + w * w;
            n = -1.0f / n;
            x *= n;
            y *= n;
            z *= n;
            w *= n;
            return *this;
        }

        void XQuaternion::Inverse(XQuaternion& qOut)
        {
            float n = x * x + y * y + z * z + w * w;
            n = -1.0f / n;
            qOut.x = x*n;
            qOut.y = y*n;
            qOut.z = x*n;
            qOut.w = w*n;
            return ;
        }

    public:

        XMatrix              toMatrix();
        void                toMatrix(XMatrix& mOut);
        XQuaternion          operator * (XQuaternion& q2);
        XQuaternion          Slerp(float t,XQuaternion& q2);
        XVector              Rotate(XVector& vIn);

    public:
        float x;
        float y;
        float z;
        float w;
    };

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -