当前位置: 首页>>代码示例>>C#>>正文


C# Ray.IntersectsTriangleBackfaceCulling方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Ray.IntersectsTriangleBackfaceCulling方法的典型用法代码示例。如果您正苦于以下问题:C# Ray.IntersectsTriangleBackfaceCulling方法的具体用法?C# Ray.IntersectsTriangleBackfaceCulling怎么用?C# Ray.IntersectsTriangleBackfaceCulling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Ray的用法示例。


在下文中一共展示了Ray.IntersectsTriangleBackfaceCulling方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRayIntersection

        public bool GetRayIntersection(ref Ray ray, out TriangleIntersectionResult? result, Triangle ignoreTriangle)
        {
            result = null;

            SortedList<float, List<CubeNode>> cubeoids = new SortedList<float, List<CubeNode>>();
            //SortedDictionary<float, CubeNode> cubeoids = new SortedDictionary<float, CubeNode>();
            this.GetRayCubeNodeIntersections(ref ray, this.root, cubeoids);
            if (cubeoids.Count == 0)
                return false;

            List<List<CubeNode>> intersectedCubeoids = cubeoids.Values.ToList();

            int cubeoidIndex = 0;

            float minDistance = float.MaxValue;
            float intersectionU = 0;
            float intersectionV = 0;
            Triangle intersectedTriangle = null;
            bool intersectionFound = false;
            Mesh intersectedMesh = null;

            Vector3 v1, v2, rayDirPosition;
            while (!intersectionFound && cubeoidIndex < cubeoids.Count)
            {
                List<CubeNode> cuboidGroup = intersectedCubeoids[cubeoidIndex++];
                for (int k = 0; k < cuboidGroup.Count; k++)
                {
                    List<Triangle> triangles = cuboidGroup[k].containingObjects;

                    for (int i = 0; i < triangles.Count; i++)
                    {
                        if (ignoreTriangle == null || ignoreTriangle != triangles[i])
                        {
                            float currentU, currentV, distance;
                            if (ray.IntersectsTriangleBackfaceCulling(triangles[i], out currentU, out currentV, out distance) &&
                                distance < minDistance)
                            {
                                minDistance = distance;
                                intersectionU = currentU;
                                intersectionV = currentV;
                                intersectedTriangle = triangles[i];
                                // Signal that intersection was found. Remaining objects in this cubeoid will be examined, but no more cubeoids.
                                intersectionFound = true;
                            }
                        }
                    }
                }
            }

            if (intersectionFound)
            {
                Vector3 p1 = intersectedTriangle.v2 - intersectedTriangle.v1;
                Vector3 p2 = intersectedTriangle.v3 - intersectedTriangle.v1;
                Vector3 interpolatedPosition = intersectedTriangle.v1 + (p1 * intersectionU) + (p2 * intersectionV);

                //Matrix world = intersectedSceneObject.World;
                //Vector3.Transform(ref interpolatedPosition, ref world, out interpolatedPosition);

                result = new TriangleIntersectionResult(
                    intersectedTriangle,
                    intersectionU,
                    intersectionV,
                    minDistance,
                    interpolatedPosition);
            }

            return intersectionFound;
        }
开发者ID:eitan3,项目名称:xna-ray-trace,代码行数:68,代码来源:MeshOctree.cs


注:本文中的Microsoft.Xna.Framework.Ray.IntersectsTriangleBackfaceCulling方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。