Ejemplo n.º 1
0
    public zCollisionPath(GLEED2D.PathItem path)
    {
        //  m_localPoints = path.LocalPoints;
        m_worldPoints = path.WorldPoints;
        m_lineWidth   = path.LineWidth;
        m_lineColor   = path.LineColor;
        m_isPolygon   = path.IsPolygon; //TODO handle this thing!

        m_normals   = new Vector2[m_worldPoints.Length - 1];
        m_midpoints = new Vector2[m_worldPoints.Length - 1];

        float leftMoast;
        float rightMost;
        float topMost;
        float bottomMost;

        leftMoast = rightMost = m_worldPoints[0].X;
        topMost   = bottomMost = m_worldPoints[0].Y;

        for (int i = 0; i < m_worldPoints.Length - 1; ++i)
        {
            Vector2 line = m_worldPoints[i + 1] - m_worldPoints[i];

            m_midpoints[i] = (line / 2.0f) + m_worldPoints[i];
            m_normals[i].X = line.Y;
            m_normals[i].Y = -line.X;
            m_normals[i].Normalize();

            //Check against bounding coords

            //Since we initialized to location 0 we use location i+1 to ensure we also check the last points in the line
            if (m_worldPoints[i + 1].X < leftMoast)
            {
                leftMoast = m_worldPoints[i + 1].X;
            }
            else if (m_worldPoints[i + 1].X > rightMost)
            {
                rightMost = m_worldPoints[i + 1].X;
            }

            if (m_worldPoints[i + 1].Y < topMost)
            {
                topMost = m_worldPoints[i + 1].Y;
            }
            else if (m_worldPoints[i + 1].Y > bottomMost)
            {
                bottomMost = m_worldPoints[i + 1].Y;
            }
        }

        //Floor the top left coord and ciel the width and height, better to have a slightly bigger box then a too small one
        m_boundingRect = new Rectangle((int)leftMoast, (int)topMost, (int)Math.Ceiling(rightMost - leftMoast), (int)Math.Ceiling(bottomMost - topMost));
    }
Ejemplo n.º 2
0
 public void paintPrimitiveBrush()
 {
     switch (currentprimitive)
     {
         case PrimitiveType.Rectangle:
             Item ri = new RectangleItem(Extensions.RectangleFromVectors(clickedPoints[0], clickedPoints[1]));
             ri.Name = ri.getNamePrefix() + level.getNextItemNumber();
             ri.layer = SelectedLayer;
             beginCommand("Add Item \"" + ri.Name + "\"");
             addItem(ri);
             endCommand();
             MainForm.Instance.toolStripStatusLabel1.Text = Resources.Rectangle_Entered;
             break;
         case PrimitiveType.Circle:
             Item ci = new CircleItem(clickedPoints[0], (mouseworldpos - clickedPoints[0]).Length());
             ci.Name = ci.getNamePrefix() + level.getNextItemNumber();
             ci.layer = SelectedLayer;
             beginCommand("Add Item \"" + ci.Name + "\"");
             addItem(ci);
             endCommand();
             MainForm.Instance.toolStripStatusLabel1.Text = Resources.Circle_Entered;
             break;
         case PrimitiveType.Path:
             Item pi = new PathItem(clickedPoints.ToArray());
             pi.Name = pi.getNamePrefix() + level.getNextItemNumber();
             pi.layer = SelectedLayer;
             beginCommand("Add Item \"" + pi.Name + "\"");
             addItem(pi);
             endCommand();
             MainForm.Instance.toolStripStatusLabel1.Text = Resources.Path_Entered;
             AdesExtensions.onAddPoly(pi);
             break;
     }
     updatetreeview();
 }
Ejemplo n.º 3
0
        public void paintPrimitiveBrush()
        {
            int nextnum = level.getNextItemNumber();
            switch (currentprimitive)
            {

                case PrimitiveType.CollisionRectangle:
                    MapObject ri;
                    if (customEntity)
                    {
                        ri = (MapObject)Activator.CreateInstance(customEntityType, Extensions.RectangleFromVectors(clickedPoints[0], clickedPoints[1]));

                    }
                    else
                    {
                        ri = new CollisionRectangle(Extensions.RectangleFromVectors(clickedPoints[0], clickedPoints[1]));
                    }

                    ri.Id = generateID(nextnum);
                    ri.Name = ri.getNamePrefix() + nextnum;
                    ri.layer = SelectedLayer;
                    beginCommand("Add MapObject \"" + ri.Name + "\"");
                    addItem(ri);
                    endCommand();
                    MainForm.Instance.toolStripStatusLabel1.Text = Resources.Rectangle_Entered;
                    break;
                case PrimitiveType.Circle:
                    MapObject ci;
                    if (customEntity)
                    {
                        ci = (MapObject)Activator.CreateInstance(customEntityType, clickedPoints[0], (mouseworldpos - clickedPoints[0]).Length());

                    }
                    else
                    {
                        ci = new CircleItem(clickedPoints[0], (mouseworldpos - clickedPoints[0]).Length());
                    }
                    ci.Id = generateID(nextnum);
                    ci.Name = ci.getNamePrefix() + nextnum;// level.getNextItemNumber();
                    ci.layer = SelectedLayer;
                    beginCommand("Add MapObject \"" + ci.Name + "\"");
                    addItem(ci);
                    endCommand();
                    MainForm.Instance.toolStripStatusLabel1.Text = Resources.Circle_Entered;
                    break;
                case PrimitiveType.Path:
                    MapObject pi;
                    if (customEntity)
                    {
                        pi = (MapObject)Activator.CreateInstance(customEntityType, clickedPoints.ToArray());

                    }
                    else
                    {
                         pi = new PathItem(clickedPoints.ToArray());
                    }

                    pi.Id = generateID(nextnum);
                    pi.Name = pi.getNamePrefix()+nextnum;//
                    pi.layer = SelectedLayer;
                    beginCommand("Add MapObject \"" + pi.Name + "\"");
                    addItem(pi);
                    endCommand();
                    MainForm.Instance.toolStripStatusLabel1.Text = Resources.Path_Entered;
                    break;
            }
            updatetreeview();
        }