Ejemplo n.º 1
0
        protected int SelectFaceByPoint(bool laser)
        {
            CRectangle viewport = new CRectangle(0, 0,  Width,  Height);
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh m = mesh;

            double eps = ToolSetting.ToolsSetting.DepthTolerance;

            bool isInFace = false;
            int minIndex = -1;
            for (int i = 0; i < m.Faces.Count; i++)
            {

                Vector3D v1 = projector.Project(m.Faces[i].GetVertex(0).Traits.Position);
                Vector3D v2 = projector.Project(m.Faces[i].GetVertex(1).Traits.Position);
                Vector3D v3 = projector.Project(m.Faces[i].GetVertex(2).Traits.Position);


                Vector2D u1 = new GraphicResearchHuiZhao.Vector2D(v1.x, v1.y);
                Vector2D u2 = new GraphicResearchHuiZhao.Vector2D(v2.x, v2.y);
                Vector2D u3 = new GraphicResearchHuiZhao.Vector2D(v3.x, v3.y);

                if (!viewport.Contains((int)v1.x, (int)v1.y) && !viewport.Contains((int)v2.x, (int)v2.y) && !viewport.Contains((int)v2.x, (int)v2.y)) continue;

                //  if (!laser && projector.GetDepthValue((int)v1.x, (int)v1.y) - v1.z < eps) continue;
                //isInFace=PointinTriangle(u1,u2,u3,mouseCurrPos);
                isInFace = IsInTriangle(u1, u2, u3, mouseCurrPos);
                if (isInFace)
                {
                    minIndex = i;
                }


            }
            if (minIndex == -1) return minIndex;



            if (key == EnumKey.Shift)
                m.Faces[minIndex].Traits.SelectedFlag = (byte)1;
            else if (key == EnumKey.Ctrl)
                m.Faces[minIndex].Traits.SelectedFlag = (byte)0;
            else
            {

                for (int i = 0; i < m.Faces.Count; i++)
                {

                    m.Faces[i].Traits.SelectedFlag = (byte)0;

                }


                m.Faces[minIndex].Traits.SelectedFlag = (byte)1;
            }
            return minIndex;
        }
Ejemplo n.º 2
0
        protected int SelectFaceByPoint(bool laser)
        {
            CRectangle      viewport  = new CRectangle(0, 0, Width, Height);
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh         m         = mesh;

            double eps = ToolSetting.ToolsSetting.DepthTolerance;

            bool isInFace = false;
            int  minIndex = -1;

            for (int i = 0; i < m.Faces.Count; i++)
            {
                Vector3D v1 = projector.Project(m.Faces[i].GetVertex(0).Traits.Position);
                Vector3D v2 = projector.Project(m.Faces[i].GetVertex(1).Traits.Position);
                Vector3D v3 = projector.Project(m.Faces[i].GetVertex(2).Traits.Position);


                Vector2D u1 = new GraphicResearchHuiZhao.Vector2D(v1.x, v1.y);
                Vector2D u2 = new GraphicResearchHuiZhao.Vector2D(v2.x, v2.y);
                Vector2D u3 = new GraphicResearchHuiZhao.Vector2D(v3.x, v3.y);

                if (!viewport.Contains((int)v1.x, (int)v1.y) && !viewport.Contains((int)v2.x, (int)v2.y) && !viewport.Contains((int)v2.x, (int)v2.y))
                {
                    continue;
                }

                //  if (!laser && projector.GetDepthValue((int)v1.x, (int)v1.y) - v1.z < eps) continue;
                //isInFace=PointinTriangle(u1,u2,u3,mouseCurrPos);
                isInFace = IsInTriangle(u1, u2, u3, mouseCurrPos);
                if (isInFace)
                {
                    minIndex = i;
                }
            }
            if (minIndex == -1)
            {
                return(minIndex);
            }



            if (key == EnumKey.Shift)
            {
                m.Faces[minIndex].Traits.SelectedFlag = (byte)1;
            }
            else if (key == EnumKey.Ctrl)
            {
                m.Faces[minIndex].Traits.SelectedFlag = (byte)0;
            }
            else
            {
                for (int i = 0; i < m.Faces.Count; i++)
                {
                    m.Faces[i].Traits.SelectedFlag = (byte)0;
                }


                m.Faces[minIndex].Traits.SelectedFlag = (byte)1;
            }
            return(minIndex);
        }