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


C# ICamera.GetCameraMatrix方法代码示例

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


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

示例1: ProjectFromCoordinate

		//also used by Camera2D
		internal static void ProjectFromCoordinate(ICamera camera, bool is2D, ref Vector2 screenPosition, float projectDepth, out Vector3 position, ref Vector2 targetSize)
		{
			Vector4 coordinate = new Vector4(0, 0, 0.5f, 1);
			if (targetSize.X != 0)
				coordinate.X = ((screenPosition.X / targetSize.X) - 0.5f) * 2;
			if (targetSize.Y != 0)
				coordinate.Y = ((screenPosition.Y / targetSize.Y) - 0.5f) * 2;

			//this is much slower for 3D Cameras than 2D, due to matrix inversion requirements.
			Matrix mat;

			if (is2D)
			{
				//projection is always identity, so only need the inverse of the view matrix...
				//which is the camera matrix
				camera.GetCameraMatrix(out mat);
			}
			else
			{
				//more complex.
				Matrix pm;
				camera.GetProjectionMatrix(out pm, ref targetSize);
				camera.GetViewMatrix(out mat);

				// OUCH
				Matrix.Multiply(ref mat, ref pm, out mat); 
				Matrix.Invert(ref mat, out mat); 
			}

			Vector4.Transform(ref coordinate, ref mat, out coordinate);

			if (coordinate.W != 0)
			{
				coordinate.W = 1.0f / coordinate.W;
				coordinate.X *= coordinate.W;
				coordinate.Y *= coordinate.W;
				coordinate.Z *= coordinate.W;
				coordinate.W = 1;
			}

			//this could probably be done better...
			Vector3 cameraPos;
			camera.GetCameraPosition(out cameraPos);

			Vector3 difference = new Vector3();
			difference.X = coordinate.X - cameraPos.X;
			difference.Y = coordinate.Y - cameraPos.Y;
			difference.Z = coordinate.Z - cameraPos.Z;

			if (difference.X != 0 || difference.Y != 0 || difference.Y != 0)
				difference.Normalize();

			difference.X *= projectDepth;
			difference.Y *= projectDepth;
			difference.Z *= projectDepth;

			position = new Vector3();
			position.X = difference.X + cameraPos.X;
			position.Y = difference.Y + cameraPos.Y;
			position.Z = difference.Z + cameraPos.Z;
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:62,代码来源:Camera3D.cs

示例2: BeginRepeat

		/// <summary></summary>
		/// <param name="state"></param>
		/// <param name="repeat"></param>
		/// <param name="camera"></param>
		/// <returns></returns>
		internal override bool BeginRepeat(DrawState state, int repeat, ref ICamera camera)
		{
			if (isDisposed)
				throw new ObjectDisposedException("this");

			GraphicsDevice device = state.graphics;

			if (!facesEnabled[repeat])
				return false;

#if XBOX360
			state.nonScreenRenderComplete = true;
#endif

			if (repeat == minFaceEnabled)
			{
				if (texture == null)
				{
					Warm(state);
				}

				if (texture.IsDisposed)
					throw new ObjectDisposedException("RenderTexture");

				state.shaderSystem.ResetTextures();
			}

			device.SetRenderTarget(texture, (CubeMapFace)repeat);

			if (cubeCamera == null)
				cubeCamera = new Camera3D(new Projection(MathHelper.PiOver2,1,100,1));

			if (repeat == minFaceEnabled)
			{
				camera.GetCameraMatrix(out cubeCameraMatrix);

				if (camera is Camera3D)
				{
					this.cubeCamera.Projection.NearClip = ((Camera3D)camera).Projection.NearClip;
					this.cubeCamera.Projection.FarClip = ((Camera3D)camera).Projection.FarClip;
					this.cubeCamera.Projection.UseLeftHandedProjection = true;// ((Camera3D)camera).Projection.UseLeftHandedProjection;
					this.cubeCamera.ReverseBackfaceCulling = true;
				}
				else
				{
					this.cubeCamera.Projection.NearClip = 1;
					this.cubeCamera.Projection.FarClip = 100;
					this.cubeCamera.Projection.UseLeftHandedProjection = false;
				}
			}

			Matrix view;
			Matrix.Multiply(ref CubeMapFaceMatrices[repeat], ref cubeCameraMatrix, out view);
			this.cubeCamera.SetCameraMatrix(ref view);

			camera = this.cubeCamera;
			return true;
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:63,代码来源:DrawTarget.cs

示例3: ProjectFromCoordinate

        internal static void ProjectFromCoordinate(ICamera camera, bool is2D, ref Vector2 screenPosition, float projectDepth, out Vector3 position, ref Vector2 targetSize)
        {
            Vector4 coordinate = new Vector4(0, 0, 0.5f, 1);
            if (targetSize.X != 0)
                coordinate.X = ((screenPosition.X / targetSize.X) - 0.5f) * 2;
            if (targetSize.Y != 0)
                coordinate.Y = ((screenPosition.Y / targetSize.Y) - 0.5f) * 2;

            Matrix mat;

            if (is2D)
            {
                camera.GetCameraMatrix(out mat);
            }
            else
            {
                Matrix pm;
                camera.GetProjectionMatrix(out pm, ref targetSize);
                camera.GetViewMatrix(out mat);

                Matrix.Multiply(ref mat, ref pm, out mat);
                Matrix.Invert(ref mat, out mat);
            }

            Vector4.Transform(ref coordinate, ref mat, out coordinate);

            if (coordinate.W != 0)
            {
                coordinate.W = 1.0f / coordinate.W;
                coordinate.X *= coordinate.W;
                coordinate.Y *= coordinate.W;
                coordinate.Z *= coordinate.W;
                coordinate.W = 1;
            }

            Vector3 cameraPos;
            camera.GetCameraPosition(out cameraPos);

            Vector3 difference = new Vector3();
            difference.X = coordinate.X - cameraPos.X;
            difference.Y = coordinate.Y - cameraPos.Y;
            difference.Z = coordinate.Z - cameraPos.Z;

            if (difference.X != 0 || difference.Y != 0 || difference.Y != 0)
                difference.Normalize();

            difference.X *= projectDepth;
            difference.Y *= projectDepth;
            difference.Z *= projectDepth;

            position = new Vector3();
            position.X = difference.X + cameraPos.X;
            position.Y = difference.Y + cameraPos.Y;
            position.Z = difference.Z + cameraPos.Z;
        }
开发者ID:TormentedEmu,项目名称:OpenUO,代码行数:55,代码来源:Camera3D.cs


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