Esempio n. 1
0
    public RigidBoneSystemInputs ApplyDeltas(RigidBoneSystemInputs baseInputs, RigidBoneSystemInputs deltaInputs)
    {
        var sumInputs = new RigidBoneSystemInputs(bones.Length)
        {
        };

        RigidTransform baseRootTransform = RigidTransform.FromRotationTranslation(
            RootBone.GetRotation(baseInputs),
            baseInputs.RootTranslation);

        RigidTransform deltaRootTransform = RigidTransform.FromRotationTranslation(
            RootBone.GetRotation(deltaInputs),
            deltaInputs.RootTranslation);

        RigidTransform sumRootTransform = deltaRootTransform.Chain(baseRootTransform);

        sumInputs.RootTranslation = sumRootTransform.Translation;
        RootBone.SetRotation(sumInputs, sumRootTransform.Rotation);

        for (int boneIdx = 1; boneIdx < bones.Length; ++boneIdx)
        {
            var bone = bones[boneIdx];
            sumInputs.Rotations[boneIdx] = bone.Constraint.Clamp(
                TwistSwing.ApplyDelta(baseInputs.Rotations[boneIdx], deltaInputs.Rotations[boneIdx]));
        }

        return(sumInputs);
    }
Esempio n. 2
0
    public RigidBoneSystemInputs CalculateDeltas(RigidBoneSystemInputs baseInputs, RigidBoneSystemInputs sumInputs)
    {
        var deltaInputs = new RigidBoneSystemInputs(bones.Length)
        {
        };

        RigidTransform baseRootTransform = RigidTransform.FromRotationTranslation(
            RootBone.GetRotation(baseInputs),
            baseInputs.RootTranslation);

        RigidTransform sumRootTransform = RigidTransform.FromRotationTranslation(
            RootBone.GetRotation(sumInputs),
            sumInputs.RootTranslation);

        RigidTransform deltaRootTransform = sumRootTransform.Chain(baseRootTransform.Invert());

        deltaInputs.RootTranslation = deltaRootTransform.Translation;
        RootBone.SetRotation(deltaInputs, deltaRootTransform.Rotation);

        for (int boneIdx = 1; boneIdx < bones.Length; ++boneIdx)
        {
            var bone = bones[boneIdx];
            deltaInputs.Rotations[boneIdx] = TwistSwing.CalculateDelta(baseInputs.Rotations[boneIdx], sumInputs.Rotations[boneIdx]);
        }

        return(deltaInputs);
    }
    public RigidTransform GetOriginToBindPoseTransform(ChannelOutputs outputs)
    {
        Vector3    orientationAngles = Orientation.GetValue(outputs);
        Vector3    centerPoint       = CenterPoint.GetValue(outputs);
        Quaternion orientation       = RotationOrder.DazStandard.FromEulerAngles(MathExtensions.DegreesToRadians(orientationAngles));

        return(RigidTransform.FromRotationTranslation(orientation, centerPoint));
    }
Esempio n. 4
0
    public void TestFromAndToRotationTranslation()
    {
        Quaternion rotation    = Quaternion.RotationYawPitchRoll(1, 2, 3);
        Vector3    translation = new Vector3(2, 3, 4);

        RigidTransform transform = RigidTransform.FromRotationTranslation(rotation, translation);

        Assert.AreEqual(0, Vector3.Distance(translation, transform.Translation), 1e-6);
        Assert.IsTrue(transform.Rotation == rotation || transform.Rotation == -rotation);
    }
Esempio n. 5
0
    public void TestTransform()
    {
        Vector3    translation = new Vector3(2, 3, 4);
        Quaternion rotation    = Quaternion.RotationYawPitchRoll(1, 2, 3);
        Matrix     matrix      = Matrix.RotationQuaternion(rotation) * Matrix.Translation(translation);

        RigidTransform transform = RigidTransform.FromRotationTranslation(rotation, translation);

        Vector3 v = new Vector3(3, 4, 5);

        Assert.IsTrue(transform.Transform(v) == Vector3.TransformCoordinate(v, matrix));
    }
Esempio n. 6
0
    public void TestInvert()
    {
        Vector3        translation = new Vector3(2, 3, 4);
        Quaternion     rotation    = Quaternion.RotationYawPitchRoll(1, 2, 3);
        RigidTransform transform   = RigidTransform.FromRotationTranslation(rotation, translation);

        Vector3 v = new Vector3(3, 4, 5);

        Vector3 transformed        = transform.Transform(v);
        Vector3 inverseTransformed = transform.Invert().Transform(transformed);

        Assert.AreEqual(
            v,
            inverseTransformed);
    }