Beispiel #1
0
        private InverseKinematicsGoal MaybeContinueTracking(FrameUpdateParameters updateParameters)
        {
            if (!tracking)
            {
                return(null);
            }

            if (!stateTracker.NonMenuActive)
            {
                tracking = false;
                return(null);
            }

            bool triggerPressed = stateTracker.IsPressed(EVRButtonId.k_EButton_SteamVR_Trigger);

            if (!triggerPressed)
            {
                tracking = false;
                return(null);
            }

            TrackedDevicePose_t gamePose = updateParameters.GamePoses[stateTracker.DeviceIdx];
            Matrix controllerTransform   = gamePose.mDeviceToAbsoluteTracking.Convert();
            var    controllerTransformDq = DualQuaternion.FromMatrix(controllerTransform);
            var    targetPosition        = controllerTransformDq.Translation * 100;
            var    targetOrientation     = controllerTransformDq.Rotation;

            return(new InverseKinematicsGoal(sourceBone,
                                             boneRelativeSourcePosition, boneRelativeSourceOrientation,
                                             targetPosition, targetOrientation));
        }
Beispiel #2
0
        private void MaybeStartTracking(FrameUpdateParameters updateParameters, RigidBoneSystemInputs inputs, ControlVertexInfo[] previousFrameControlVertexInfos)
        {
            if (tracking == true)
            {
                //already tracking
                return;
            }

            if (!stateTracker.NonMenuActive)
            {
                return;
            }

            bool triggerPressed = stateTracker.IsPressed(EVRButtonId.k_EButton_SteamVR_Trigger);

            if (!triggerPressed)
            {
                return;
            }

            tracking = true;

            TrackedDevicePose_t gamePose          = updateParameters.GamePoses[stateTracker.DeviceIdx];
            Matrix         controllerTransform    = gamePose.mDeviceToAbsoluteTracking.Convert();
            DualQuaternion controllerTransformDq  = DualQuaternion.FromMatrix(controllerTransform);
            var            worldSourcePosition    = controllerTransformDq.Translation * 100;
            var            worldSourceOrientation = controllerTransformDq.Rotation;

            sourceBone = parentInstance.MapPositionToBone(worldSourcePosition, previousFrameControlVertexInfos);
            var inverseSourceBoneTotalTransform = sourceBone.GetChainedTransform(inputs).Invert();

            boneRelativeSourcePosition    = inverseSourceBoneTotalTransform.Transform(worldSourcePosition) - sourceBone.CenterPoint;
            boneRelativeSourceOrientation = worldSourceOrientation.Chain(inverseSourceBoneTotalTransform.Rotation);
        }
    public PoseRecipe RecipizePose()
    {
        var     rootTransform   = DualQuaternion.FromMatrix(dragHandle.Transform);
        Vector3 rootRotation    = MathExtensions.RadiansToDegrees(model.MainDefinition.BoneSystem.RootBone.RotationOrder.ToEulerAngles(rootTransform.Rotation));
        Vector3 rootTranslation = rootTransform.Translation;

        Dictionary <string, float[]> boneRotations = new Dictionary <string, float[]>();
        var poseDeltas = ikAnimator.PoseDeltas;

        rootTranslation += Vector3.Transform(poseDeltas.RootTranslation / 100, rootTransform.Rotation);
        foreach (var bone in model.MainDefinition.BoneSystem.Bones)
        {
            var twistSwing = poseDeltas.Rotations[bone.Index];
            var angles     = MathExtensions.RadiansToDegrees(bone.RotationOrder.ToTwistSwingAngles(twistSwing));
            if (!angles.IsZero)
            {
                boneRotations.Add(bone.Name, angles.ToArray());
            }
        }

        return(new PoseRecipe {
            rotation = rootRotation.ToArray(),
            translation = rootTranslation.ToArray(),
            boneRotations = boneRotations
        });
    }
    public void TestFromMatrix()
    {
        Quaternion rotation    = Quaternion.RotationYawPitchRoll(1, 2, 3);
        Vector3    translation = new Vector3(2, 3, 4);
        Matrix     matrix      = Matrix.RotationQuaternion(rotation) * Matrix.Translation(translation);

        DualQuaternion dq = DualQuaternion.FromMatrix(matrix);

        Assert.AreEqual(0, Vector3.Distance(translation, dq.Translation), 1e-6);
        Assert.IsTrue(dq.Rotation == rotation || dq.Rotation == -rotation);
    }
    public ChannelInputs Update(ChannelInputs shapeInputs, FrameUpdateParameters updateParameters, ControlVertexInfo[] previousFrameControlVertexInfos)
    {
        ChannelInputs inputs = new ChannelInputs(shapeInputs);

        for (int idx = 0; idx < inputs.RawValues.Length; ++idx)
        {
            inputs.RawValues[idx] += model.Inputs.RawValues[idx];
        }

        dragHandle.Update(updateParameters);
        DualQuaternion rootTransform = DualQuaternion.FromMatrix(dragHandle.Transform);

        var blendedPose = GetBlendedPose(updateParameters.Time);

        poser.Apply(inputs, blendedPose, rootTransform);

        ikAnimator.Update(updateParameters, inputs, previousFrameControlVertexInfos);

        proceduralAnimator.Update(updateParameters, inputs);

        return(inputs);
    }