예제 #1
0
		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];
				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.Vertices.Length;
				polygon.Count = count;
				if (polygon.Vertices.Length < count) polygon.Vertices = new float[count];
				boundingBox.ComputeWorldVertices(slot, polygon.Vertices);
			}

			if (updateAabb) aabbCompute();
		}
		/// <summary>Returns true if the polygon contains the line segment.</summary>
		public bool IntersectsSegment (Polygon polygon, float x1, float y1, float x2, float y2) {
			float[] vertices = polygon.Vertices;
			int nn = polygon.Count;

			float width12 = x1 - x2, height12 = y1 - y2;
			float det1 = x1 * y2 - y1 * x2;
			float x3 = vertices[nn - 2], y3 = vertices[nn - 1];
			for (int ii = 0; ii < nn; ii += 2) {
				float x4 = vertices[ii], y4 = vertices[ii + 1];
				float det2 = x3 * y4 - y3 * x4;
				float width34 = x3 - x4, height34 = y3 - y4;
				float det3 = width12 * height34 - height12 * width34;
				float x = (det1 * width34 - width12 * det2) / det3;
				if (((x >= x3 && x <= x4) || (x >= x4 && x <= x3)) && ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))) {
					float y = (det1 * height34 - height12 * det2) / det3;
					if (((y >= y3 && y <= y4) || (y >= y4 && y <= y3)) && ((y >= y1 && y <= y2) || (y >= y2 && y <= y1))) return true;
				}
				x3 = x4;
				y3 = y4;
			}
			return false;
		}
		/// <summary>Returns true if the polygon contains the point.</summary>
		public bool ContainsPoint (Polygon polygon, float x, float y) {
			float[] vertices = polygon.Vertices;
			int nn = polygon.Count;

			int prevIndex = nn - 2;
			bool inside = false;
			for (int ii = 0; ii < nn; ii += 2) {
				float vertexY = vertices[ii + 1];
				float prevY = vertices[prevIndex + 1];
				if ((vertexY < y && prevY >= y) || (prevY < y && vertexY >= y)) {
					float vertexX = vertices[ii];
					if (vertexX + (y - vertexY) / (prevY - vertexY) * (vertices[prevIndex] - vertexX) < x) inside = !inside;
				}
				prevIndex = ii;
			}
			return inside;
		}
예제 #4
0
        public void Update(Skeleton skeleton, bool updateAabb)
        {
            List<BoundingBoxAttachment> boundingBoxes = BoundingBoxes;
            List<Polygon> polygons = Polygons;
            List<Slot> slots = skeleton.slots;
            int slotCount = slots.Count;

            boundingBoxes.Clear();
            foreach (Polygon polygon in polygons)
                polygonPool.Add(polygon);
            polygons.Clear();

            for (int i = 0; i < slotCount; i++) {
                Slot slot = slots[i];
                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[poolCount - 1];
                    polygonPool.RemoveAt(poolCount - 1);
                }
                else
                {
                    polygon = new Polygon();
                    polygon.Count = boundingBox.Vertices.Length;
                    polygon.Vertices = boundingBox.Vertices;
                }
                polygons.Add(polygon);

                boundingBox.ComputeWorldVertices(slot.bone, polygon.Vertices.ToArray());
            }

            Polygons = polygons;

            if (updateAabb) aabbCompute();
        }
예제 #5
0
        public void Update(Skeleton skeleton)
        {
            aabb = false;

            List<BoundingBoxAttachment> boundingBoxes = BoundingBoxes;
            List<Polygon> polygons = Polygons;
            List<Slot> slots = skeleton.slots;
            int slotCount = slots.Count;
            float x = skeleton.x, y = skeleton.y;

            boundingBoxes.Clear();
            foreach (Polygon polygon in polygons)
                polygonPool.Add(polygon);
            polygons.Clear();

            for (int i = 0; i < slotCount; i++) {
                Slot slot = slots[i];
                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[poolCount - 1];
                    polygonPool.RemoveAt(poolCount - 1);
                } else
                    polygon = new Polygon();
                polygons.Add(polygon);

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