本文整理汇总了C#中Sphere.RayIntersection方法的典型用法代码示例。如果您正苦于以下问题:C# Sphere.RayIntersection方法的具体用法?C# Sphere.RayIntersection怎么用?C# Sphere.RayIntersection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sphere
的用法示例。
在下文中一共展示了Sphere.RayIntersection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDirectionalLightCameraCornerPoints
void GetDirectionalLightCameraCornerPoints( Camera mainCamera, float initialNearDistance,
float initialFarDistance, bool clipByShadowFarDistance, out Vec3[] cornerPoints )
{
float nearDistance = initialNearDistance;
float farDistance = initialFarDistance;
Frustum frustum = FrustumUtils.GetFrustumByCamera( mainCamera );
//clip by shadow far distance sphere (only for perspective camera)
if( mainCamera.ProjectionType == ProjectionTypes.Perspective && clipByShadowFarDistance )
{
Vec3[] points = null;
frustum.ToPoints( ref points );
Sphere sphere = new Sphere( mainCamera.DerivedPosition, farDistance );
Vec3[] intersections = new Vec3[ 3 ];
for( int n = 0; n < 3; n++ )
{
Vec3 pointEnd = points[ n + 4 ];
float scale1;
float scale2;
Ray ray = new Ray( mainCamera.DerivedPosition, pointEnd - mainCamera.DerivedPosition );
sphere.RayIntersection( ray, out scale1, out scale2 );
float scale = Math.Max( scale1, scale2 );
intersections[ n ] = ray.GetPointOnRay( scale );
}
Plane farPlane = Plane.FromPoints( intersections[ 0 ], intersections[ 1 ], intersections[ 2 ] );
Ray cameraDirectionAsRay = new Ray( mainCamera.DerivedPosition, mainCamera.DerivedDirection );
Vec3 pointByDirection;
farPlane.RayIntersection( cameraDirectionAsRay, out pointByDirection );
farDistance = ( pointByDirection - mainCamera.DerivedPosition ).Length();
if( nearDistance + 5 > farDistance )
farDistance = nearDistance + 5;
}
if( nearDistance < .0001f )
nearDistance = .0001f;
if( farDistance < nearDistance + .01f )
farDistance = nearDistance + .01f;
frustum.NearDistance = nearDistance;
frustum.MoveFarDistance( farDistance );
cornerPoints = null;
frustum.ToPoints( ref cornerPoints );
}