當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。