// Hack function to do diaonal flip first in transformations static public void TransformPoints_DiagFirst(PointF[] points, PointF origin, bool diagonal, bool horizontal, bool vertical) { // Put the points into origin/local space TranslatePoints(points, -origin.X, -origin.Y); TmxRotationMatrix rotate = new TmxRotationMatrix(); // Apply the flips/rotations (order matters) if (diagonal) { TmxRotationMatrix d = new TmxRotationMatrix(0, 1, 1, 0); rotate = TmxRotationMatrix.Multiply(d, rotate); } if (horizontal) { TmxRotationMatrix h = new TmxRotationMatrix(-1, 0, 0, 1); rotate = TmxRotationMatrix.Multiply(h, rotate); } if (vertical) { TmxRotationMatrix v = new TmxRotationMatrix(1, 0, 0, -1); rotate = TmxRotationMatrix.Multiply(v, rotate); } // Apply the combined flip/rotate transformation rotate.TransformPoints(points); // Put points back into world space TranslatePoints(points, origin.X, origin.Y); }
static public TmxRotationMatrix Multiply(TmxRotationMatrix M1, TmxRotationMatrix M2) { float m00 = M1[0, 0] * M2[0, 0] + M1[0, 1] * M2[1, 0]; float m01 = M1[0, 0] * M2[0, 1] + M1[0, 1] * M2[1, 1]; float m10 = M1[1, 0] * M2[0, 0] + M1[1, 1] * M2[1, 0]; float m11 = M1[1, 0] * M2[0, 1] + M1[1, 1] * M2[1, 1]; return new TmxRotationMatrix(m00, m01, m10, m11); }
static public TmxRotationMatrix Multiply(TmxRotationMatrix M1, TmxRotationMatrix M2) { float m00 = M1[0, 0] * M2[0, 0] + M1[0, 1] * M2[1, 0]; float m01 = M1[0, 0] * M2[0, 1] + M1[0, 1] * M2[1, 1]; float m10 = M1[1, 0] * M2[0, 0] + M1[1, 1] * M2[1, 0]; float m11 = M1[1, 0] * M2[0, 1] + M1[1, 1] * M2[1, 1]; return(new TmxRotationMatrix(m00, m01, m10, m11)); }
public static TmxRotationMatrix Multiply(TmxRotationMatrix M1, TmxRotationMatrix M2) { float m = M1[0, 0] * M2[0, 0] + M1[0, 1] * M2[1, 0]; float m2 = M1[0, 0] * M2[0, 1] + M1[0, 1] * M2[1, 1]; float m3 = M1[1, 0] * M2[0, 0] + M1[1, 1] * M2[1, 0]; float m4 = M1[1, 0] * M2[0, 1] + M1[1, 1] * M2[1, 1]; return(new TmxRotationMatrix(m, m2, m3, m4)); }
static public void RotatePoints(PointF[] points, TmxObject tmxObject) { TranslatePoints(points, -tmxObject.Position.X, -tmxObject.Position.Y); TmxRotationMatrix rotate = new TmxRotationMatrix(-tmxObject.Rotation); rotate.TransformPoints(points); TranslatePoints(points, tmxObject.Position.X, tmxObject.Position.Y); }
public static void TransformPoints_DiagFirst(PointF[] points, PointF origin, bool diagonal, bool horizontal, bool vertical) { TranslatePoints(points, 0f - origin.X, 0f - origin.Y); TmxRotationMatrix tmxRotationMatrix = new TmxRotationMatrix(); if (diagonal) { tmxRotationMatrix = TmxRotationMatrix.Multiply(new TmxRotationMatrix(0f, 1f, 1f, 0f), tmxRotationMatrix); } if (horizontal) { tmxRotationMatrix = TmxRotationMatrix.Multiply(new TmxRotationMatrix(-1f, 0f, 0f, 1f), tmxRotationMatrix); } if (vertical) { tmxRotationMatrix = TmxRotationMatrix.Multiply(new TmxRotationMatrix(1f, 0f, 0f, -1f), tmxRotationMatrix); } tmxRotationMatrix.TransformPoints(points); TranslatePoints(points, origin.X, origin.Y); }