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


C# Camera.SetOrthoWindow方法代码示例

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


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

示例1: GetShadowCamera

		public void GetShadowCamera( SceneManager sceneManager, Camera camera, Viewport viewport, Light light,
		                             Camera textureCamera, int iteration )
		{
			Vector3 pos, dir;
			Quaternion q;

			// reset custom view / projection matrix in case already set
			textureCamera.SetCustomViewMatrix( false );
			textureCamera.SetCustomProjectionMatrix( false );
			textureCamera.Near = light.DeriveShadowNearClipDistance( camera );
			textureCamera.Far = light.DeriveShadowFarClipDistance( camera );


			// get the shadow frustum's far distance
			var shadowDist = light.ShadowFarDistance;
			if ( shadowDist == 0.0f )
			{
				// need a shadow distance, make one up
				shadowDist = camera.Near*300;
			}
			var shadowOffset = shadowDist*sceneManager.ShadowDirectionalLightTextureOffset;

			// Directional lights
			if ( light.Type == LightType.Directional )
			{
				// set up the shadow texture
				// Set ortho projection
				textureCamera.ProjectionType = Projection.Orthographic;
				// set ortho window so that texture covers far dist
				textureCamera.SetOrthoWindow( shadowDist*2, shadowDist*2 );

				// Calculate look at position
				// We want to look at a spot shadowOffset away from near plane
				// 0.5 is a litle too close for angles
				var target = camera.DerivedPosition + ( camera.DerivedDirection*shadowOffset );

				// Calculate direction, which same as directional light direction
				dir = -light.DerivedDirection; // backwards since point down -z
				dir.Normalize();

				// Calculate position
				// We want to be in the -ve direction of the light direction
				// far enough to project for the dir light extrusion distance
				pos = target + dir*sceneManager.ShadowDirectionalLightExtrusionDistance;

				// Round local x/y position based on a world-space texel; this helps to reduce
				// jittering caused by the projection moving with the camera
				// Viewport is 2 * near clip distance across (90 degree fov)
				//~ Real worldTexelSize = (texCam->getNearClipDistance() * 20) / vp->getActualWidth();
				//~ pos.x -= fmod(pos.x, worldTexelSize);
				//~ pos.y -= fmod(pos.y, worldTexelSize);
				//~ pos.z -= fmod(pos.z, worldTexelSize);
				var worldTexelSize = ( shadowDist*2 )/textureCamera.Viewport.ActualWidth;

				//get texCam orientation

				var up = Vector3.UnitY;
				// Check it's not coincident with dir
				if ( Utility.Abs( up.Dot( dir ) ) >= 1.0f )
				{
					// Use camera up
					up = Vector3.UnitZ;
				}
				// cross twice to rederive, only direction is unaltered
				var left = dir.Cross( up );
				left.Normalize();
				up = dir.Cross( left );
				up.Normalize();
				// Derive quaternion from axes
				q = Quaternion.FromAxes( left, up, dir );

				//convert world space camera position into light space
				var lightSpacePos = q.Inverse()*pos;

				//snap to nearest texel
				lightSpacePos.x -= lightSpacePos.x%worldTexelSize; //fmod(lightSpacePos.x, worldTexelSize);
				lightSpacePos.y -= lightSpacePos.y%worldTexelSize; //fmod(lightSpacePos.y, worldTexelSize);

				//convert back to world space
				pos = q*lightSpacePos;
			}
				// Spotlight
			else if ( light.Type == LightType.Spotlight )
			{
				// Set perspective projection
				textureCamera.ProjectionType = Projection.Perspective;
				// set FOV slightly larger than the spotlight range to ensure coverage
				var fovy = light.SpotlightOuterAngle*1.2;

				// limit angle
				if ( fovy.InDegrees > 175 )
				{
					fovy = (Degree)( 175 );
				}
				textureCamera.FieldOfView = fovy;

				// Calculate position, which same as spotlight position
				pos = light.GetDerivedPosition();

				// Calculate direction, which same as spotlight direction
//.........这里部分代码省略.........
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:101,代码来源:DefaultShadowCameraSetup.cs

示例2: RenderCompositeMap

        /// <summary>
        /// Helper method to render a composite map.
        /// </summary>
        /// <param name="size"> The requested composite map size</param>
        /// <param name="rect"> The region of the composite map to update, in image space</param>
        /// <param name="mat">The material to use to render the map</param>
        /// <param name="destCompositeMap"></param>
        public virtual void RenderCompositeMap(int size, Rectangle rect,
            Material mat, Texture destCompositeMap)
        {
            //return;
            if (mCompositeMapSM == null)
            {
                //dedicated SceneManager

                mCompositeMapSM = Root.Instance.CreateSceneManager(SceneType.ExteriorClose, "TerrainMaterialGenerator_SceneManager");
                float camDist = 100;
                float halfCamDist = camDist * 0.5f;
                mCompositeMapCam = mCompositeMapSM.CreateCamera("TerrainMaterialGenerator_Camera");
                mCompositeMapCam.Position = new Vector3(0, 0, camDist);
                //mCompositeMapCam.LookAt(Vector3.Zero);
                mCompositeMapCam.ProjectionType = Projection.Orthographic;
                mCompositeMapCam.Near = 10;
                mCompositeMapCam.Far = 999999* 3;
                //mCompositeMapCam.AspectRatio = camDist / camDist;
                mCompositeMapCam.SetOrthoWindow(camDist, camDist);
                // Just in case material relies on light auto params
                mCompositeMapLight = mCompositeMapSM.CreateLight("TerrainMaterialGenerator_Light");
                mCompositeMapLight.Type = LightType.Directional;

                RenderSystem rSys = Root.Instance.RenderSystem;
                float hOffset = rSys.HorizontalTexelOffset / (float)size;
                float vOffset = rSys.VerticalTexelOffset / (float)size;

                //setup scene
                mCompositeMapPlane = mCompositeMapSM.CreateManualObject("TerrainMaterialGenerator_ManualObject");
                mCompositeMapPlane.Begin(mat.Name, OperationType.TriangleList);
                mCompositeMapPlane.Position(-halfCamDist, halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(0 - hOffset, 0 - vOffset);
                mCompositeMapPlane.Position(-halfCamDist, -halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(0 - hOffset, 1 - vOffset);
                mCompositeMapPlane.Position(halfCamDist, -halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(1 - hOffset, 1 - vOffset);
                mCompositeMapPlane.Position(halfCamDist, halfCamDist, 0);
                mCompositeMapPlane.TextureCoord(1 - hOffset, 0 - vOffset);
                mCompositeMapPlane.Quad(0, 1, 2, 3);
                mCompositeMapPlane.End();
                mCompositeMapSM.RootSceneNode.AttachObject(mCompositeMapPlane);
            }//end if

            // update
            mCompositeMapPlane.SetMaterialName(0, mat.Name);
            mCompositeMapLight.Direction = TerrainGlobalOptions.LightMapDirection;
            mCompositeMapLight.Diffuse = TerrainGlobalOptions.CompositeMapDiffuse;
            mCompositeMapSM.AmbientLight =TerrainGlobalOptions.CompositeMapAmbient;
            

            //check for size change (allow smaller to be reused)
            if (mCompositeMapRTT != null && size != mCompositeMapRTT.Width)
            {
                TextureManager.Instance.Remove(mCompositeMapRTT);
                mCompositeMapRTT = null;
            }
            if (mCompositeMapRTT == null)
            {
                mCompositeMapRTT = TextureManager.Instance.CreateManual(
                    mCompositeMapSM.Name + "/compRTT",
                    ResourceGroupManager.DefaultResourceGroupName,
                    TextureType.TwoD,
                    size,
                    size,
                    0,
                    PixelFormat.BYTE_RGBA,
                    TextureUsage.RenderTarget);

                RenderTarget rtt = mCompositeMapRTT.GetBuffer().GetRenderTarget();
                // don't render all the time, only on demand
                rtt.IsAutoUpdated = false;
                Viewport vp = rtt.AddViewport(mCompositeMapCam);
                // don't render overlays
                vp.ShowOverlays = false;
            }

            // calculate the area we need to update
            float vpleft = (float)rect.Left / (float)size;
            float vptop = (float)rect.Top / (float)size;
            float vpright = (float)rect.Right / (float)size;
            float vpbottom = (float)rect.Bottom / (float)size;
            float vpwidth = (float)rect.Width / (float)size;
            float vpheight = (float)rect.Height / (float)size;

            RenderTarget rtt2 = mCompositeMapRTT.GetBuffer().GetRenderTarget();
            Viewport vp2 = rtt2.GetViewport(0);
            mCompositeMapCam.SetWindow(vpleft, vptop, vpright, vpbottom);
            rtt2.Update();
            vp2.Update();
            // We have an RTT, we want to copy the results into a regular texture
            // That's because in non-update scenarios we don't want to keep an RTT
            // around. We use a single RTT to serve all terrain pages which is more
            // efficient.
//.........这里部分代码省略.........
开发者ID:WolfgangSt,项目名称:axiom,代码行数:101,代码来源:TerrainMaterialGenerator.cs


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