bool RotDir(const XMVECTOR& dir_from, const XMVECTOR& dir_to, float ang_limit, XMVECTOR* axis, float* ang) { XMVECTOR eps0 = XMVectorSet(0.0005f, 0.0005f, 0.0005f, 1.0f); //XMVECTOR eps0 = { 0.0000001f, 0.0000001f, 0.0000001f, 0.0000001f }; XMVECTOR ik_dir = XMVector3Normalize(dir_to); XMVECTOR tg_dir = XMVector3Normalize(dir_from); if (XMVector3NearEqual(tg_dir, ik_dir, eps0)){ return false; } // 回転軸と角度 eps0 = XMVectorSet(0.0000001f, 0.0000001f, 0.0000001f, 1.0f); //XMVectorSet(0.0005f, 0.0005f, 0.0005f, 0.0f); XMVECTOR rot_axis = XMVector3Cross(tg_dir, ik_dir); if (XMVector3NearEqual(rot_axis, XMVectorSet(0, 0, 0, 0), eps0)){ return false; } *axis = XMVector3Normalize(rot_axis); *ang = XMVectorGetX(XMVectorACos(XMVector3Dot(tg_dir, ik_dir))); // 回転量制限 if (*ang > ang_limit)*ang = ang_limit; if (*ang < -ang_limit)*ang = -ang_limit; return true; }
bool MathHelper::CompareVector3WithEpsilon(const XMFLOAT3& lhs, const XMFLOAT3& rhs) { return XMVector3NearEqual(XMLoadFloat3(&lhs), XMLoadFloat3(&rhs), XMLoadFloat3(&vector3Epsilon)) == TRUE; }