RotationBetween() публичный статический Метод

Returns a quaternion representing the rotation between vectors Not robust, but faster
public static RotationBetween ( OpenTK.Vector3 from, OpenTK.Vector3 to ) : Quaternion
from OpenTK.Vector3 The vetor the rotation start from
to OpenTK.Vector3 The vector the quaternion should result in if from vector was transformed by the resulting Quaternion
Результат Quaternion
Пример #1
0
        /// <summary>
        /// Test wheter a bone has moved unatural much since last frame
        /// </summary>
        /// <param name="bones">The skeleton, a tree of bones</param>
        /// <returns>True if any changes has been applied to the skeleton</returns>
        private bool JerkingTest(TreeNode <Bone> bones, bool pos = true, bool rot = true)
        {
            bool hasChanges = false;

            foreach (TreeNode <Bone> bone in bones)
            {
                if (bone.IsRoot || bone.Data.HasNaN)
                {
                    continue;
                }
                Bone lastFrameBone = lastSkel.Root.FindTreeNode(tn => tn.Data.Name == bone.Data.Name).Data;

                #region Poss
                if (pos && bone != bones)
                {
                    Vector3 posInitial         = lastFrameBone.Pos;
                    Vector3 diffInitToFinalVec = (bone.Data.Pos - posInitial);
                    if (diffInitToFinalVec.Length > 0.025f)
                    {
                        diffInitToFinalVec.NormalizeFast();
                        diffInitToFinalVec *= 0.025f;
                        Quaternion rotToNewPos =
                            QuaternionHelper2.RotationBetween(
                                bone.Parent.Data.GetYAxis(),
                                ((posInitial + diffInitToFinalVec) - bone.Parent.Data.Pos));
                        FK(bone.Parent, rotToNewPos);
                        hasChanges = true;
                    }
                }
                #endregion
                #region Rots
                if (rot)
                {
                    Quaternion oriFinal   = bone.Data.Orientation;
                    Quaternion oriInitial = lastFrameBone.Orientation;
                    if (!bone.IsLeaf)
                    {
                        float quatDiff = QuaternionHelper2.DifferenceBetween(oriFinal, oriInitial);
                        if (quatDiff > 0.03f)
                        {
                            float      slerp  = (1 - quatDiff) - (Mathf.Cos((MathHelper.Pi * quatDiff) / 2) - (1 - quatDiff * 0.8f));
                            Quaternion qTrans = Quaternion.Invert(
                                Quaternion.Slerp(oriInitial, oriFinal, slerp)
                                * Quaternion.Invert(oriInitial));
                            FK(bone, qTrans);
                            hasChanges = true;
                        }
                    }
                }
                #endregion
            }
            return(hasChanges);
        }