public void CollidesFrom(Rectangle rec1, Rectangle rec2)
        {
            hColFrom = sides.none;
            vColFrom = sides.none;

            if ((rec1.Top <= rec2.Top && rec1.Bottom >= rec2.Top + two) || (rec1.Top > rec2.Top && rec2.Bottom >= rec1.Top - two))
            {
                if (rec1.Right > rec2.Right)
                {
                    hColFrom = sides.right;
                }
                else if (rec1.Left < rec2.Left)
                {
                    hColFrom = sides.left;
                }
            }

            if ((rec1.Left <= rec2.Left && rec1.Right >= rec2.Left + two) || (rec1.Left > rec2.Left && rec2.Right >= rec1.Left - two))
            {
                if (rec1.Top < rec2.Top && rec1.Bottom < rec2.Top + ten)
                {
                    vColFrom = sides.top;
                }
                else if (rec1.Bottom > rec2.Bottom)
                {
                    vColFrom = sides.bottom;
                }
            }
        }
Пример #2
0
 public CollisionBox2D(Object obj, Vector3 pos, Vector2 size, CollisionType collisionType = CollisionType.Static, bool isEnabled = true)
     : base(obj, collisionType, isEnabled)
 {
     this._position = pos;
     this._size     = size;
     this.BoxSides  = new sides(pos, size);
 }
Пример #3
0
 /// <summary>
 /// return the position of the corner
 /// </summary>
 /// <param name="lr">left or right</param>
 /// <param name="ud">up or down</param>
 /// <returns></returns>
 private Position GetCorner(sides lr, sides ud)
 {
     if (lr == sides.left)
     {
         if (ud == sides.up)
         {
             return(new Position(0, 0));
         }
         else if (ud == sides.down)
         {
             return(new Position(2, 0));
         }
     }
     if (lr == sides.right)
     {
         if (ud == sides.up)
         {
             return(new Position(0, 2));
         }
         else if (ud == sides.down)
         {
             return(new Position(2, 2));
         }
     }
     throw new Exception("lr must be left or right and us must be up or down");
     return(new Position(-1, -1));
 }
Пример #4
0
 public void changeSideBack()
 {
     if (currentSide == sides.top)
     {
         currentSide = sides.left;
         return;
     }
     currentSide--;
 }
Пример #5
0
 public void changeSide()
 {
     if (currentSide == sides.left)
     {
         currentSide = 0;
         return;
     }
     currentSide++;
 }
Пример #6
0
 public bool SameSide(sides o)
 {
     return((Left == true && o.Left == true) || (Right == true && o.Right == true) || (Top == true && o.Top == true) ||
            (Bottom == true && o.Bottom == true));
 }
Пример #7
0
 public void markSide(sides side)
 {
     marked[side] = true;
 }
Пример #8
0
 private JointID getJointIdForSide(sides side, side_joints joint)
 {
     switch (side)
     {
         case sides.LEFT:
             switch (joint)
             {
                 case side_joints.ELBOW:
                     return JointID.ElbowLeft;
                 case side_joints.SHOULDER:
                     return JointID.ShoulderLeft;
                 case side_joints.WRIST:
                     return JointID.WristLeft;
                 default:
                     // Invalid
                     return JointID.Count;
             }
         case sides.RIGHT:
         {
             switch (joint)
             {
                 case side_joints.ELBOW:
                     return JointID.ElbowRight;
                 case side_joints.SHOULDER:
                     return JointID.ShoulderRight;
                 case side_joints.WRIST:
                     return JointID.WristRight;
                 default:
                     // Invalid
                     return JointID.Count;
             }
         }
         default:
             return JointID.Count;
     }
 }
Пример #9
0
        public static bool IsIntersected(Rect r, Point a, Point b)
        {
            sides code;
            Point c; /* одна из точек */
            Point start = new Point(a.X, a.Y);
            /* код конечных точек отрезка */
            sides code_a = GetIntersectionData(r, a);
            sides code_b = GetIntersectionData(r, b);

            if (code_a.IsInside() && code_b.IsInside())
            {
                return(true);
            }

            /* пока одна из точек отрезка вне прямоугольника */
            while (!code_a.IsInside() || !code_b.IsInside())
            {
                /* если обе точки с одной стороны прямоугольника, то отрезок не пересекает прямоугольник */
                if (code_a.SameSide(code_b))
                {
                    return(false);
                }

                /* выбираем точку c с ненулевым кодом */
                if (!code_a.IsInside())
                {
                    code = code_a;
                    c    = a;
                }
                else
                {
                    code = code_b;
                    c    = b;
                }

                /* если c левее r, то передвигаем c на прямую x = r->x_min
                 * если c правее r, то передвигаем c на прямую x = r->x_max */
                if (code.Left)
                {
                    c.Y += (a.Y - b.Y) * (r.Left - c.X) / (a.X - b.X);
                    c.X  = r.Left;
                }
                else if (code.Right)
                {
                    c.Y += (a.Y - b.Y) * (r.Right - c.X) / (a.X - b.X);
                    c.X  = r.Right;
                }/* если c ниже r, то передвигаем c на прямую y = r->y_min
                 *  если c выше r, то передвигаем c на прямую y = r->y_max */
                else if (code.Bottom)
                {
                    c.X += (a.X - b.X) * (r.Bottom - c.Y) / (a.Y - b.Y);
                    c.Y  = r.Bottom;
                }
                else if (code.Top)
                {
                    c.X += (a.X - b.X) * (r.Top - c.Y) / (a.Y - b.Y);
                    c.Y  = r.Top;
                }

                /* обновляем код */
                if (code == code_a)
                {
                    a      = c;
                    code_a = GetIntersectionData(r, a);
                }
                else
                {
                    b      = c;
                    code_b = GetIntersectionData(r, b);
                }
            }
            return(true);
        }
Пример #10
0
 public Color getColor(sides side)
 {
     return(colors[(int)side]);
 }
 public CollisionDetector()
 {
     hColFrom = sides.none;
     vColFrom = sides.none;
 }
Пример #12
0
 public bool SameSide(sides o)
 {
     return((Left && o.Left) || (Right && o.Right) || (Top && o.Top) ||
            (Bottom && o.Bottom));
 }
Пример #13
0
 public bool SameSide(sides o)
 {
     return (Left && o.Left) || (Right && o.Right) || (Top && o.Top)
         || (Bottom && o.Bottom);
 }
Пример #14
0
        private void tryInputSide(sides side, float height, bool alternative)
        {
            List <Point> margins;
            Point        _p1, _p2;
            Point        higher;
            Point        lower;

            switch (side)
            {
            case sides.LEFT:
                margins = marginPoints_left;
                _p1     = p1;
                _p2     = p3;
                break;

            case sides.BOTTOM:
                margins = marginPoints_bottom;
                _p1     = p3;
                _p2     = p4;
                break;

            case sides.RIGHT:
                margins = marginPoints_right;
                _p1     = p2;
                _p2     = p4;
                break;

            case sides.TOP:
                margins = marginPoints_top;
                _p1     = p1;
                _p2     = p2;
                break;

            default:
                margins = marginPoints_left;
                _p1     = p1;
                _p2     = p3;
                break;
            }
            if (_p1.getHeight() > _p2.getHeight())
            {
                higher = _p1;
                lower  = _p2;
            }
            else
            {
                higher = _p2;
                lower  = _p1;
            }

            if (alternative)
            {
                if (lower.getHeight() < height && higher.getHeight() >= height && input_side_alt != side && input_side != side && output_side != side)
                {
                    int pointIndex = Utilities.getIndexOfClosestValue(margins, height);
                    input_side_alt = side;
                    alt_input      = margins.ElementAt(pointIndex);
                    setOutput(height, true);
                }
            }
            else
            {
                if (lower.getHeight() < height && higher.getHeight() >= height && input_side != side)
                {
                    int pointIndex = Utilities.getIndexOfClosestValue(margins, height);
                    input_side = side;
                    input      = margins.ElementAt(pointIndex);
                    setOutput(height, false);
                }
            }
        }
Пример #15
0
 public bool ConnectedOnSide(sides side)
 {
     return connectedSides[(int)side];
 }
Пример #16
0
        public List<sides> GetOtherConnections(sides start)
        {
            List<sides> otherSides = new List<sides>();

            for (int i = 0; i < connectedSides.Length; i++)
            {
                if (connectedSides[i])
                    if (i != (int)start)
                        otherSides.Add((sides)i);
            }

            return otherSides;
        }
Пример #17
0
 /// <summary>
 /// returns the posotion of the side cell.
 /// </summary>
 /// <param name="s">The side</param>
 /// <returns></returns>
 private Position GetSide(sides s)
 {
     return(s == sides.up ? new Position(0, 1) : s == sides.down ? new Position(2, 1) : s == sides.left ? new Position(1, 0) : new Position(1, 2));
 }
Пример #18
0
 public bool SameSide(sides o)
 {
     return (Left ==true && o.Left == true) || (Right == true && o.Right == true) || (Top == true && o.Top == true)
         || (Bottom == true && o.Bottom == true);
 }
Пример #19
0
 public void setSideColor(sides side, Color c)
 {
     colors[(int)side] = c;
 }