/// <summary> /// Maps all object from the parent's coordinate system to the global coordinate system. </summary> /// <param name="base"> the root bone to start at. Set it to <code>null</code> to traverse the whole bone hierarchy. </param> public virtual void UnmapObjects(Mainline.Key.BoneRef @base) { int start = @base == null ? -1 : @base.Id - 1; for (int i = start + 1; i < CurrentKey.BoneRefs.Length; i++) { Mainline.Key.BoneRef @ref = CurrentKey.GetBoneRef(i); if (@ref.Parent != @base && @base != null) { continue; } Bone parent = @ref.Parent == null ? this.Root : this.UnmappedTweenedKeys[@ref.Parent.Timeline].Object; UnmappedTweenedKeys[@ref.Timeline].Object.Set(TweenedKeys[@ref.Timeline].Object); UnmappedTweenedKeys[@ref.Timeline].Object.Unmap(parent); UnmapObjects(@ref); } foreach (Mainline.Key.ObjectRef @ref in CurrentKey.ObjectRefs) { if (@ref.Parent != @base && @base != null) { continue; } Bone parent = @ref.Parent == null ? this.Root : this.UnmappedTweenedKeys[@ref.Parent.Timeline].Object; UnmappedTweenedKeys[@ref.Timeline].Object.Set(TweenedKeys[@ref.Timeline].Object); UnmappedTweenedKeys[@ref.Timeline].Object.Unmap(parent); } }
/// <summary> /// Returns a bounding box for this player. /// The bounding box is calculated for all bones and object starting from the given root. </summary> /// <param name="root"> the starting root. Set it to null to calculate the bounding box for the whole player </param> /// <returns> the bounding box </returns> public virtual Rectangle GetBoundingRectangle(Mainline.Key.BoneRef root) { Bone boneRoot = root == null ? this.Root : this.UnmappedTweenedKeys[root.Timeline].Object; this.rect.Set(boneRoot.Position.X, boneRoot.Position.Y, boneRoot.Position.X, boneRoot.Position.Y); this.CalcBoundingRectangle(root); this.rect.CalculateSize(); return(this.rect); }
/// <summary> /// Sets the given values of the bone with the given name. </summary> /// <param name="name"> the name of the bone </param> /// <param name="x"> the new x value of the bone </param> /// <param name="y"> the new y value of the bone </param> /// <param name="angle"> the new angle of the bone </param> /// <param name="scaleX"> the new scale in x direction of the bone </param> /// <param name="scaleY"> the new scale in y direction of the bone </param> /// <exception cref="SpriterException"> if no bone exists of the given name </exception> public virtual void SetBone(string name, float x, float y, float angle, float scaleX, float scaleY) { int index = GetBoneIndex(name); if (index == -1) { throw new SpriterException("No bone found of name \"" + name + "\""); } Mainline.Key.BoneRef @ref = CurrentKey.GetBoneRef(index); Bone bone = GetBone(index); bone.Set(x, y, angle, scaleX, scaleY, 0f, 0f); UnmapObjects(@ref); }
private void CalcBoundingRectangle(Mainline.Key.BoneRef root) { foreach (Mainline.Key.BoneRef @ref in CurrentKey.BoneRefs) { if (@ref.Parent != root && root != null) { continue; } Bone bone = this.UnmappedTweenedKeys[@ref.Timeline].Object; this.PrevBBox.CalcFor(bone, Animation.GetTimeline(@ref.Timeline).ObjectInfo); Rectangle.SetBiggerRectangle(rect, this.PrevBBox.BoundingRect, rect); this.CalcBoundingRectangle(@ref); } foreach (Mainline.Key.ObjectRef @ref in CurrentKey.ObjectRefs) { if (@ref.Parent != root) { continue; } Bone bone = this.UnmappedTweenedKeys[@ref.Timeline].Object; this.PrevBBox.CalcFor(bone, Animation.GetTimeline(@ref.Timeline).ObjectInfo); Rectangle.SetBiggerRectangle(rect, this.PrevBBox.BoundingRect, rect); } }
private void LoadRefs(ContentReader input, int objectRefCount, int boneRefCount, Mainline.Key _key) { for (int id = 0; id < boneRefCount; id++) { int parent = input.ReadInt32(); int timeline = input.ReadInt32(); int key = input.ReadInt32(); Mainline.Key.BoneRef boneRef = new Mainline.Key.BoneRef(id, timeline, key, _key.GetBoneRef(parent)); _key.AddBoneRef(boneRef); } for (int id = 0; id < objectRefCount; id++) { int parent = input.ReadInt32(); int timeline = input.ReadInt32(); int key = input.ReadInt32(); int z = input.ReadInt32(); Mainline.Key.ObjectRef objref = new Mainline.Key.ObjectRef(id, timeline, key, _key.GetBoneRef(parent), z); _key.AddObjectRef(objref); } // TODO sort? }
/// <summary> /// Returns an iterator to iterate over all time line bones in the current animation starting at a given root. </summary> /// <param name="start"> the bone reference to start at </param> /// <returns> the bone iterator </returns> public virtual IEnumerator <Bone> BoneIterator(Mainline.Key.BoneRef start) { this.boneIterator.Index = start.Id; return(this.boneIterator); }