Microsoft.Xna.Framework.Matrix.CreateTranslation C# (CSharp) Method

CreateTranslation() public static method

public static CreateTranslation ( Vector3 position ) : Matrix
position Vector3
return Matrix
        public static Matrix CreateTranslation(Vector3 position)
        {
            Matrix result;
            result.M11 = 1f;
            result.M12 = 0f;
            result.M13 = 0f;
            result.M14 = 0f;
            result.M21 = 0f;
            result.M22 = 1f;
            result.M23 = 0f;
            result.M24 = 0f;
            result.M31 = 0f;
            result.M32 = 0f;
            result.M33 = 1f;
            result.M34 = 0f;
            result.M41 = position.X;
            result.M42 = position.Y;
            result.M43 = position.Z;
            result.M44 = 1f;
            return result;
        }

Usage Example

        private void Transform(AstroObject astroObject, Matrix3D baseTransformation, FrameworkElement txt)
        {
            // Transform Model
            if (astroObject == null)
            {
                return;
            }
            var m = Matrix.Identity;

            m *= Matrix.CreateTranslation(0, 60, 0);
            m *= Matrix.CreateRotationX(Microsoft.Xna.Framework.MathHelper.ToRadians(90));
            m *= baseTransformation.ToXnaMatrix();
            astroObject.Transform = m;
            astroObject.IsVisible = true;

            // Transform FrameworkElement
            // Center at origin of the TextBlock
            var centerAtOrigin = Matrix3DFactory.CreateTranslation(-txt.ActualWidth * 0.5, -txt.ActualHeight * 0.5, 0);
            // Swap the y-axis
            var scale = Matrix3DFactory.CreateScale(1, -1, 1);
            // Move a bit away from the center
            var translation = Matrix3DFactory.CreateTranslation(0, 50, 0);
            // Calculate the complete transformation matrix based on the first detection result
            var world = centerAtOrigin * translation * scale * baseTransformation;

            // Calculate the final transformation matrix by using the camera projection matrix
            var vp = Matrix3DFactory.CreateViewportTransformation(Viewport.ActualWidth, Viewport.ActualHeight);
            var mp = Matrix3DFactory.CreateViewportProjection(world, Matrix3D.Identity, arDetector.Projection, vp);

            // Apply the final transformation matrix to the TextBox
            txt.Projection = new Matrix3DProjection {
                ProjectionMatrix = mp
            };
            txt.Visibility = Visibility.Visible;
        }
All Usage Examples Of Microsoft.Xna.Framework.Matrix::CreateTranslation