Beispiel #1
0
 public static bool Check(Vector2 point, Transform trans)
 {
     Matrix matPoint = Matrix.CreateTranslation(point.X, point.Y, 0);
     Matrix matTrans = trans.GetMatrix();
     Matrix convert = matPoint * Matrix.Invert(matTrans);
     Vector2 convertPoint = Vector2.Transform(point, convert);
     return Check(convertPoint, new Rectangle(0, 0, (int)trans.Size.X, (int)trans.Size.Y));
 }
Beispiel #2
0
 public static bool Check(Vector2 point, Transform trans, Texture2D texture)
 {
     Matrix matPoint = Matrix.CreateTranslation(point.X, point.Y, 0);
     Matrix matTrans = trans.GetMatrix();
     Matrix convert = matPoint * Matrix.Invert(matTrans);
     Vector2 convertPoint = Vector2.Transform(point, convert);
     if (Check(convertPoint, new Rectangle(0, 0, (int)trans.Size.X, (int)trans.Size.Y)))
     {
         Color[] data =  new Color[texture.Width * texture.Height];
         texture.GetData(data);
         Point p = new Point((int)convertPoint.X, (int)convertPoint.Y);
         if (data[p.X + p.Y * texture.Width].A != 0)
             return true;
         return false;
     }
     return false;
 }
Beispiel #3
0
 public static bool Check(Point point, Transform trans, Texture2D texture)
 {
     Vector2 p = new Vector2(point.X, point.Y);
     return Check(p, trans, texture);
 }
Beispiel #4
0
 public static bool Check(Point point, Transform trans)
 {
     Vector2 p = new Vector2(point.X, point.Y);
     return Check(p, trans);
 }
Beispiel #5
0
        public static void Transform(ETransformType ett, Vector2 pDelta, Transform trans)
        {
            switch (ett)
            {
                case ETransformType.TopLeft:
                    trans.Size = new Vector2((float)Math.Max(trans.Size.X - pDelta.X, 1.0f), (float)Math.Max(trans.Size.Y - pDelta.Y, 1.0f));
                    // Keep the position of the Bottom Right corner
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2f, trans.Position.Y + pDelta.Y / 2f);
                    break;
                case ETransformType.TopRight:
                    trans.Size = new Vector2((float)Math.Max(trans.Size.X + pDelta.X, 1.0f), (float)Math.Max(trans.Size.Y - pDelta.Y, 1));
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2f, trans.Position.Y + pDelta.Y / 2);
                    break;
                case ETransformType.BottomLeft:
                    trans.Size = new Vector2((float)Math.Max(trans.Size.X - pDelta.X, 1.0f), (float)Math.Max(trans.Size.Y + pDelta.Y, 1.0f));
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2f, trans.Position.Y + pDelta.Y / 2f);
                    break;
                case ETransformType.BottomRight:
                    trans.Size = new Vector2((float)Math.Max(trans.Size.X + pDelta.X, 1f), (float)Math.Max(trans.Size.Y + pDelta.Y, 1f));
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2f, trans.Position.Y + pDelta.Y / 2f);
                    break;

                case ETransformType.Top:
                    trans.Size = new Vector2(trans.Size.X, trans.Size.Y - pDelta.Y);
                    trans.Position = new Vector2(trans.Position.X, trans.Position.Y + pDelta.Y / 2);
                    break;
                case ETransformType.Bottom:
                    trans.Size = new Vector2(trans.Size.X, trans.Size.Y + pDelta.Y);
                    trans.Position = new Vector2(trans.Position.X, trans.Position.Y + pDelta.Y / 2);
                    break;
                case ETransformType.Left:
                    trans.Size = new Vector2(trans.Size.X - pDelta.X, trans.Size.Y);
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2, trans.Position.Y);
                    break;
                case ETransformType.Right:
                    trans.Size = new Vector2(trans.Size.X + pDelta.X, trans.Size.Y);
                    trans.Position = new Vector2(trans.Position.X + pDelta.X / 2, trans.Position.Y);
                    break;

                case ETransformType.Middle:
                    trans.Position = new Vector2(trans.Position.X + pDelta.X, trans.Position.Y + pDelta.Y);
                    break;
            }
        }