?? xquaternion.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 + -