本文整理汇总了C#中Ray.SetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Ray.SetLength方法的具体用法?C# Ray.SetLength怎么用?C# Ray.SetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ray
的用法示例。
在下文中一共展示了Ray.SetLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Intersect
//https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
public override bool Intersect(Ray ray, out Intersection intersection)
{
Statistics.Add("Triangle test");
intersection = null;
//don't intersect backside
if (Vector3.Dot(ray.Direction, Normal) > 0)
{
return false;
}
var P = Vector3.Cross(ray.Direction, _e2);
var det = Vector3.Dot(_e1, P);
//if determinant is near zero, then there is no intersection
if (det > -float.Epsilon && det < float.Epsilon)
{
return false;
}
var invDet = 1/det;
var T = Vector3.Subtract(ray.Origin, _p1);
//calculate u coordinate of triangle
var u = Vector3.Dot(T, P)*invDet;
//if it lies outside the triangle
if (u < 0 || u > 1)
{
return false;
}
var Q = Vector3.Cross(T, _e1);
//calculate v coordinate of triangle
var v = Vector3.Dot(ray.Direction, Q)*invDet;
//if it lies outside the triangle
if (v < 0 || u + v > 1)
{
return false;
}
//t parameter of ray
float t = Vector3.Dot(_e2, Q)*invDet;
if (t > Constants.MinimumRayT && t <= ray.T)
{
var intersectionPoint = ray.GetPoint(t);
ray.SetLength(t);
intersection = new Intersection(this, ray, Normal, intersectionPoint, t, Material);
Statistics.Add("Triangle test success");
return true;
}
return false;
}