Ejemplo n.º 1
0
    private void SetTransform(Transform bone, Quaternion Rstandard, Quaternion Roffset, Vector3 Poffset)
    {
        // On récupère le composant DTrackPose
        DTrackPose pose = bone.GetComponent <DTrackPose>();
        // On applique le changement de repère spécifique à la pièce traquée
        Matrix4x4 newRotationMatrix = pose.inv_p * pose.body_desc.rotationMatrix * pose.p;
        // nouveau Quaternion
        Quaternion newOrientation = newRotationMatrix.ExtractQuaternion();
        //Quaternion quat = Quaternion.Inverse (Roffset) * pose.body_desc.orientation;
        Quaternion quat = Quaternion.Inverse(Roffset) * newOrientation;

        //bone.localRotation = Rstandard*quat;
        if (!(Mathf.Abs(quat.x) < eps && Mathf.Abs(quat.y) < eps && Mathf.Abs(quat.z) < eps && Mathf.Abs(quat.w) < eps))
        {
            bone.localRotation = Rstandard * Quaternion.Inverse(bone.parent.rotation) * quat;
            //bone.localRotation = Rstandard * quat;
        }
    }
Ejemplo n.º 2
0
    private void initListes(Transform parent)
    {
        if (parent.childCount == 0) //Si l'objet n'a pas d'enfant, il n'y a pas de nouveau bone à traiter
        {
            return;
        }

        for (int i = 0; i < parent.childCount; i++)
        {
            Transform  currentChild = parent.GetChild(i);
            DTrackPose pose         = currentChild.GetComponent <DTrackPose>();
            if (pose)
            {
                bones.Add(currentChild);
                rotationDtrack.Add(pose.body_desc.orientation);
                positionDtrack.Add(pose.body_desc.position);
            }

            initListes(currentChild);
        }
    }
Ejemplo n.º 3
0
    private DTrackPose getDtrackparent(GameObject child)
    {
        Transform parent = child.GetComponentInParent <Transform>();

        if (parent)
        {
            DTrackPose pose = parent.gameObject.GetComponent <DTrackPose>();
            if (pose)
            {
                return(pose);
            }
            else
            {
                pose = getDtrackparent(parent.gameObject);
                if (pose.id == -1)
                {
                    if (child.gameObject.GetComponent <DTrackPose>())
                    {
                        pose = child.gameObject.GetComponent <DTrackPose>();
                    }
                }
                return(pose);
            }
        }
        else
        {
            DTrackPose pose = child.gameObject.GetComponent <DTrackPose>();
            if (pose)
            {
                return(pose);
            }
            else
            {
                pose    = new DTrackPose();
                pose.id = -1;
                return(pose);
            }
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Recursive function to store all children having a DTrackPose component in the right order
    /// </summary>
    /// <param name="parent">Parent.</param>
    private void AddChildrenToList(Transform parent)
    {
        int n = parent.childCount;

        if (n == 0)
        {
            return;
        }
        for (int i = 0; i < n; i++)
        {
            currentChild = parent.GetChild(i);
            DTrackPose pose = currentChild.GetComponent <DTrackPose>();
            if (pose != null)
            {
                bones.Add(currentChild);                         // on ajoute à la table le transform de l'enfant
                rotationOffsets.Add(pose.body_desc.orientation); // on ajoute la première rotation envoyée par DTrack : ceci sera notre offset pour la suite
                rotationStandards.Add(currentChild.localRotation);
                //Debug.Log(pose.body_desc.orientation);
                positionOffsets.Add(pose.body_desc.position);
            }
            AddChildrenToList(currentChild);             // on traite les petits enfants
        }
    }