public void Merge(ActorBehavior behaviour) { Vector3 rootRotation = new Vector3(rotation); Vector3 rootTranslation = new Vector3(translation); DualQuaternion rootTransform = DualQuaternion.FromRotationTranslation( behaviour.model.MainDefinition.BoneSystem.RootBone.RotationOrder.FromEulerAngles(MathExtensions.DegreesToRadians(rootRotation)), rootTranslation); behaviour.dragHandle.Transform = rootTransform.ToMatrix(); var poseDeltas = behaviour.ikAnimator.PoseDeltas; poseDeltas.ClearToZero(); foreach (var bone in behaviour.model.MainDefinition.BoneSystem.Bones) { Vector3 angles; if (boneRotations.TryGetValue(bone.Name, out var values)) { angles = new Vector3(values); } else { angles = Vector3.Zero; } var twistSwing = bone.RotationOrder.FromTwistSwingAngles(MathExtensions.DegreesToRadians(angles)); poseDeltas.Rotations[bone.Index] = twistSwing; } }
public DualQuaternion Invert() { var inverseRotation = Quaternion.Invert(Rotation); var inverseTranslation = Vector3.Transform(-Translation, inverseRotation); return(DualQuaternion.FromRotationTranslation(inverseRotation, inverseTranslation)); }
private DualQuaternion GetJointCenteredRotationTransform(ChannelOutputs outputs, Matrix3x3 parentScale) { Quaternion worldSpaceRotation = GetRotation(outputs); Vector3 translation = Vector3.Transform(Translation.GetValue(outputs), parentScale); return(DualQuaternion.FromRotationTranslation(worldSpaceRotation, translation)); }
public void TestFromAndToRotationTranslation() { Quaternion rotation = Quaternion.RotationYawPitchRoll(1, 2, 3); Vector3 translation = new Vector3(2, 3, 4); DualQuaternion dq = DualQuaternion.FromRotationTranslation(rotation, translation); Assert.AreEqual(0, Vector3.Distance(translation, dq.Translation), 1e-6); Assert.IsTrue(dq.Rotation == rotation || dq.Rotation == -rotation); }
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); DualQuaternion dq = DualQuaternion.FromRotationTranslation(rotation, translation); Vector3 v = new Vector3(3, 4, 5); Assert.IsTrue(dq.Transform(v) == Vector3.TransformCoordinate(v, matrix)); }
public void Apply(ChannelInputs inputs, Pose pose, DualQuaternion rootTransform) { foreach (Bone bone in boneSystem.Bones) { bone.AddRotation(orientationOutputs, inputs, pose.BoneRotations[bone.Index]); } var rescaledRootTransform = DualQuaternion.FromRotationTranslation(rootTransform.Rotation, rootTransform.Translation * 100); boneSystem.RootBone.SetRotation(orientationOutputs, inputs, rescaledRootTransform.Rotation); boneSystem.RootBone.SetTranslation(inputs, rescaledRootTransform.Translation); boneSystem.Bones[1].SetTranslation(inputs, pose.RootTranslation); }
public void TestInvert() { Vector3 translation = new Vector3(2, 3, 4); Quaternion rotation = Quaternion.RotationYawPitchRoll(1, 2, 3); DualQuaternion dq = DualQuaternion.FromRotationTranslation(rotation, translation); Vector3 v = new Vector3(3, 4, 5); Vector3 transformed = dq.Transform(v); Vector3 inverseTransformed = dq.Invert().Transform(transformed); Assert.AreEqual( v, inverseTransformed); }