/// <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;
		}
		//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;
		}
Exemple #3
0
        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;
        }
Exemple #4
0
        //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;
        }
Exemple #5
0
        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;
        }