public void Rotate(float angle) { Control = s.Matrix3x2.Multiply( s.Matrix3x2.Rotation(angle), // premultiply Control); }
public void RotateAt(float angle, float centerX, float centerY) { angle = Conversions.DegreesToRadians(angle); var sina = (float)Math.Sin(angle); var cosa = (float)Math.Cos(angle); var matrix = new s.Matrix3x2(cosa, sina, -sina, cosa, centerX - centerX * cosa + centerY * sina, centerY - centerX * sina - centerY * cosa); Control = s.Matrix3x2.Multiply(matrix, Control); }
public Matrix3x3(Matrix3x2 Other) { M00 = Other.M11; M01 = Other.M12; M02 = 0; M10 = Other.M21; M11 = Other.M22; M12 = 0; M20 = Other.M31; M21 = Other.M32; M22 = 1; }
public static void Invert(ref Matrix3x2 matrix, out Matrix3x2 result) { float determinant = matrix.Determinant(); if (MathUtil.WithinEpsilon(determinant, 0.0f)) { result = Matrix3x2.Identity; return; } float invdet = 1.0f / determinant; float _offsetX = matrix.M31; float _offsetY = matrix.M32; result = new Matrix3x2( matrix.M22 * invdet, -matrix.M12 * invdet, -matrix.M21 * invdet, matrix.M11 * invdet, (matrix.M21 * _offsetY - _offsetX * matrix.M22) * invdet, (_offsetX * matrix.M12 - matrix.M11 * _offsetY) * invdet); }
public Result DrawGlyphRun(object clientDrawingContext, float baselineOriginX, float baselineOriginY, MeasuringMode measuringMode, GlyphRun glyphRun, GlyphRunDescription glyphRunDescription, ComObject clientDrawingEffect) { var pathGeometry = new PathGeometry(_d2DFactory); var geometrySink = pathGeometry.Open(); var fontFace = glyphRun.FontFace; if (glyphRun.Indices.Length > 0) fontFace.GetGlyphRunOutline(glyphRun.FontSize, glyphRun.Indices, glyphRun.Advances, glyphRun.Offsets, glyphRun.IsSideways, glyphRun.BidiLevel % 2 != 0, geometrySink); geometrySink.Close(); geometrySink.Dispose(); fontFace.Dispose(); var matrix = new Matrix3x2() { M11 = 1, M12 = 0, M21 = 0, M22 = 1, M31 = baselineOriginX, M32 = baselineOriginY }; var transformedGeometry = new TransformedGeometry(_d2DFactory, pathGeometry, matrix); var brushColor = (Color4)Color.Black; if (clientDrawingEffect != null && clientDrawingEffect is ColorDrawingEffect) brushColor = (clientDrawingEffect as ColorDrawingEffect).Color; var brush = new SolidColorBrush(_renderTarget, brushColor); _renderTarget.DrawGeometry(transformedGeometry, brush); _renderTarget.FillGeometry(transformedGeometry, brush); pathGeometry.Dispose(); transformedGeometry.Dispose(); brush.Dispose(); return SharpDX.Result.Ok; }
/// <summary> /// 计算转换矩阵。 /// </summary> private void CalculateMatrix() { matrix = new Matrix3x2(1, 0, 0, 1, -shape.Center.X, -shape.Center.Y); if (rotate != 0) { matrix *= Matrix3x2.Rotation(this.rotateRadian); } if (this.scale != 1) { matrix *= Matrix3x2.Scaling(scale); } matrix *= Matrix3x2.Translation(offset.X + scale * shape.Center.X, offset.Y + scale * shape.Center.Y); }
public void Append(IMatrix matrix) { Control = s.Matrix3x2.Multiply(this.Control, matrix.ToDx()); }
public void ScaleAt(float scaleX, float scaleY, float centerX, float centerY) { var matrix = new s.Matrix3x2(scaleX, 0f, 0f, scaleY, centerX - centerX * scaleX, centerY - centerY * scaleY); Control = s.Matrix3x2.Multiply(matrix, Control); }
public void Scale(float sx, float sy) { Control = s.Matrix3x2.Multiply(s.Matrix3x2.Scaling(sx, sy), Control); // premultiply }
public MatrixHandler(ref s.Matrix3x2 m) { this.Control = m; // copied the value as Control is a struct }
public void Invert() { this.Control = s.Matrix3x2.Invert(this.Control); }
/// <summary> /// Creates a matrix that rotates about a specified center. /// </summary> /// <param name="angle">Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.</param> /// <param name="center">The center of the rotation.</param> /// <param name="result">When the method completes, contains the created rotation matrix.</param> public static void Rotation(float angle, Vector2 center, out Matrix3x2 result) { result = Translation(-center) * Rotation(angle) * Translation(center); }
/// <summary> /// Creates a matrix that rotates. /// </summary> /// <param name="angle">Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.</param> /// <param name="result">When the method completes, contains the created rotation matrix.</param> public static void Rotation(float angle, out Matrix3x2 result) { float cos = (float)Math.Cos(angle); float sin = (float)Math.Sin(angle); result = Matrix3x2.Identity; result.M11 = cos; result.M12 = sin; result.M21 = -sin; result.M22 = cos; }
/// <summary> /// Creates a matrix that is scaling from a specified center. /// </summary> /// <param name="x">Scaling factor that is applied along the x-axis.</param> /// <param name="y">Scaling factor that is applied along the y-axis.</param> /// <param name="center">The center of the scaling.</param> /// <param name="result">The created scaling matrix.</param> public static void Scaling( float x, float y, ref Vector2 center, out Matrix3x2 result) { Matrix3x2 localResult; localResult.M11 = x; localResult.M12 = 0.0f; localResult.M21 = 0.0f; localResult.M22 = y; localResult.M31 = center.X - (x * center.X); localResult.M32 = center.Y - (y * center.Y); result = localResult; }
/// <summary> /// Creates a transformation matrix. /// </summary> /// <param name="xScale">Scaling factor that is applied along the x-axis.</param> /// <param name="yScale">Scaling factor that is applied along the y-axis.</param> /// <param name="angle">Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis.</param> /// <param name="xOffset">X-coordinate offset.</param> /// <param name="yOffset">Y-coordinate offset.</param> /// <param name="result">When the method completes, contains the created transformation matrix.</param> public static void Transformation(float xScale, float yScale, float angle, float xOffset, float yOffset, out Matrix3x2 result) { result = Scaling(xScale, yScale) * Rotation(angle) * Translation(xOffset, yOffset); }
public void Create() { this.Control = s.Matrix3x2.Identity; }
/// <summary> /// Creates a translation matrix using the specified offsets. /// </summary> /// <param name="value">The offset for both coordinate planes.</param> /// <param name="result">When the method completes, contains the created translation matrix.</param> public static void Translation(ref Vector2 value, out Matrix3x2 result) { Translation(value.X, value.Y, out result); }
public MatrixHandler() { this.Control = s.Matrix3x2.Identity; }
/// <summary> /// Creates a translation matrix using the specified offsets. /// </summary> /// <param name="x">X-coordinate offset.</param> /// <param name="y">Y-coordinate offset.</param> /// <param name="result">When the method completes, contains the created translation matrix.</param> public static void Translation(float x, float y, out Matrix3x2 result) { result = Matrix3x2.Identity; result.M31 = x; result.M32 = y; }
public void Rotate(float angle) { Control = s.Matrix3x2.Multiply(s.Matrix3x2.Rotation(Conversions.DegreesToRadians(angle)), Control); // premultiply }
/// <summary> /// Transforms a vector by this matrix. /// </summary> /// <param name="matrix">The matrix to use as a transformation matrix.</param> /// <param name="point">The original vector to apply the transformation.</param> /// <returns>The result of the transformation for the input vector.</returns> public static Vector2 TransformPoint(Matrix3x2 matrix, Vector2 point) { Vector2 result; result.X = (point.X * matrix.M11) + (point.Y * matrix.M21) + matrix.M31; result.Y = (point.X * matrix.M12) + (point.Y * matrix.M22) + matrix.M32; return result; }
public void Translate(float x, float y) { Control = s.Matrix3x2.Multiply(s.Matrix3x2.Translation(x, y), Control); // premultiply }
/// <summary> /// Transforms a vector by this matrix. /// </summary> /// <param name="matrix">The matrix to use as a transformation matrix.</param> /// <param name="point">The original vector to apply the transformation.</param> /// <param name="result">The result of the transformation for the input vector.</param> /// <returns></returns> public static void TransformPoint(ref Matrix3x2 matrix, ref Vector2 point, out Vector2 result) { Vector2 localResult; localResult.X = (point.X * matrix.M11) + (point.Y * matrix.M21) + matrix.M31; localResult.Y = (point.X * matrix.M12) + (point.Y * matrix.M22) + matrix.M32; result = localResult; }
public void Skew(float skewX, float skewY) { var matrix = new s.Matrix3x2(1, (float)Math.Tan(Conversions.DegreesToRadians(skewX)), (float)Math.Tan(Conversions.DegreesToRadians(skewY)), 1, 0, 0); Control = s.Matrix3x2.Multiply(matrix, Control); }
/// <summary> /// Calculates the inverse of the specified matrix. /// </summary> /// <param name="value">The matrix whose inverse is to be calculated.</param> /// <returns>the inverse of the specified matrix.</returns> public static Matrix3x2 Invert(Matrix3x2 value) { Matrix3x2 result; Invert(ref value, out result); return result; }
public void Prepend(IMatrix matrix) { Control = s.Matrix3x2.Multiply(matrix.ToDx(), this.Control); }
/// <summary> /// Creates a skew matrix. /// </summary> /// <param name="angleX">Angle of skew along the X-axis in radians.</param> /// <param name="angleY">Angle of skew along the Y-axis in radians.</param> /// <param name="result">When the method completes, contains the created skew matrix.</param> public static void Skew(float angleX, float angleY, out Matrix3x2 result) { result = Matrix.Identity; result.M12 = (float) Math.Tan(angleX); result.M21 = (float) Math.Tan(angleY); }
public void Create(float m11, float m12, float m21, float m22, float dx, float dy) { this.Control = new s.Matrix3x2(m11, m12, m21, m22, dx, dy); }
/// <summary> /// Calculates the inverse of the specified matrix. /// </summary> /// <param name="value">The matrix whose inverse is to be calculated.</param> /// <param name="result">When the method completes, contains the inverse of the specified matrix.</param> public static void Invert(ref Matrix3x2 value, out Matrix3x2 result) { float determinant = value.Determinant(); if (MathUtil.WithinEpsilon(determinant, 0.0f)) { result = Identity; return; } float invdet = 1.0f / determinant; float _offsetX = value.M31; float _offsetY = value.M32; result = new Matrix3x2( value.M22 * invdet, -value.M12 * invdet, -value.M21 * invdet, value.M11 * invdet, (value.M21 * _offsetY - _offsetX * value.M22) * invdet, (_offsetX * value.M12 - value.M11 * _offsetY) * invdet); }
public void Transform(Transform transform) { var currentTx = renderTarget.Transform; var tx = new Matrix3x2 ( (float)transform.A, (float)transform.B, (float)transform.C, (float)transform.D, (float)transform.E, (float)transform.F); renderTarget.Transform = tx * currentTx; }
public Transform(SharpDX.Matrix3x2 pMatrix) { Matrix = pMatrix; }