コード例 #1
0
ファイル: Bone.cs プロジェクト: TiagoJSM/Storytime
 public Bone(Bone parent, string name = null)
     : this(name)
 {
     Parent = parent;
     if (parent != null)
      Parent.AddChildren(this);
 }
コード例 #2
0
        public Bone Add(BoneActor actor)
        {
            Bone bone = null;
            if (actor.Parent != null)
            {
                var parent = actor.Parent.AssignedBone;
                bone = new Bone(parent);
            }
            else
            {
                bone = new Bone()
                {
                    Length = FirstBoneDefaultLenght
                };
                _skeleton.AddBone(bone);
            }

            actor.AssignedBone = bone;
            SetBoneData(actor);

            actor.OnParentChange += OnParentChangeHandler;

            _boneDictionary.Add(bone, actor);
            return bone;
        }
コード例 #3
0
 public BoneActor Add(Vector2 startPosition, Bone parent = null)
 {
     Bone bone = new Bone(parent)
     {
         AbsolutePosition = startPosition,
         Length = FirstBoneDefaultLenght
     };
     if (parent == null)
     {
         _skeleton.AddBone(bone);
     }
     return CreateBoneActorWith(bone);
 }
コード例 #4
0
 public BoneActor Add(Vector2 startPosition, Vector2 endPosition, Bone parent = null)
 {
     Bone bone = new Bone(parent)
     {
         AbsolutePosition = startPosition,
         AbsoluteEnd = endPosition
     };
     if (parent == null)
     {
         _skeleton.AddBone(bone);
     }
     return CreateBoneActorWith(bone);
 }
コード例 #5
0
        public void AddAnimationFrame(Bone bone, BoneAnimationFrame frame)
        {
            if (_framesMapping.ContainsKey(bone))
            {
                _framesMapping[bone].Add(frame);
            }
            else
            {
                var frames = new List<BoneAnimationFrame>() { frame };
                _framesMapping.Add(bone, frames);
            }

            if (_longestAnimationTime < frame.EndTime)
            {
                _longestAnimationTime = frame.EndTime;
            }
        }
コード例 #6
0
        private void UpdateBone(Bone bone)
        {
            var endTime = _elapsedTime;
            if (!_framesMapping.ContainsKey(bone))
                return;
            var frames = _framesMapping[bone];
            var frame = frames.GetAt(_elapsedTime);

            if (frame == null)
            {
                frame = frames.GetLastFrame();
                endTime = frame.EndTime;
            }

            if (frame == null)
                return;
            frame.SetBoneTransformationValues(bone, endTime);
        }
コード例 #7
0
        public void RelativeEndIsConsistent()
        {
            var boneRoot = new Bone();
            var boneChild = new Bone(boneRoot);
            var leafChild = new Bone(boneChild);

            boneRoot.AbsolutePosition = new Vector2(100);
            boneRoot.Length = 128;

            AssetHelpers.AreEqual(new Vector2(100, 228), boneRoot.AbsoluteEnd, 0.00001f);

            boneChild.AbsolutePosition = boneRoot.AbsoluteEnd;
            boneChild.AbsoluteEnd = new Vector2(250, 378);

            AssetHelpers.AreEqual(new Vector2(250, 378), boneChild.AbsoluteEnd, 0.00001f);

            leafChild.AbsolutePosition = boneChild.AbsoluteEnd;
            leafChild.AbsoluteEnd = new Vector2(400, 528);

            AssetHelpers.AreEqual(new Vector2(400, 528), leafChild.AbsoluteEnd, 0.00001f);
        }
コード例 #8
0
        public void RotatingRootKeepsAllChildrenConsistent()
        {
            var boneRoot = new Bone();
            var boneChild = new Bone(boneRoot);
            var leafChild = new Bone(boneChild);

            boneRoot.AbsolutePosition = new Vector2(0);
            boneRoot.Length = 100;

            boneChild.AbsolutePosition = boneRoot.AbsoluteEnd;
            boneChild.AbsoluteEnd = new Vector2(0, 200);

            leafChild.AbsolutePosition = boneChild.AbsoluteEnd;
            leafChild.AbsoluteEnd = new Vector2(0, 400);

            boneRoot.AbsoluteEnd = new Vector2(100, 0);

            AssetHelpers.AreEqual(new Vector2(100, 0), boneRoot.AbsoluteEnd, 0.0001f);
            AssetHelpers.AreEqual(new Vector2(200, 0), boneChild.AbsoluteEnd, 0.0001f);
            AssetHelpers.AreEqual(new Vector2(400, 0), leafChild.AbsoluteEnd, 0.0001f);
        }
コード例 #9
0
        public void MovingRootKeepsAllChildrenConsistent()
        {
            var boneRoot = new Bone();
            var boneChild = new Bone(boneRoot);
            var leafChild = new Bone(boneChild);

            boneRoot.AbsolutePosition = new Vector2(100);
            boneRoot.Length = 128;

            boneChild.AbsolutePosition = boneRoot.AbsoluteEnd;
            boneChild.AbsoluteEnd = new Vector2(250, 378);

            leafChild.AbsolutePosition = boneChild.AbsoluteEnd;
            leafChild.AbsoluteEnd = new Vector2(400, 528);

            boneRoot.AbsolutePosition = new Vector2(150);

            AssetHelpers.AreEqual(new Vector2(150, 278), boneRoot.AbsoluteEnd, 0.00001f);
            AssetHelpers.AreEqual(new Vector2(300, 428), boneChild.AbsoluteEnd, 0.00001f);
            AssetHelpers.AreEqual(new Vector2(450, 578), leafChild.AbsoluteEnd, 0.00001f);
        }
コード例 #10
0
 public BoneActorSceneObject(BoneActor boneActor, IPuppeteerSceneOjectActionContext context)
 {
     _boneActor = boneActor;
     _context = context;
     _bone = _boneActor.AssignedBone;
 }
コード例 #11
0
ファイル: Bone.cs プロジェクト: TiagoJSM/Storytime
 public void AddChildren(Bone children)
 {
     if (_children.Contains(children)) return;
     children.Parent = this;
 }
コード例 #12
0
ファイル: Bone.cs プロジェクト: TiagoJSM/Storytime
 public void RemoveChildren(Bone children)
 {
     if (!_children.Contains(children)) return;
     children.Parent = null;
 }
コード例 #13
0
 private void PropagateBoneChanges(Bone bone)
 {
     var children = bone.Children;
     foreach (var child in children)
     {
         var actor = _boneDictionary[child];
         SetActorData(actor);
         PropagateBoneChanges(child);
     }
 }
コード例 #14
0
        private BoneActor CreateBoneActorWith(Bone bone)
        {
            var actor = _scene.AddWorldEntity<BoneActor>();
            actor.AssignedBone = bone;

            actor.OnParentChange += OnParentChangeHandler;

            _boneDictionary.Add(bone, actor);
            return actor;
        }
コード例 #15
0
 public void SynchronizeBoneChain(Bone bone)
 {
     var actor = _boneDictionary[bone];
     SetActorData(actor);
     PropagateBoneChanges(bone);
 }
コード例 #16
0
        public void RotationsInBoneStructure()
        {
            var boneRoot = new Bone();
            var boneChild = new Bone(boneRoot);
            var leafChild = new Bone(boneChild);

            boneRoot.AbsolutePosition = new Vector2(0);
            boneRoot.Length = 100;

            boneChild.AbsolutePosition = boneRoot.AbsoluteEnd;
            boneChild.AbsoluteEnd = new Vector2(100, 0);

            leafChild.AbsolutePosition = boneChild.AbsoluteEnd;
            leafChild.AbsoluteEnd = new Vector2(200, 0);

            boneRoot.AbsoluteEnd = new Vector2(100, 0);

            AssetHelpers.AreEqual(new Vector2(100, 0), boneRoot.AbsoluteEnd, 0.0001f);
            AssetHelpers.AreEqual(new Vector2(0, -100), boneChild.AbsoluteEnd, 0.0001f);
            AssetHelpers.AreEqual(new Vector2(0, -200), leafChild.AbsoluteEnd, 0.0001f);
        }
コード例 #17
0
 public void SetBoneTransformationValues(Bone bone, TimeSpan totalElapsed)
 {
     bone.Translation = InterpolateTranslation(totalElapsed);
     bone.Rotation = InterpolateRotation(totalElapsed);
 }
コード例 #18
0
 private void UpdateChildBonesOf(Bone bone)
 {
     foreach(var child in bone.Children)
     {
         UpdateBone(child);
         UpdateChildBonesOf(child);
     }
 }