Пример #1
0
        //屏幕拾取点与模型中面的映射,即拾取点属于哪个面的判断,并返回该面中心点
        public static Vertex3 PointinWhichTri(Vertex3 ObP, t3DModel model)
        {
            Vertex3 Center = new Vertex3(0, 0, 0);
            int     t      = 0;

            for (int i = 0; i < model.numOfObjects; i++)
            {
                t3DObject pObject = model.pObject[i];        //模型中的体
                for (int j = 0; j < pObject.numOfFaces; j++) //体的面
                {
                    Vertex3[] p = new Vertex3[3];
                    for (int k = 0; k < 3; k++)
                    {
                        int     index = pObject.pFaces[j].vertIndex[k];
                        Vertex3 pi    = new Vertex3(pObject.pVerts[index].x, pObject.pVerts[index].y, pObject.pVerts[index].z);//每一个三角面顶点坐标
                        p[k] = pi;
                    }

                    Triangle Tri = new Triangle(p[0], p[1], p[2]);
                    if (PointinTriangle(Tri.p1, Tri.p2, Tri.p3, ObP))
                    {
                        Center = CenterP(Tri.p1, Tri.p2, Tri.p3);
                        break;
                        //goto finish;
                    }
                }
                t++;
            }
            // finish:
            return(Center);
        }
Пример #2
0
        //计算单点特定时刻是否被遮挡
        public static bool SinglePointShelter(Vertex3 ObP, t3DModel model, Vector3 Dn)
        {
            List <string> sunside = new List <string>();
            bool          Shelter = false;

            for (int i = 1; i < model.numOfObjects; i++)
            {
                t3DObject pObject = model.pObject[i];        //模型中的体
                for (int j = 0; j < pObject.numOfFaces; j++) //体的面
                {
                    Vertex3[] p = new Vertex3[3];
                    //获取面的顶点坐标
                    for (int k = 0; k < 3; k++)
                    {
                        int     index = pObject.pFaces[j].vertIndex[k];
                        Vertex3 pi    = new Vertex3(pObject.pVerts[index].x, pObject.pVerts[index].y, pObject.pVerts[index].z);//每一个三角面顶点坐标
                        p[k] = pi;
                    }
                    Triangle Tri = new Triangle(p[0], p[1], p[2]);

                    //计算三角面的法向量
                    Tri.CalculateVectorNorm();
                    //判断三角面是否是阳面,如果是阳面则做点是否被其遮挡判断
                    Tri.SunnySide(Dn);
                    if (Tri.IsSunnySide)
                    {
                        sunside.Add(i + ";" + j);
                        //if (IntersectJudge(Tri.Vn, Tri.p1, ObP, Dn))
                        //{
                        //    Shelter = true;
                        //    break;
                        //}
                    }
                }
                //if (Shelter) break;
            }
            return(Shelter);
        }