Exemplo n.º 1
0
        public virtual void ItemsInBoundingSphere <T>(List <T> objects, Sphere boundingSphere) where T : IOctreeObject
        {
            // if the current box is totally contained in our leaf, then add me and all my kids
            if (boundingSphere.Contains(ContainerBox) == ContainmentType.Contains)
            {
                FastAddChildren <T>(objects);
            }
            else
            {
                // ok so we know that we are probably intersecting or outside
                foreach (T item in containedObjects) // add our stragglers
                {
                    objects.Add(item);
                }

                if (ChildLeaves != null)
                {
                    foreach (OctreeLeaf leaf in ChildLeaves)
                    {
                        // see if any of the sub boxes intersect our frustum
                        if (leaf.ContainerBox.Intersects(boundingSphere))
                        {
                            leaf.ItemsInBoundingSphere <T>(objects, boundingSphere);
                        }
                    }
                }
            }
        }
    public void NewRenderStatus(Transform Object, bool ShouldRender)
    {
        if (ShouldRender)
        {
            SetRenderer(Object, true);
        }

        else
        {
            int ReferenceCount = 0;
            foreach (RenderSphere Sphere in RenderSpheres)
            {
                if (Sphere.Contains(Object))
                {
                    ++ReferenceCount;
                }
            }

            // If there is no RenderSpheres which have this Transform in their collision list, it's not in range.
            if (ReferenceCount < 1)
            {
                SetRenderer(Object, false);
            }
        }
    }
Exemplo n.º 3
0
        static void FloodFill(VectorMap map, Point origin, Sphere target, BoolMap fillMap, out int area, out Rectangle bounds)
        {
            var queue = new Queue <Point>(map.Width + map.Height);

            queue.Enqueue(origin);
            bounds = new Rectangle(int.MaxValue, int.MaxValue, 0, 0);
            area   = 0;
            while (queue.Count > 0)
            {
                Point p = queue.Dequeue();
                if (fillMap[p.X, p.Y] || !target.Contains(map[p]))
                {
                    continue;
                }
                fillMap[p.X, p.Y] = true;
                if (bounds.X > p.X)
                {
                    bounds.X = p.X;
                }
                if (bounds.Y > p.Y)
                {
                    bounds.Y = p.Y;
                }
                if (bounds.Right <= p.X)
                {
                    bounds.Width = p.X - bounds.X + 1;
                }
                if (bounds.Bottom <= p.Y)
                {
                    bounds.Height = p.Y - bounds.Y + 1;
                }
                area++;
                if (p.X > 0)
                {
                    queue.Enqueue(new Point(p.X - 1, p.Y));
                }
                if (p.Y > 0)
                {
                    queue.Enqueue(new Point(p.X, p.Y - 1));
                }
                if (p.X < map.Width - 1)
                {
                    queue.Enqueue(new Point(p.X + 1, p.Y));
                }
                if (p.Y < map.Height - 1)
                {
                    queue.Enqueue(new Point(p.X, p.Y + 1));
                }
            }
            if (bounds.Size == Size.Empty)
            {
                bounds.Location = Point.Empty;
            }
        }
Exemplo n.º 4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (loadedImage == null || !browseButton.Enabled)
            {
                return;
            }
            Rectangle clipRectangle = Rectangle.Intersect(e.ClipRectangle, imageRect);

            if (clipRectangle == Rectangle.Empty)
            {
                return;
            }
            if (!showChromaMap.Checked)
            {
                e.Graphics.DrawImage(loadedImage, imageRect);
            }
            else
            {
                using (Bitmap cm = chromaMap.ToBitmap()) e.Graphics.DrawImage(cm, imageRect);
            }

            var queue   = new Queue <Point>(chromaMap.Width + chromaMap.Height);
            var fillMap = new BoolMap(chromaMap.Width, chromaMap.Height);

            queue.Enqueue(fillOrigin);
            while (queue.Count > 0)
            {
                Point p = queue.Dequeue();
                if (fillMap[p.X, p.Y] || !boundingSphere.Contains(chromaMap[p]))
                {
                    continue;
                }
                fillMap[p.X, p.Y] = true;
                Point q = new Point(imageRect.X + p.X, imageRect.Y + p.Y);
                e.Graphics.FillRectangle(Brushes.Blue, q.X, q.Y, 1, 1);
                if (p.X > 0)
                {
                    queue.Enqueue(new Point(p.X - 1, p.Y));
                }
                if (p.Y > 0)
                {
                    queue.Enqueue(new Point(p.X, p.Y - 1));
                }
                if (p.X < chromaMap.Width - 1)
                {
                    queue.Enqueue(new Point(p.X + 1, p.Y));
                }
                if (p.Y < chromaMap.Height - 1)
                {
                    queue.Enqueue(new Point(p.X, p.Y + 1));
                }
            }
        }