示例#1
0
        public static BoundingRect Union(BoundingRect rect1, BoundingRect rect2)
        {
            BoundingRect result;

            float num6 = rect1.Max.X;
            float num5 = rect2.Max.X;
            float num4 = rect1.Max.Y;
            float num3 = rect2.Max.Y;
            float num2 = (rect1.Min.X < rect2.Min.X) ? rect1.Min.X : rect2.Min.X;
            float num  = (rect1.Min.Y < rect2.Min.Y) ? rect1.Min.Y : rect2.Min.Y;
            float num8 = (num6 > num5) ? num6 : num5;
            float num7 = (num4 > num3) ? num4 : num3;

            result.Min.X = num2;
            result.Min.Y = num;
            result.Max.X = num8;
            result.Max.Y = num7;

            return(result);
        }
示例#2
0
        public static void Intersect(ref BoundingRect rect1, ref BoundingRect rect2, out BoundingRect result)
        {
            float num8 = rect1.Max.X;
            float num7 = rect2.Max.X;
            float num6 = rect1.Max.Y;
            float num5 = rect2.Max.Y;
            float num2 = (rect1.Min.X > rect2.Min.X) ? rect1.Min.X : rect2.Min.X;
            float num  = (rect1.Min.Y > rect2.Min.Y) ? rect1.Min.Y : rect2.Min.Y;
            float num4 = (num8 < num7) ? num8 : num7;
            float num3 = (num6 < num5) ? num6 : num5;

            if ((num4 > num2) && (num3 > num))
            {
                result.Min.X = num2;
                result.Min.Y = num;
                result.Max.X = num4;
                result.Max.Y = num3;
            }

            result.Min.X = 0;
            result.Min.Y = 0;
            result.Max.X = 0;
            result.Max.Y = 0;
        }
示例#3
0
 static BoundingRect()
 {
     mEmpty  = new BoundingRect();
     mMinMax = new BoundingRect(Vector2.One * float.MinValue, Vector2.One * float.MaxValue);
 }
示例#4
0
        public void AddReference(Entity entity)
        {
            if (!allNodes && leaves.Count < maxLeavesBeforeSubTrees)
            {
                leaves.Add(entity);
                entity.GetComponent <QuadTreeReferenceComponent>().node = this;
            }
            else
            {
                if (!allNodes)
                {
                    subNodes.Add(new QuadTreeNode(new BoundingRect(boundingRect.Left,
                                                                   boundingRect.Bottom,
                                                                   boundingRect.Width / 2,
                                                                   boundingRect.Height / 2),
                                                  this));
                    subNodes.Add(new QuadTreeNode(new BoundingRect(boundingRect.Center.X,
                                                                   boundingRect.Bottom,
                                                                   boundingRect.Width / 2,
                                                                   boundingRect.Height / 2),
                                                  this));
                    subNodes.Add(new QuadTreeNode(new BoundingRect(boundingRect.Left,
                                                                   boundingRect.Center.Y,
                                                                   boundingRect.Width / 2,
                                                                   boundingRect.Height / 2),
                                                  this));
                    subNodes.Add(new QuadTreeNode(new BoundingRect(boundingRect.Center.X,
                                                                   boundingRect.Center.Y,
                                                                   boundingRect.Width / 2,
                                                                   boundingRect.Height / 2),
                                                  this));
                    allNodes = true;

                    List <Entity> temp = new List <Entity>();
                    temp.AddRange(leaves);
                    leaves.Clear();
                    AddReference(entity);
                    foreach (Entity e in temp)
                    {
                        AddReference(e);
                    }
                }
                else
                {
                    TransformComponent xfrom = entity.GetComponent <TransformComponent>();
                    bool noIntersect         = true;
                    foreach (QuadTreeNode qtn in subNodes)
                    {
                        BoundingRect entityAABB = entity.GetComponent <CollisionComponent>()
                                                  .GetAABB((float)Math.Cos(xfrom.Rotation),
                                                           (float)Math.Sin(xfrom.Rotation),
                                                           xfrom.Scale);
                        entityAABB.Min += xfrom.Position;
                        entityAABB.Max += xfrom.Position;
                        if (qtn.boundingRect.Contains(entityAABB))
                        {
                            qtn.AddReference(entity);
                            noIntersect = false;
                            break;
                        }
                    }
                    if (noIntersect)
                    {
                        leaves.Add(entity);
                        entity.GetComponent <QuadTreeReferenceComponent>().node = this;
                    }
                }
            }
        }
示例#5
0
 public Camera(float width, float height)
 {
     BoundingRect = new BoundingRect(_position.X, _position.Y, width, height);
     HandleResize((int)width, (int)height);
 }