Exemplo n.º 1
0
        /// <summary>
        /// Clears any previous polygons, finds all visible bounding box attachments,
        /// and computes the world vertices for each bounding box's polygon.</summary>
        /// <param name="skeleton">The skeleton.</param>
        /// <param name="updateAabb">
        /// If true, the axis aligned bounding box containing all the polygons is computed.
        /// If false, the SkeletonBounds AABB methods will always return true.
        /// </param>
        public void Update(Skeleton skeleton, bool updateAabb)
        {
            ExposedList <BoundingBoxAttachment> boundingBoxes = BoundingBoxes;
            ExposedList <Polygon> polygons = Polygons;
            ExposedList <Slot>    slots    = skeleton.slots;
            int slotCount = slots.Count;

            boundingBoxes.Clear();
            for (int i = 0, n = polygons.Count; i < n; i++)
            {
                polygonPool.Add(polygons.Items[i]);
            }
            polygons.Clear();

            for (int i = 0; i < slotCount; i++)
            {
                Slot slot = slots.Items[i];
                if (!slot.bone.active)
                {
                    continue;
                }
                BoundingBoxAttachment boundingBox = slot.attachment as BoundingBoxAttachment;
                if (boundingBox == null)
                {
                    continue;
                }
                boundingBoxes.Add(boundingBox);

                Polygon polygon   = null;
                int     poolCount = polygonPool.Count;
                if (poolCount > 0)
                {
                    polygon = polygonPool.Items[poolCount - 1];
                    polygonPool.RemoveAt(poolCount - 1);
                }
                else
                {
                    polygon = new Polygon();
                }
                polygons.Add(polygon);

                int count = boundingBox.worldVerticesLength;
                polygon.Count = count;
                if (polygon.Vertices.Length < count)
                {
                    polygon.Vertices = new float[count];
                }
                boundingBox.ComputeWorldVertices(slot, polygon.Vertices);
            }

            if (updateAabb)
            {
                AabbCompute();
            }
            else
            {
                minX = int.MinValue;
                minY = int.MinValue;
                maxX = int.MaxValue;
                maxY = int.MaxValue;
            }
        }
Exemplo n.º 2
0
        public Polygon GetPolygon(BoundingBoxAttachment attachment)
        {
            int index = BoundingBoxes.IndexOf(attachment);

            return(index == -1 ? null : Polygons.Items[index]);
        }