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


C# Sphere.RayIntersection方法代码示例

本文整理汇总了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 );
        }
开发者ID:whztt07,项目名称:SDK,代码行数:53,代码来源:RenderingLowLevelMethodsImpl.cs


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