public void SideSelection(_Point p)
        {
            string[] sideSelection = new string[6];
            int      i             = 0;

            foreach (Cube myCube in Model)
            {
                foreach (Polygon p1 in myCube.faces)
                {
                    //if (p1 != selected)
                    p1.IsPointed = false;
                }
            }

            List <Polygon> SelectedSides = new List <Polygon>();

            i = 0;
            foreach (Cube myCube in Model)
            {
                foreach (Polygon p1 in myCube.faces)
                {
                    Edge[] polygon = p1.ePolygon(AnT.Height * 1.0);
                    if (PointInPolygon(polygon, p) == 1)
                    {
                        SelectedSides.Add(p1);
                        p1.IsPointed = true;
                        i++;
                    }
                }
            }
            k = i;
            //textBox1.Text = i.ToString();

            double  z        = 0;
            double  min      = 1;
            Polygon selected = new Polygon();

            foreach (Polygon p1 in SelectedSides)
            {
                Polygon temp = p1.Depth(out z);
                if (z < min)
                {
                    selected = temp;
                    min      = z;
                }
            }

            foreach (Cube myCube in Model)
            {
                foreach (Polygon p1 in myCube.faces)
                {
                    if (p1 != selected)
                    {
                        p1.IsPointed = false;
                    }
                }
            }
            selected.IsPointed = true;
            selectedSide       = selected;
        }
        public void EdgeSelection(_Point p)
        {
            foreach (Cube myCube in Model)
            {
                foreach (CubeEdge p1 in myCube.edges)
                {
                    // if (p1 != selected)
                    p1.IsPointed = false;
                }
            }

            foreach (Cube myCube in Model)
            {
                foreach (CubeEdge p1 in myCube.edges)
                {
                    Edge[] polygon = p1.eCubeEdge(AnT.Height * 1.0);

                    /*txtMouseX.Text = polygon[0].end.x.ToString();
                     * txtMouseY.Text = p.x.ToString();
                     *
                     * txtMouseZ.Text = polygon[0].end.y.ToString();
                     * textBox1.Text = p.y.ToString();*/

                    if ((Math.Abs(polygon[0].end.x - p.x) <= 2) && (Math.Abs(polygon[0].end.y - p.y) <= 2))
                    {
                        p1.IsPointed  = true;
                        selectedEdge_ = p1;
                        //MessageBox.Show("yahoo!!");
                        return;
                    }
                }
            }
        }
예제 #3
0
        public string Classify(_Point p0, _Point p1)
        {
            _Point p2 = new _Point(this.x, this.y);
            _Point a  = p1 - p0;
            _Point b  = p2 - p0;
            double sa = a.x * b.y - b.x * a.y;

            if (sa > 0)
            {
                return("LEFT");
            }
            if (sa < 0)
            {
                return("RIGHT");
            }
            if ((a.x * b.x < 0) || (a.y * b.y < 0))
            {
                return("BEHIND");
            }
            if (a.Length() < b.Length())
            {
                return("BEYOND");
            }
            if ((p2.x == p0.x) && (p2.y == p0.y))
            {
                return("BEGIN");
            }
            if ((p2.x == p1.x) && (p2.y == p1.y))
            {
                return("END");
            }
            return("BETWEEN");
        }
예제 #4
0
        public Edge[] eCubeEdge(double controlHeight)
        {
            Edge[] epolyg = new Edge[3];

            for (int i = 0; i < epolyg.Length; i++)
            {
                epolyg[i] = new Edge();
            }

            double xCoord = 0, yCoord = 0, zCoord = 0;

            Glu.gluProject(middle.x, middle.y, middle.z, GetModelview(), GetProjection(), GetViewport(), out xCoord, out yCoord, out zCoord);
            _Point p1 = new _Point(Math.Round(xCoord, 0), controlHeight - Math.Round(yCoord, 0));

            Glu.gluProject(begin.x, begin.y, begin.z, GetModelview(), GetProjection(), GetViewport(), out xCoord, out yCoord, out zCoord);
            _Point p0 = new _Point(Math.Round(xCoord, 0), controlHeight - Math.Round(yCoord, 0));

            epolyg[0] = new Edge(p0, p1);

            Glu.gluProject(end.x, end.y, end.z, GetModelview(), GetProjection(), GetViewport(), out xCoord, out yCoord, out zCoord);
            p1 = new _Point(Math.Round(xCoord, 0), controlHeight - Math.Round(yCoord, 0));
            Glu.gluProject(middle.x, middle.y, middle.z, GetModelview(), GetProjection(), GetViewport(), out xCoord, out yCoord, out zCoord);
            p0        = new _Point(Math.Round(xCoord, 0), controlHeight - Math.Round(yCoord, 0));
            epolyg[1] = new Edge(p0, p1);

            Glu.gluProject(end.x, end.y, end.z, GetModelview(), GetProjection(), GetViewport(), out xCoord, out yCoord, out zCoord);
            p1 = new _Point(Math.Round(xCoord, 0), controlHeight - Math.Round(yCoord, 0));
            Glu.gluProject(begin.x, begin.y, begin.z, GetModelview(), GetProjection(), GetViewport(), out xCoord, out yCoord, out zCoord);
            p0        = new _Point(Math.Round(xCoord, 0), controlHeight - Math.Round(yCoord, 0));
            epolyg[2] = new Edge(p0, p1);


            return(epolyg);
        }
        public bool EdgeHasPoint(_Point a, _Point begin, _Point end)
        {
            double p = (a.x - end.x) / (begin.x - end.x);

            if ((((p * begin.y + (1 - p) * end.y)) == a.y) && (p >= 0) && (p <= 1))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #6
0
 bool cursorInside(_Point p)
 {
     foreach (Cube myCube in Model)
     {
         foreach (Polygon p1 in myCube.faces)
         {
             Edge[] polygon = p1.ePolygon(AnT.Height * 1.0);
             if (PointInPolygon(polygon, p) == 1)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #7
0
        public Edge[] ePolygon(double controlHeight)
        {
            Edge[] epolyg = new Edge[vertices.Length - 1];

            for (int i = 0; i < epolyg.Length; i++)
            {
                epolyg[i] = new Edge();
            }

            double xCoord = 0, yCoord = 0, zCoord = 0;

            for (int i = 0; i < epolyg.Length; i++)
            {
                Glu.gluProject(vertices[i + 1].x, vertices[i + 1].y, vertices[i + 1].z, GetModelview(), GetProjection(), GetViewport(), out xCoord, out yCoord, out zCoord);
                _Point p1 = new _Point(Math.Round(xCoord, 0), controlHeight - Math.Round(yCoord, 0));
                Glu.gluProject(vertices[i].x, vertices[i].y, vertices[i].z, GetModelview(), GetProjection(), GetViewport(), out xCoord, out yCoord, out zCoord);
                _Point p0 = new _Point(Math.Round(xCoord, 0), controlHeight - Math.Round(yCoord, 0));
                epolyg[i] = new Edge(p0, p1);
            }
            return(epolyg);
        }
예제 #8
0
        double ScaleCoeff(_Point p)
        {
            double xScale;

            if (cursorInside(p))
            {
                xScale = 1 - Math.Abs(mouseEndXScale - mouseStartXScale) / 100;
            }
            else
            {
                xScale = 1 + Math.Abs(mouseEndXScale - mouseStartXScale) / 100;
            }
            //txtMouseX.Text = xScale.ToString();
            //txtMouseY.Text = mouseStartXScale.ToString();
            //txtMouseZ.Text = mouseEndXScale.ToString();
            if (xScale < 0)
            {
                return(0.3);
            }
            return(xScale);
        }
        public int PointInPolygon(Edge[] polygon, _Point p)
        {
            int parity = 0;

            for (int i = 0; i < polygon.Length; i++)
            {
                switch (EdgeType(p, polygon[i]))
                {
                case "TOUCHING":
                case "CROSSING":
                    parity++;
                    break;
                }
            }
            if ((parity % 2) == 0)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
        public string EdgeType(_Point a, Edge e)
        {
            _Point v = e.begin;
            _Point w = e.end;

            switch (a.Classify(e))
            {
            case "LEFT":
                if ((v.y < a.y) && (a.y <= w.y))
                {
                    return("CROSSING");
                }
                else
                {
                    return("INESSENTIAL");
                }

            case "RIGHT":
                if ((w.y < a.y) && (a.y <= v.y))
                {
                    return("CROSSING");
                }
                else
                {
                    return("INESSENTIAL");
                }

            case "BETWEEN":
            case "BEGIN":
            case "END":
                return("TOUCHING");

            default:
                return("INESSENTIAL");
            }
        }
예제 #11
0
 public Edge(_Point p0, _Point p1)
 {
     begin = p0; end = p1;
 }