Exemplo n.º 1
0
        private void InitBoundBoxes(Vector2 position)
        {
            Rectangle rect = new Rectangle((int)Math.Round(position.X), (int)Math.Round(position.Y), Sprite.SpriteRect.Width, Sprite.SpriteRect.Height);

            BoundBox        = new RotRectangle(rect, angle);
            BoundCircle     = new Circle(rect.Width / 2 + rect.Height / 2); // approx size, can optimize with a get corner from rotrect
            BoundBox.Origin = Sprite.Origin;
        }
Exemplo n.º 2
0
 private Vector2[] GenerateAxes(RotRectangle r)
 {
     Vector2[] axes = new Vector2[4];
     axes[0] = new Vector2(UR.X - UL.X, UR.Y - UL.Y);
     axes[1] = new Vector2(UR.X - DR.X, UR.Y - DR.Y);
     axes[2] = new Vector2(r.UL.X - r.DL.X, r.UL.Y - r.DL.Y);
     axes[3] = new Vector2(r.UL.X - r.UR.X, r.UL.Y - r.UR.Y);
     return(axes);
 }
Exemplo n.º 3
0
 public bool Intersects(RotRectangle r)
 {
     Vector2[] axes    = GenerateAxes(r);
     float[]   scalarA = new float[4];
     float[]   scalarB = new float[4];
     foreach (Vector2 axis in axes)
     {
         scalarA[0] = Vector2.Dot(axis, Vector2.Multiply(axis, Vector2.Dot(UL, axis) / axis.LengthSquared()));
         scalarA[1] = Vector2.Dot(axis, Vector2.Multiply(axis, Vector2.Dot(DL, axis) / axis.LengthSquared()));
         scalarA[2] = Vector2.Dot(axis, Vector2.Multiply(axis, Vector2.Dot(DR, axis) / axis.LengthSquared()));
         scalarA[3] = Vector2.Dot(axis, Vector2.Multiply(axis, Vector2.Dot(UR, axis) / axis.LengthSquared()));
         scalarB[0] = Vector2.Dot(axis, Vector2.Multiply(axis, Vector2.Dot(r.UL, axis) / axis.LengthSquared()));
         scalarB[1] = Vector2.Dot(axis, Vector2.Multiply(axis, Vector2.Dot(r.DL, axis) / axis.LengthSquared()));
         scalarB[2] = Vector2.Dot(axis, Vector2.Multiply(axis, Vector2.Dot(r.DR, axis) / axis.LengthSquared()));
         scalarB[3] = Vector2.Dot(axis, Vector2.Multiply(axis, Vector2.Dot(r.UR, axis) / axis.LengthSquared()));
         if (scalarB.Max() < scalarA.Min() || scalarA.Max() < scalarB.Min())
         {
             return(false);
         }
     }
     return(true);
 }