zoukankan      html  css  js  c++  java
  • 使用IntersectInformation类

    参考于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.操纵三角形

  • 相关阅读:
    单元測试和白盒測试相关总结
    数据结构:图的实现--邻接矩阵
    Android提示版本号更新操作流程
    《集体智慧编程》代码勘误:第六章
    LINUX设备驱动程序笔记(三)字符设备驱动程序
    数学定理证明机械化的中国学派(II)
    《Java并发编程实战》第三章 对象的共享 读书笔记
    Linux系列-安装经常使用软件
    Kubuntu 初始配置
    虚拟互换(virtual swap)
  • 原文地址:https://www.cnblogs.com/Drizzle/p/523569.html
Copyright © 2011-2022 走看看