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


C# Ray.GetPointOnRay方法代码示例

本文整理汇总了C#中Ray.GetPointOnRay方法的典型用法代码示例。如果您正苦于以下问题:C# Ray.GetPointOnRay方法的具体用法?C# Ray.GetPointOnRay怎么用?C# Ray.GetPointOnRay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ray的用法示例。


在下文中一共展示了Ray.GetPointOnRay方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnGetEditorSelectionByRay

 protected override bool OnGetEditorSelectionByRay( Ray ray, out Vec3 pos, ref float priority )
 {
     float scale1, scale2;
     bool ret = GetBox().RayIntersection( ray, out scale1, out scale2 );
     if( ret )
         pos = ray.GetPointOnRay( Math.Min( scale1, scale2 ) );
     else
         pos = Vec3.Zero;
     return ret;
 }
开发者ID:CITS4242B2010,项目名称:project2010,代码行数:10,代码来源:DynamicCollision.cs

示例2: GetDirectionalLightCameraDestinationPoint

        Vec3 GetDirectionalLightCameraDestinationPoint( Camera mainCamera, Vec3[] cornerPoints )
        {
            if( mainCamera.ProjectionType == ProjectionTypes.Perspective )
            {
                //perspective camera

                Ray cameraDirectionAsRay = new Ray( mainCamera.DerivedPosition, mainCamera.DerivedDirection );

                Vec3 nearPoint = cornerPoints[ 0 ];
                Vec3 farPoint = cornerPoints[ 4 ];

                Vec3 projectedPoint = MathUtils.ProjectPointToLine( cameraDirectionAsRay.Origin,
                    cameraDirectionAsRay.Origin + cameraDirectionAsRay.Direction, farPoint );

                if( ( projectedPoint - farPoint ).Length() >= ( projectedPoint - nearPoint ).Length() )
                {
                    return projectedPoint;
                }
                else
                {
                    Vec3 centerBetweenPoints = ( nearPoint + farPoint ) / 2;

                    Vec3 normal = ( farPoint - centerBetweenPoints ).GetNormalize();
                    Plane plane = Plane.FromPointAndNormal( centerBetweenPoints, normal );

                    float scale;
                    plane.RayIntersection( cameraDirectionAsRay, out scale );

                    return cameraDirectionAsRay.GetPointOnRay( scale );
                }
            }
            else
            {
                //orthographic camera

                Vec3 destinationPoint = Vec3.Zero;
                foreach( Vec3 point in cornerPoints )
                    destinationPoint += point;
                destinationPoint /= (float)cornerPoints.Length;

                return destinationPoint;
            }
        }
开发者ID:whztt07,项目名称:SDK,代码行数:43,代码来源:RenderingLowLevelMethodsImpl.cs

示例3: 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

示例4: CreateWaterPlaneSplash

        private void CreateWaterPlaneSplash(Ray ray)
        {
            if (ray.Direction.Z >= 0)
                return;

            foreach (WaterPlane waterPlane in WaterPlane.Instances)
            {
                //check by plane
                Plane plane = new Plane(Vec3.ZAxis, waterPlane.Position.Z);
                float scale;
                if (!plane.LineIntersection(ray.Origin, ray.Origin + ray.Direction, out scale))
                    continue;
                Vec3 pos = ray.GetPointOnRay(scale);

                //check by bounds
                Rect bounds2 = new Rect(waterPlane.Position.ToVec2());
                bounds2.Expand(waterPlane.Size * .5f);
                if (!bounds2.IsContainsPoint(pos.ToVec2()))
                    continue;

                //create splash
                waterPlane.CreateSplash(WaterPlaneType.SplashTypes.Bullet, pos);
            }
        }
开发者ID:AKNightHawk,项目名称:AssaultKnights2,代码行数:24,代码来源:Bullet.cs

示例5: MakeConvexPolyhedronForSpotLight

		static ConvexPolyhedron MakeConvexPolyhedronForSpotLight( RenderLight light )
		{
			float outerAngle = light.SpotlightOuterAngle;
			if( outerAngle < new Degree( 1 ).InRadians() )
				outerAngle = new Degree( 1 ).InRadians();
			if( outerAngle > new Degree( 179 ).InRadians() )
				outerAngle = new Degree( 179 ).InRadians();

			List<Vec3> vertices = new List<Vec3>( 10 );
			List<ConvexPolyhedron.Face> faces = new List<ConvexPolyhedron.Face>( 16 );

			Mat3 worldRotation = Quat.FromDirectionZAxisUp( light.Direction ).ToMat3();

			float sideAngle;
			{
				float radius = MathFunctions.Sin( outerAngle / 2 ) * light.AttenuationFar;

				float l = MathFunctions.Sqrt( light.AttenuationFar * light.AttenuationFar - radius * radius );
				radius /= MathFunctions.Cos( MathFunctions.PI * 2 / 16 );

				sideAngle = MathFunctions.ATan( radius / l );
			}

			Vec3 farPoint;
			{
				Mat3 pointRotation = worldRotation * Mat3.FromRotateByY( outerAngle / 4 );
				Vec3 direction = pointRotation * Vec3.XAxis;
				Vec3 point = light.Position + direction * light.AttenuationFar;

				Plane plane = Plane.FromPointAndNormal( point, direction );
				Ray ray = new Ray( light.Position, light.Direction * light.AttenuationFar );

				float scale;
				plane.RayIntersection( ray, out scale );
				farPoint = ray.GetPointOnRay( scale * 1.05f );
			}

			vertices.Add( light.Position );
			vertices.Add( farPoint );

			for( int nAxisAngle = 0; nAxisAngle < 8; nAxisAngle++ )
			{
				float axisAngle = ( MathFunctions.PI * 2 ) * ( (float)nAxisAngle / 8 );

				Mat3 worldAxisRotation = worldRotation * Mat3.FromRotateByX( axisAngle );

				Plane sidePlane;
				{
					Mat3 sideAngleRotation = Mat3.FromRotateByY( sideAngle + MathFunctions.PI / 2 );
					Mat3 pointRotation = worldAxisRotation * sideAngleRotation;
					sidePlane = Plane.FromPointAndNormal( light.Position, pointRotation * Vec3.XAxis );
				}

				{
					Mat3 pointRotation = worldAxisRotation * Mat3.FromRotateByY( outerAngle / 4 );
					Vec3 direction = pointRotation * Vec3.XAxis;
					Vec3 point = light.Position + direction * ( light.AttenuationFar * 1.05f );

					Ray ray = new Ray( farPoint, point - farPoint );

					float scale;
					sidePlane.RayIntersection( ray, out scale );
					Vec3 p = ray.GetPointOnRay( scale );

					vertices.Add( p );
				}
			}

			for( int n = 0; n < 8; n++ )
			{
				faces.Add( new ConvexPolyhedron.Face( 0, n + 2, ( n + 1 ) % 8 + 2 ) );
				faces.Add( new ConvexPolyhedron.Face( 1, ( n + 1 ) % 8 + 2, n + 2 ) );
			}

			//foreach( ConvexPolyhedron.Face face in faces )
			//{
			//   camera.DebugGeometry.Color = new ColorValue( 0, 0, 1 );
			//   Vec3 p0 = vertices[ face.Vertex0 ];
			//   Vec3 p1 = vertices[ face.Vertex1 ];
			//   Vec3 p2 = vertices[ face.Vertex2 ];
			//   camera.DebugGeometry.AddLine( p0, p1 );
			//   camera.DebugGeometry.AddLine( p1, p2 );
			//   camera.DebugGeometry.AddLine( p2, p0 );

			//   Vec3[] v = new Vec3[ 3 ] { p0, p1, p2 };
			//   int[] i = new int[] { 0, 1, 2 };
			//   camera.DebugGeometry.Color = new ColorValue( 0, 0, 1, .5f );
			//   camera.DebugGeometry.AddVertexIndexBuffer( v, i, Mat4.Identity, false, true );
			//}
			//camera.DebugGeometry.Color = new ColorValue( 1, 0, 0 );
			//foreach( Vec3 vertex in vertices )
			//   camera.DebugGeometry.AddSphere( new Sphere( vertex, .1f ) );

			return new ConvexPolyhedron( vertices.ToArray(), faces.ToArray(), .0001f );
		}
开发者ID:whztt07,项目名称:NeoAxisCommunity,代码行数:95,代码来源:RenderingLowLevelMethodsImpl.cs

示例6: GetClipPlanesForDirectionalLightShadowGeneration

        static Plane[] GetClipPlanesForDirectionalLightShadowGeneration( Camera camera,
            RenderLight light, float farClipDistance)
        {
            float shadowFarDistance = SceneManager.Instance.ShadowFarDistance;

            Frustum cameraFrustum = FrustumUtils.GetFrustumByCamera( camera, farClipDistance );

            Vec3 cameraPosition = cameraFrustum.Origin;

            Vec3 farCenterPoint;
            {
                float distance = shadowFarDistance;
                //small border
                distance *= 1.05f;

                //not optimal
                distance *= MathFunctions.Sqrt( 2 );

                farCenterPoint = cameraPosition + cameraFrustum.Axis.Item0 * distance;
            }
            Vec3 pyramidCenter = ( cameraPosition + farCenterPoint ) * .5f;

            Plane farPlane;
            {
                Vec3 normal = ( farCenterPoint - cameraPosition ).GetNormalize();
                float distance = Vec3.Dot( normal, farCenterPoint );
                farPlane = new Plane( normal, distance );
            }

            Vec3[] farCorners = new Vec3[ 4 ];
            {
                //4 - top-right far, 5 - top-left far, 6 - bottom-left far, 7 - bottom-right far.
                Vec3[] points = camera.GetWorldSpaceCorners();

                for( int n = 0; n < 4; n++ )
                {
                    Ray ray = new Ray( cameraPosition, points[ n + 4 ] - cameraPosition );
                    float scale;
                    farPlane.RayIntersection( ray, out scale );
                    farCorners[ n ] = ray.GetPointOnRay( scale );
                }
            }

            Vec3[] pyramidPoints = new Vec3[ 5 ];
            {
                pyramidPoints[ 0 ] = cameraPosition;
                for( int n = 0; n < 4; n++ )
                    pyramidPoints[ n + 1 ] = farCorners[ n ];
            }

            Line[] pyramidEdges = new Line[ 8 ];
            {
                for( int n = 0; n < 4; n++ )
                {
                    pyramidEdges[ n ] = new Line( cameraPosition, farCorners[ n ] );
                    pyramidEdges[ n + 4 ] = new Line( farCorners[ n ],
                        farCorners[ ( n + 1 ) % 4 ] );
                }
            }

            List<Plane> clipPlanes = new List<Plane>( 7 );
            {
                Vec3 lightDirectionOffset = light.Direction * 10000.0f;

                //back planes
                {
                    if( farPlane.GetSide( farCenterPoint - lightDirectionOffset ) ==
                        Plane.Side.Negative )
                    {
                        clipPlanes.Add( farPlane );
                    }

                    for( int n = 0; n < 4; n++ )
                    {
                        Plane plane = Plane.FromPoints( cameraPosition, farCorners[ n ],
                            farCorners[ ( n + 1 ) % 4 ] );

                        if( plane.GetSide( cameraPosition - lightDirectionOffset ) ==
                            Plane.Side.Negative )
                        {
                            clipPlanes.Add( farPlane );
                        }
                    }
                }

                //generate edge planes
                foreach( Line pyramidEdge in pyramidEdges )
                {
                    Vec3 p1 = pyramidEdge.Start;
                    Vec3 p2 = pyramidEdge.End;
                    Vec3 p3 = p1 - lightDirectionOffset;

                    Plane plane;
                    {
                        plane = Plane.FromPoints( p1, p2, p3 );
                        if( plane.GetSide( pyramidCenter ) == Plane.Side.Positive )
                            plane = Plane.FromPoints( p2, p1, p3 );
                    }

                    bool existsPyramidPointsOnBothSides = false;
//.........这里部分代码省略.........
开发者ID:DarrenHassan,项目名称:GDM4242-GroupD,代码行数:101,代码来源:LowLevelSceneManagement.cs


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