Beispiel #1
0
 public virtual void tweenBones(com.brashmonkey.spriter.animation.SpriterAnimation
                                animation)
 {
     foreach (System.Collections.Generic.KeyValuePair <com.brashmonkey.spriter.objects.SpriterBone
                                                       , int> entry in bonesToTween.EntrySet())
     {
         com.brashmonkey.spriter.objects.SpriterBone       toTween = entry.Key;
         com.brashmonkey.spriter.animation.SpriterKeyFrame frame   = animation.frames[entry.
                                                                                      Value];
         long time = frame.getTime();
         com.brashmonkey.spriter.animation.SpriterKeyFrame currentFrame = animation.getPreviousFrameForBone
                                                                              (toTween, time);
         com.brashmonkey.spriter.animation.SpriterKeyFrame nextFrame = animation.getNextFrameFor
                                                                           (toTween, currentFrame, 1);
         if (nextFrame != currentFrame)
         {
             com.brashmonkey.spriter.objects.SpriterBone bone1 = currentFrame.getBoneFor(toTween
                                                                                         );
             com.brashmonkey.spriter.objects.SpriterBone bone2 = nextFrame.getBoneFor(toTween);
             this.interpolateAbstractObject(toTween, bone1, bone2, currentFrame.getTime(), nextFrame
                                            .getTime(), time);
         }
         com.brashmonkey.spriter.objects.SpriterBone[] bones = new com.brashmonkey.spriter.objects.SpriterBone
                                                               [frame.getBones().Length + 1];
         for (int i = 0; i < bones.Length - 1; i++)
         {
             bones[i] = frame.getBones()[i];
         }
         bones[bones.Length - 1] = toTween;
         frame.setBones(bones);
     }
 }
Beispiel #2
0
 protected virtual void drawBones(com.brashmonkey.spriter.player.SpriterAbstractPlayer
                                  player)
 {
     this.setDrawColor(1, 0, 0, 1);
     for (int i = 0; i < player.getBonesToAnimate(); i++)
     {
         com.brashmonkey.spriter.objects.SpriterBone bone = player.getRuntimeBones()[i];
         float xx = bone.getX() + (float)System.Math.Cos(DegreeToRadian(bone.getAngle
                                                                            ())) * 5;
         float yy = bone.getY() + (float)System.Math.Sin(DegreeToRadian(bone.getAngle
                                                                            ())) * 5;
         float x2 = (float)System.Math.Cos(DegreeToRadian(bone.getAngle() + 90)) *
                    (SpriterCalculator.BONE_WIDTH / 2) * bone.getScaleY();
         float y2 = (float)System.Math.Sin(DegreeToRadian(bone.getAngle() + 90)) *
                    (SpriterCalculator.BONE_WIDTH / 2) * bone.getScaleY();
         float targetX = bone.getX() + (float)System.Math.Cos(DegreeToRadian(bone.getAngle
                                                                                 ())) * SpriterCalculator.BONE_LENGTH * bone.getScaleX();
         float targetY = bone.getY() + (float)System.Math.Sin(DegreeToRadian(bone.getAngle
                                                                                 ())) * SpriterCalculator.BONE_LENGTH * bone.getScaleX();
         float upperPointX = xx + x2;
         float upperPointY = yy + y2;
         this.drawLine(bone.getX(), bone.getY(), upperPointX, upperPointY);
         this.drawLine(upperPointX, upperPointY, targetX, targetY);
         float lowerPointX = xx - x2;
         float lowerPointY = yy - y2;
         this.drawLine(bone.getX(), bone.getY(), lowerPointX, lowerPointY);
         this.drawLine(lowerPointX, lowerPointY, targetX, targetY);
         this.drawLine(bone.getX(), bone.getY(), targetX, targetY);
     }
 }
        public virtual void resolve(float x, float y, int chainLength, com.brashmonkey.spriter.objects.SpriterAbstractObject
                                    effector)
        {
            float xx = effector.getX() + (float)System.Math.Cos(SpriterCalculator.DegreeToRadian(effector
                                                                                                 .getAngle())) * SpriterCalculator.BONE_LENGTH * effector
                       .getScaleX();
            float yy = effector.getY() + (float)System.Math.Sin(SpriterCalculator.DegreeToRadian(effector
                                                                                                 .getAngle())) * SpriterCalculator.BONE_LENGTH * effector
                       .getScaleX();

            effector.setAngle(com.brashmonkey.spriter.SpriterCalculator.angleBetween(effector
                                                                                     .getX(), effector.getY(), x, y));
            if (this.player.getFlipX() == -1)
            {
                effector.setAngle(effector.getAngle() + 180f);
            }
            com.brashmonkey.spriter.objects.SpriterBone parent = null;
            if (effector.hasParent())
            {
                parent = player.getRuntimeBones()[effector.getParentId()];
                effector.copyValuesTo(temp);
                com.brashmonkey.spriter.SpriterCalculator.reTranslateRelative(parent, temp);
                if (effector is com.brashmonkey.spriter.objects.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) <= 1)
                {
                    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)));
                this.player.updateRecursively(parent);
                if (parent.hasParent())
                {
                    parent = player.getRuntimeBones()[parent.getParent().getId()];
                }
                else
                {
                    parent = null;
                }
                xx = effector.getX() + (float)System.Math.Cos(SpriterCalculator.DegreeToRadian(effector.getAngle
                                                                                                   ())) * SpriterCalculator.BONE_LENGTH * effector.getScaleX
                         ();
                yy = effector.getY() + (float)System.Math.Sin(SpriterCalculator.DegreeToRadian(effector.getAngle
                                                                                                   ())) * SpriterCalculator.BONE_LENGTH * effector.getScaleX
                         ();
            }
        }
 public virtual com.brashmonkey.spriter.objects.SpriterBone getBoneFor(com.brashmonkey.spriter.objects.SpriterBone
                                                                       bone)
 {
     foreach (com.brashmonkey.spriter.objects.SpriterBone b in this.bones)
     {
         if (b.equals(bone))
         {
             return(b);
         }
     }
     return(null);
 }
 public override void calcBoundingBox(com.brashmonkey.spriter.objects.SpriterBone
                                      parent)
 {
     if (this.weight == 0)
     {
         this.first.calcBoundingBox(parent);
     }
     else
     {
         if (this.weight == 1)
         {
             this.second.calcBoundingBox(parent);
         }
         else
         {
             base.calcBoundingBox(parent);
         }
     }
 }
Beispiel #6
0
 /// <summary>Searches for a keyframe in this animation which has a smaller or equal starting time as the given time and contains the given bone.
 ///     </summary>
 /// <remarks>Searches for a keyframe in this animation which has a smaller or equal starting time as the given time and contains the given bone.
 ///     </remarks>
 /// <param name="bone"></param>
 /// <param name="time"></param>
 /// <returns>A keyframe object which has a smaller or equal starting time than the given time and contains the given bone.
 ///     </returns>
 public virtual com.brashmonkey.spriter.animation.SpriterKeyFrame getPreviousFrameForBone
     (com.brashmonkey.spriter.objects.SpriterBone bone, long time)
 {
     com.brashmonkey.spriter.animation.SpriterKeyFrame frame = null;
     foreach (com.brashmonkey.spriter.animation.SpriterKeyFrame key in this.frames)
     {
         if (!key.containsBone(bone))
         {
             continue;
         }
         if (key.getTime() <= time)
         {
             frame = key;
         }
         else
         {
             break;
         }
     }
     return(frame);
 }
        public virtual void tweenBones(com.brashmonkey.spriter.animation.SpriterAnimation
			 animation)
        {
            foreach (System.Collections.Generic.KeyValuePair<com.brashmonkey.spriter.objects.SpriterBone
                , int> entry in bonesToTween.EntrySet())
            {
                com.brashmonkey.spriter.objects.SpriterBone toTween = entry.Key;
                com.brashmonkey.spriter.animation.SpriterKeyFrame frame = animation.frames[entry.
                    Value];
                long time = frame.getTime();
                com.brashmonkey.spriter.animation.SpriterKeyFrame currentFrame = animation.getPreviousFrameForBone
                    (toTween, time);
                com.brashmonkey.spriter.animation.SpriterKeyFrame nextFrame = animation.getNextFrameFor
                    (toTween, currentFrame, 1);
                if (nextFrame != currentFrame)
                {
                    com.brashmonkey.spriter.objects.SpriterBone bone1 = currentFrame.getBoneFor(toTween
                        );
                    com.brashmonkey.spriter.objects.SpriterBone bone2 = nextFrame.getBoneFor(toTween);
                    this.interpolateAbstractObject(toTween, bone1, bone2, currentFrame.getTime(), nextFrame
                        .getTime(), time);
                }
                com.brashmonkey.spriter.objects.SpriterBone[] bones = new com.brashmonkey.spriter.objects.SpriterBone
                    [frame.getBones().Length + 1];
                for (int i = 0; i < bones.Length - 1; i++)
                {
                    bones[i] = frame.getBones()[i];
                }
                bones[bones.Length - 1] = toTween;
                frame.setBones(bones);
            }
        }
 /// <summary>Manipulates the given bone.</summary>
 /// <remarks>Manipulates the given bone.</remarks>
 /// <param name="bone"></param>
 public virtual void modSpriterBone(com.brashmonkey.spriter.objects.SpriterBone bone
                                    )
 {
     this.modObject(bone);
 }
 /// <summary>Returns whether this frame has information about the given bone.</summary>
 /// <remarks>Returns whether this frame has information about the given bone.</remarks>
 /// <param name="bone"></param>
 /// <returns>True if this frame contains the bone, false otherwise.</returns>
 public virtual bool containsBone(com.brashmonkey.spriter.objects.SpriterBone bone
                                  )
 {
     return(this.getBoneFor(bone) != null);
 }
Beispiel #10
0
 //import com.brashmonkey.spriter.converters.SpriterObjectConverter;
 //import com.discobeard.spriter.dom.AnimationObject;
 //final private SpriterObjectConverter objectConverter = new SpriterObjectConverter();
 public virtual com.brashmonkey.spriter.animation.SpriterAnimation buildAnimation(
     com.discobeard.spriter.dom.Animation animation)
 {
     com.discobeard.spriter.dom.MainLine mainline = animation.getMainline();
     System.Collections.Generic.IList <com.discobeard.spriter.dom.TimeLine> timeLines =
         animation.getTimeline();
     System.Collections.Generic.IList <com.discobeard.spriter.dom.Key> keyFrames = mainline
                                                                                   .getKey();
     bonesToTween = new System.Collections.Generic.Dictionary <com.brashmonkey.spriter.objects.SpriterBone
                                                               , int>();
     objectsToTween = new System.Collections.Generic.Dictionary <com.brashmonkey.spriter.objects.SpriterObject
                                                                 , int>();
     com.brashmonkey.spriter.animation.SpriterAnimation spriterAnimation = new com.brashmonkey.spriter.animation.SpriterAnimation
                                                                               (animation.getId(), animation.getName(), animation.getLength());
     for (int k = 0; k < keyFrames.Count; k++)
     {
         com.discobeard.spriter.dom.Key mainlineKey = keyFrames[k];
         System.Collections.Generic.IList <com.brashmonkey.spriter.objects.SpriterObject> tempObjects
             = new System.Collections.Generic.List <com.brashmonkey.spriter.objects.SpriterObject
                                                    >();
         System.Collections.Generic.IList <com.brashmonkey.spriter.objects.SpriterBone> tempBones
             = new System.Collections.Generic.List <com.brashmonkey.spriter.objects.SpriterBone
                                                    >();
         com.brashmonkey.spriter.animation.SpriterKeyFrame frame = new com.brashmonkey.spriter.animation.SpriterKeyFrame
                                                                       ();
         frame.setTime(mainlineKey.getTime());
         frame.setId(mainlineKey.getId());
         foreach (com.discobeard.spriter.dom.BoneRef boneRef in mainlineKey.getBoneRef())
         {
             com.discobeard.spriter.dom.TimeLine         timeline    = timeLines[boneRef.getTimeline()];
             com.discobeard.spriter.dom.Key              timelineKey = timeline.getKey()[boneRef.getKey()];
             com.brashmonkey.spriter.objects.SpriterBone bone        = boneMerger.merge(boneRef, timelineKey
                                                                                        );
             bone.setName(timeline.getName());
             if (mainlineKey.getTime() != timelineKey.getTime())
             {
                 bonesToTween.Add(bone, k);
             }
             else
             {
                 tempBones.Add(bone);
             }
         }
         //}
         foreach (com.discobeard.spriter.dom.AnimationObjectRef objectRef in mainlineKey.getObjectRef
                      ())
         {
             com.discobeard.spriter.dom.TimeLine timeline    = timeLines[objectRef.getTimeline()];
             com.discobeard.spriter.dom.Key      timelineKey = timeline.getKey()[objectRef.getKey()
                                                               ];
             com.brashmonkey.spriter.objects.SpriterObject @object = objectMerger.merge(objectRef
                                                                                        , timelineKey);
             @object.setName(timeline.getName());
             if (mainlineKey.getTime() != timelineKey.getTime())
             {
                 objectsToTween.Add(@object, k);
             }
             else
             {
                 tempObjects.Add(@object);
             }
         }
         //}
         frame.setObjects(Sharpen.Collections.ToArray(tempObjects, new com.brashmonkey.spriter.objects.SpriterObject
                                                      [tempObjects.Count]));
         frame.setBones(Sharpen.Collections.ToArray(tempBones, new com.brashmonkey.spriter.objects.SpriterBone
                                                    [tempBones.Count]));
         spriterAnimation.frames.Add(frame);
     }
     this.tweenBones(spriterAnimation);
     this.tweenObjects(spriterAnimation);
     return(spriterAnimation);
 }
 /// <summary>Generates data which is necessary to animate all animations as intended.
 /// 	</summary>
 /// <remarks>
 /// Generates data which is necessary to animate all animations as intended.
 /// This method has to called inside the specific constructor.
 /// </remarks>
 protected internal void generateData()
 {
     int maxObjects = 0;
     int maxBones = 0;
     int maxBonesFrameIndex = 0;
     int maxObjectsFrameIndex = 0;
     int maxBonesAnimationIndex = 0;
     int maxObjectsAnimationIndex = 0;
     foreach (com.brashmonkey.spriter.animation.SpriterAnimation animation in this.animations)
     {
         foreach (com.brashmonkey.spriter.animation.SpriterKeyFrame frame in animation.frames)
         {
             maxBones = System.Math.Max(frame.getBones().Length, maxBones);
             if (maxBones == frame.getBones().Length)
             {
                 maxBonesFrameIndex = frame.getId();
                 maxBonesAnimationIndex = animation.id;
             }
             maxObjects = System.Math.Max(frame.getObjects().Length, maxObjects);
             if (maxObjects == frame.getObjects().Length)
             {
                 maxObjectsFrameIndex = frame.getId();
                 maxObjectsAnimationIndex = animation.id;
             }
             foreach (com.brashmonkey.spriter.objects.SpriterObject o in frame.getObjects())
             {
                 //o.setLoader(this.loader);
                 o.setRef(this.loader.findReference(o.getRef()));
             }
         }
     }
     this.instructions = new com.brashmonkey.spriter.draw.DrawInstruction[maxObjects];
     this.moddedObjects = new com.brashmonkey.spriter.objects.SpriterModObject[this.instructions
         .Length];
     this.tempObjects = new com.brashmonkey.spriter.objects.SpriterObject[this.instructions
         .Length];
     this.tempObjects2 = new com.brashmonkey.spriter.objects.SpriterObject[this.instructions
         .Length];
     this.nonTransformedTempObjects = new com.brashmonkey.spriter.objects.SpriterObject
         [this.instructions.Length];
     for (int i = 0; i < this.instructions.Length; i++)
     {
         this.instructions[i] = new com.brashmonkey.spriter.draw.DrawInstruction(null, 0,
             0, 0, 0, 0, 0, 0, 0);
         this.tempObjects[i] = new com.brashmonkey.spriter.objects.SpriterObject();
         this.tempObjects2[i] = new com.brashmonkey.spriter.objects.SpriterObject();
         this.nonTransformedTempObjects[i] = new com.brashmonkey.spriter.objects.SpriterObject
             ();
         this.nonTransformedTempObjects[i].setId(i);
         this.moddedObjects[i] = new com.brashmonkey.spriter.objects.SpriterModObject();
         this.moddedObjects[i].setId(i);
     }
     this.tempBones = new com.brashmonkey.spriter.objects.SpriterBone[maxBones];
     this.tempBones2 = new com.brashmonkey.spriter.objects.SpriterBone[tempBones.Length
         ];
     this.nonTransformedTempBones = new com.brashmonkey.spriter.objects.SpriterBone[tempBones
         .Length];
     this.moddedBones = new com.brashmonkey.spriter.objects.SpriterModObject[this.tempBones
         .Length];
     for (int i_1 = 0; i_1 < this.tempBones.Length; i_1++)
     {
         this.tempBones[i_1] = new com.brashmonkey.spriter.objects.SpriterBone();
         this.tempBones2[i_1] = new com.brashmonkey.spriter.objects.SpriterBone();
         this.nonTransformedTempBones[i_1] = new com.brashmonkey.spriter.objects.SpriterBone
             ();
         this.nonTransformedTempBones[i_1].setId(i_1);
         this.moddedBones[i_1] = new com.brashmonkey.spriter.objects.SpriterModObject();
         this.moddedBones[i_1].setId(i_1);
     }
     com.brashmonkey.spriter.objects.SpriterBone[] tmpBones1 = new com.brashmonkey.spriter.objects.SpriterBone
         [this.tempBones.Length];
     com.brashmonkey.spriter.objects.SpriterBone[] tmpBones2 = new com.brashmonkey.spriter.objects.SpriterBone
         [this.tempBones.Length];
     com.brashmonkey.spriter.objects.SpriterObject[] tmpObjs1 = new com.brashmonkey.spriter.objects.SpriterObject
         [this.instructions.Length];
     com.brashmonkey.spriter.objects.SpriterObject[] tmpObjs2 = new com.brashmonkey.spriter.objects.SpriterObject
         [this.instructions.Length];
     for (int i_2 = 0; i_2 < tmpObjs1.Length; i_2++)
     {
         tmpObjs1[i_2] = new com.brashmonkey.spriter.objects.SpriterObject();
         tmpObjs2[i_2] = new com.brashmonkey.spriter.objects.SpriterObject();
     }
     for (int i_3 = 0; i_3 < tmpBones1.Length; i_3++)
     {
         tmpBones1[i_3] = new com.brashmonkey.spriter.objects.SpriterBone();
         tmpBones2[i_3] = new com.brashmonkey.spriter.objects.SpriterBone();
     }
     this.lastFrame.setBones(tmpBones1);
     this.lastFrame.setObjects(tmpObjs1);
     this.lastTempFrame.setBones(tmpBones2);
     this.lastTempFrame.setObjects(tmpObjs2);
     foreach (com.brashmonkey.spriter.objects.SpriterObject @object in this.animations
         [maxObjectsAnimationIndex].frames[maxObjectsFrameIndex].getObjects())
     {
         for (int i_4 = 0; i_4 < this.nonTransformedTempObjects.Length; i_4++)
         {
             if (this.nonTransformedTempObjects[i_4].getId() == @object.getId())
             {
                 @object.copyValuesTo(this.nonTransformedTempObjects[i_4]);
             }
         }
     }
     foreach (com.brashmonkey.spriter.objects.SpriterBone bone in this.animations[maxBonesAnimationIndex
         ].frames[maxBonesFrameIndex].getBones())
     {
         for (int i_4 = 0; i_4 < this.nonTransformedTempBones.Length; i_4++)
         {
             if (this.nonTransformedTempBones[i_4].getId() == bone.getId())
             {
                 bone.copyValuesTo(this.nonTransformedTempBones[i_4]);
             }
         }
     }
     this.generated = true;
 }
Beispiel #12
0
 public virtual void addChildBone(com.brashmonkey.spriter.objects.SpriterBone bone
                                  )
 {
     bone.setParent(this);
     childBones.AddLast(bone);
 }