本文整理汇总了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;
}