public virtual void updateAbstractObject(SpriterAbstractObject @object)
 {
     if (@object.hasParent())
     {
         SpriterAbstractObject obj = (@object is SpriterBone
                                      ) ? (SpriterAbstractObject)this.lastFrame.getBones()[@object.getId()] : this.lastFrame.getObjects()[@object
                                                                                                                                          .getId()];
         SpriterCalculator.translateRelative(this.tempBones[@object
                                                            .getParentId()], obj.getX(), obj.getY(), @object);
     }
 }
 private void updateTransformedTempObject(SpriterAbstractObject
                                          source, SpriterAbstractObject target)
 {
     source.copyValuesTo(target);
     if (!target.hasParent())
     {
         target.setX(target.getX() + this.pivotX);
         target.setY(target.getY() + this.pivotY);
     }
     this.translateRelative(target, (target.hasParent()) ? this.tempBones2[target.getParentId
                                                                               ()] : this.tempParent);
 }
 private void interpolateAbstractObject(SpriterAbstractObject
                                        target, SpriterAbstractObject obj1, SpriterAbstractObject
                                        obj2, float startTime, float endTime)
 {
     if (obj2 == null)
     {
         return;
     }
     target.setX(this.interpolate(obj1.getX(), obj2.getX(), startTime, endTime, this.frame
                                  ));
     target.setY(this.interpolate(obj1.getY(), obj2.getY(), startTime, endTime, this.frame
                                  ));
     target.setScaleX(this.interpolate(obj1.getScaleX(), obj2.getScaleX(), startTime,
                                       endTime, this.frame));
     target.setScaleY(this.interpolate(obj1.getScaleY(), obj2.getScaleY(), startTime,
                                       endTime, this.frame));
     target.setAngle(this.interpolateAngle(obj1.getAngle(), obj2.getAngle(), startTime
                                           , endTime, this.frame));
 }
Exemple #4
0
 /// <summary>
 /// Resolves the inverse kinematics constraints with the implemented algorithm in
 /// <see cref="resolve(float, float, int, SpriterAbstractObject, SpriterAbstractPlayer)
 ///     ">resolve(float, float, int, SpriterAbstractObject, SpriterAbstractPlayer)
 ///     </see>
 /// .
 /// </summary>
 /// <param name="player">player to apply the resolving.</param>
 public virtual void resolve(SpriterAbstractPlayer player)
 {
     foreach (SpriterIKObject key in this.ikMap.Keys)
     {
         for (int j = 0; j < key.iterations; j++)
         {
             SpriterAbstractObject obj = this.ikMap[key];
             if (obj is Com.Brashmonkey.Spriter.objects.SpriterBone)
             {
                 obj = player.getRuntimeBones()[obj.getId()];
             }
             else
             {
                 obj = player.getRuntimeObjects()[obj.getId()];
             }
             this.resolve(obj.getX(), obj.getY(), key.chainLength, obj, player);
         }
     }
 }
        protected override void resolve(float x, float y, int chainLength, SpriterAbstractObject effector, SpriterAbstractPlayer player)
        {
            base.updateRecursively(player, effector);
            float xx = effector.getX() + (float)System.Math.Cos(SpriterCalculator.DegreeToRadian(effector
                                                                                                 .getAngle())) * Com.Brashmonkey.Spriter.draw.AbstractDrawer.BONE_LENGTH * effector
                       .getScaleX();
            float yy = effector.getY() + (float)System.Math.Sin(SpriterCalculator.DegreeToRadian(effector
                                                                                                 .getAngle())) * Com.Brashmonkey.Spriter.draw.AbstractDrawer.BONE_LENGTH * effector
                       .getScaleX();

            effector.setAngle(Com.Brashmonkey.Spriter.SpriterCalculator.angleBetween(effector
                                                                                     .getX(), effector.getY(), x, y));
            if (player.getFlipX() == -1)
            {
                effector.setAngle(effector.getAngle() + 180f);
            }
            SpriterBone parent = null;

            if (effector.hasParent())
            {
                parent = player.getRuntimeBones()[effector.getParentId()];
            }
            //effector.copyValuesTo(temp);
            //SpriterCalculator.reTranslateRelative(parent, temp);
            //if(effector instanceof SpriterBone)	temp.copyValuesTo(player.lastFrame.getBones()[effector.getId()]);
            //else temp.copyValuesTo(player.lastFrame.getObjects()[effector.getId()]);
            for (int i = 0; i < chainLength && parent != null; i++)
            {
                if (Com.Brashmonkey.Spriter.SpriterCalculator.distanceBetween(xx, yy, x, y) <= this
                    .tolerance)
                {
                    SpriterBone p = null;
                    if (parent.hasParent())
                    {
                        p = player.getRuntimeBones()[parent.getParentId()];
                    }
                    int j = 0;
                    while (p != null && j < chainLength)
                    {
                        base.updateRecursively(player, p);
                        if (p.hasParent())
                        {
                            p = player.getRuntimeBones()[p.getParentId()];
                        }
                        else
                        {
                            p = null;
                        }
                        j++;
                    }
                    return;
                }
                parent.setAngle(parent.getAngle() + Com.Brashmonkey.Spriter.SpriterCalculator.angleDifference
                                    (Com.Brashmonkey.Spriter.SpriterCalculator.angleBetween(parent.getX(), parent.getY
                                                                                                (), x, y), Com.Brashmonkey.Spriter.SpriterCalculator.angleBetween(parent.getX(),
                                                                                                                                                                  parent.getY(), xx, yy)));
                base.updateRecursively(player, parent);
                if (parent.hasParent())
                {
                    parent = player.getRuntimeBones()[parent.getParent().getId()];
                }
                else
                {
                    parent = null;
                }
                xx = effector.getX() + (float)System.Math.Cos(SpriterCalculator.DegreeToRadian(effector.getAngle
                                                                                                   ())) * Com.Brashmonkey.Spriter.draw.AbstractDrawer.BONE_LENGTH * effector.getScaleX
                         ();
                yy = effector.getY() + (float)System.Math.Sin(SpriterCalculator.DegreeToRadian(effector.getAngle
                                                                                                   ())) * Com.Brashmonkey.Spriter.draw.AbstractDrawer.BONE_LENGTH * effector.getScaleX
                         ();
            }
        }