Drizzle

博客园 首页 新随笔 联系 订阅 管理

参考于http://www.gamedev.net/community/forums/topic.asp?topic_id=295123&whichpage=1?

已知Mesh对象myMesh、相交信息IntersectInformation intInfo。
1.得到三角形
                short[] intersectedIndices = new short[3];
                short[] indices = (short[])myMesh.LockIndexBuffer(typeof(short), LockFlags.ReadOnly, myMesh.NumberFaces * 3);
                Array.Copy(indices, intInf.FaceIndex * 3, intersectedIndices, 0, 3);
                myMesh.UnlockIndexBuffer();

                // create an array to hold the vertices for the intersected face
                CustomVertex.PositionNormalTextured[] IntersectedVertices = new CustomVertex.PositionNormalTextured[3];

                // extract vertex data from mesh, using our indices we obtained earlier
                CustomVertex.PositionNormalTextured[] meshVertices = (CustomVertex.PositionNormalTextured[])myMesh.LockVertexBuffer(typeof(CustomVertex.PositionNormalTextured), LockFlags.ReadOnly, myMesh.NumberVertices);
               //三个顶点
                IntersectedVertices[0] = meshVertices[intersectedIndices[0]];
                IntersectedVertices[1] = meshVertices[intersectedIndices[1]];
                IntersectedVertices[2] = meshVertices[intersectedIndices[2]];
                myMesh.UnlockVertexBuffer();
2.求交点
             //三角形三个点的向量。
            Vector3 v1 = new Vector3(IntersectedVertices[0].X, IntersectedVertices[0].Y, IntersectedVertices[0].Z);
            Vector3 v2 = new Vector3(IntersectedVertices[1].X, IntersectedVertices[1].Y, IntersectedVertices[1].Z);
            Vector3 v3 = new Vector3(IntersectedVertices[2].X, IntersectedVertices[2].Y, IntersectedVertices[2].Z);

            //交点
            pickedPosition = v1 + intInf.V * (v3 - v1) + intInf.U * (v2 - v1);
3.操纵三角形

posted on 2006-10-08 17:14  岁月随风  阅读(279)  评论(0编辑  收藏  举报