Exemplo n.º 1
0
 void ApplyBone(BoneWeight bw, Vector2 sourceVector, ref Vector2 resultVector, ref float overallWeight)
 {
     if (items != null && bw.Index > 0 && bw.Index < items.Length)
     {
         BoneArray.Entry e = items[bw.Index];
         resultVector  += bw.Weight * e.RelativeTransform.TransformVector(sourceVector);
         overallWeight += bw.Weight;
     }
 }
Exemplo n.º 2
0
        public Matrix32 CalcLocalToParentWidgetTransform()
        {
            if (BaseIndex == 0)
            {
                return(Matrix32.Identity);
            }
            BoneArray.Entry b = Parent.AsWidget.BoneArray[BaseIndex];
            var             l = ClipAboutZero(b.Length);
            Vector2         u = b.Tip - b.Joint;
            Vector2         v = new Vector2(-u.Y / l, u.X / l);

            return(new Matrix32(u, v, b.Tip));
        }
Exemplo n.º 3
0
 public override void Update(float delta)
 {
     base.Update(delta);
     if (Index > 0 && Parent != null)
     {
         BoneArray.Entry e;
         e.Joint    = Position;
         e.Rotation = Rotation;
         e.Length   = Length;
         if (BaseIndex > 0)
         {
             // Tie the bone to the parent bone.
             BoneArray.Entry b = Parent.AsWidget.BoneArray[BaseIndex];
             float           l = ClipAboutZero(b.Length);
             Vector2         u = b.Tip - b.Joint;
             Vector2         v = new Vector2(-u.Y / l, u.X / l);
             e.Joint     = b.Tip + u * Position.X + v * Position.Y;
             e.Rotation += b.Rotation;
         }
         // Get position of bone's tip.
         e.Tip = Vector2.RotateDegRough(new Vector2(e.Length, 0), e.Rotation) + e.Joint;
         if (RefLength != 0)
         {
             float relativeScaling = Length / ClipAboutZero(RefLength);
             // Calculating the matrix of relative transformation.
             Matrix32 m1, m2;
             m1 = Matrix32.TransformationRough(Vector2.Zero, Vector2.One, RefRotation * Mathf.DegToRad, RefPosition);
             m2 = Matrix32.TransformationRough(Vector2.Zero, new Vector2(relativeScaling, 1), e.Rotation * Mathf.DegToRad, e.Joint);
             e.RelativeTransform = m1.CalcInversed() * m2;
         }
         else
         {
             e.RelativeTransform = Matrix32.Identity;
         }
         Parent.AsWidget.BoneArray[Index] = e;
         Parent.PropagateDirtyFlags(DirtyFlags.GlobalTransform);
         for (var child = Parent.FirstChild; child != null; child = child.NextSibling)
         {
             child.DirtyMask |= DirtyFlags.LocalTransform | DirtyFlags.ParentBoundingRect;
         }
     }
 }