Beispiel #1
0
 /// <summary>Changes the state of each effector to unactive.</summary>
 /// <remarks>Changes the state of each effector to unactive. The effect results in non animated bodyparts.
 ///     </remarks>
 /// <param name="parents">indicates whether parents of the effectors have to be deactivated or not.
 ///     </param>
 public virtual void deactivateEffectors(SpriterAbstractPlayer player, bool parents)
 {
     foreach (SpriterIKObject key in this.ikMap.Keys)
     {
         SpriterAbstractObject obj = this.ikMap[key];
         if (obj is SpriterBone)
         {
             obj = player.getRuntimeBones()[obj.getId()];
         }
         else
         {
             obj = player.getRuntimeObjects()[obj.getId()];
         }
         obj.active = false;
         if (!parents)
         {
             continue;
         }
         SpriterBone par = (SpriterBone)obj.getParent();
         for (int j = 0; j < key.chainLength && par != null; j++)
         {
             player.getRuntimeBones()[par.getId()].active = false;
             par = (SpriterBone)par.getParent();
         }
     }
 }
Beispiel #2
0
 public virtual void activateAll(SpriterAbstractPlayer
                                 player)
 {
     foreach (SpriterBone bone in player.getRuntimeBones())
     {
         bone.active = true;
     }
     foreach (SpriterObject obj in player.getRuntimeObjects())
     {
         obj.active = true;
     }
 }
Beispiel #3
0
 protected internal virtual void updateRecursively(SpriterAbstractPlayer
                                                   player, SpriterAbstractObject @object)
 {
     this.updateObject(player, @object);
     if (@object is SpriterBone)
     {
         foreach (SpriterBone child in ((SpriterBone
                                         )@object).getChildBones())
         {
             this.updateRecursively(player, player.getRuntimeBones()[child.getId()]);
         }
         foreach (SpriterObject child_1 in ((SpriterBone
                                             )@object).getChildObjects())
         {
             this.updateRecursively(player, player.getRuntimeObjects()[child_1.getId()]);
         }
     }
 }
Beispiel #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);
         }
     }
 }
Beispiel #5
0
 /// <summary>Resolves the inverse kinematics constraint with a specific algtorithm</summary>
 /// <param name="x">the target x value</param>
 /// <param name="y">the target y value</param>
 /// <param name="chainLength">number of parents which are affected</param>
 /// <param name="effector">the actual effector where the resolved information has to be stored in.
 ///     </param>
 protected abstract void resolve(float x, float y, int chainLength, SpriterAbstractObject effector, SpriterAbstractPlayer player);
Beispiel #6
0
 protected internal virtual void updateObject(SpriterAbstractPlayer
                                              player, SpriterAbstractObject @object)
 {
     player.updateAbstractObject(@object);
 }
        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
                         ();
            }
        }