public Affine() { fMatrix = new XFORM(); // Start out with identity matrix Reset(); }
public GDI32Transform() { fMatrix = new XFORM(); fTransformMatrix = new float3x3(); // Start out with identity matrix SetToIdentity(); }
public XFORM(XFORM a) { eM11 = a.eM11; eM12 = a.eM12; eM21 = a.eM21; eM22 = a.eM22; eDx = a.eDx; eDy = a.eDy; }
// Copy transform if valid public bool SetTransform(XFORM xm) { if (xm.eM11 * xm.eM22 == xm.eM12 * xm.eM21) return false; fMatrix = xm; return true; }
public static void Pack(BufferChunk chunk, XFORM aTrans) { chunk += aTrans.eDx; chunk += aTrans.eDy; chunk += aTrans.eM11; chunk += aTrans.eM12; chunk += aTrans.eM21; chunk += aTrans.eM22; }
// transform = transform * b public bool Combine(XFORM b) { if (b.eM11 * b.eM22 == b.eM12 * b.eM21) return false; XFORM a = new XFORM(fMatrix); // 11 12 11 12 // 21 22 21 22 fMatrix.eM11 = a.eM11 * b.eM11 + a.eM12 * b.eM21; fMatrix.eM12 = a.eM11 * b.eM12 + a.eM12 * b.eM22; fMatrix.eM21 = a.eM21 * b.eM11 + a.eM22 * b.eM21; fMatrix.eM22 = a.eM21 * b.eM12 + a.eM22 * b.eM22; fMatrix.eDx = a.eDx * b.eM11 + a.eDy * b.eM21 + b.eDx; fMatrix.eDy = a.eDx * b.eM12 + a.eDy * b.eM22 + b.eDy; return true; }
// transform = 1 / transform // M = A * x + B // Inv(M) = Inv(A) * x - Inv(A) * B public bool Invert() { float det = fMatrix.eM11 * fMatrix.eM22 - fMatrix.eM21 * fMatrix.eM12; if (det == 0) return false; XFORM old = new XFORM(fMatrix); fMatrix.eM11 = old.eM22 / det; fMatrix.eM12 = -old.eM12 / det; fMatrix.eM21 = -old.eM21 / det; fMatrix.eM22 = old.eM11 / det; fMatrix.eDx = -(fMatrix.eM11 * old.eDx + fMatrix.eM21 * old.eDy); fMatrix.eDy = -(fMatrix.eM12 * old.eDx + fMatrix.eM22 * old.eDy); return true; }
public static extern bool SetWorldTransform([In] SafeHandle hdc, ref TOAPI.Types.XFORM lpXform);
public bool Rotate(float angle, float x0, float y0) { float3 unity = new float3(new float2(x0, y0)); unity.Unit(); fTransformMatrix = float3x3.Rotate(angle, unity); XFORM xm = new XFORM(); Translate(-x0, -y0); // make (x0,y0) the origin double rad = angle * (Math.PI / 180); xm.eM11 = (float)Math.Cos(rad); xm.eM12 = (float)Math.Sin(rad); xm.eM21 = -xm.eM12; xm.eM22 = xm.eM11; xm.eDx = 0; xm.eDy = 0; Combine(xm); // rotate Translate(x0, y0); // move origin back return true; }
void Pack(BufferChunk chunk, XFORM aTrans) { //chunk += aTrans.eDx; //chunk += aTrans.eDy; //chunk += aTrans.eM11; //chunk += aTrans.eM12; //chunk += aTrans.eM21; //chunk += aTrans.eM22; }
public bool Rotate(float angle, float x0, float y0) { XFORM xm = new XFORM(); Translate(-x0, -y0); // make (x0,y0) the origin double rad = angle * (3.14159265359 / 180); xm.eM11 = (float)Math.Cos(rad); xm.eM12 = (float)Math.Sin(rad); xm.eM21 = -xm.eM12; xm.eM22 = xm.eM11; xm.eDx = 0; xm.eDy = 0; Combine(xm); // rotate Translate(x0, y0); // move origin back return true; }
private Transform2D GetWorldTransform() { XFORM aTransform = new XFORM(); bool result = GDI32.GetWorldTransform(this, out aTransform); Transform2D trans = new Transform2D(); trans.SetTransform(aTransform); return trans; }
private bool SetWorldTransform(XFORM aTransform) { bool result = GDI32.SetWorldTransform(HDC, ref aTransform); return result; }
private XFORM GetWorldTransform() { XFORM aTransform = new XFORM(); bool result = GDI32.GetWorldTransform(HDC, out aTransform); return aTransform; }
static extern bool ModifyWorldTransform([In] SafeHandle hdc, [In] TOAPI.Types.XFORM lpXform, uint iMode);
//public XFORM WorldTransform //{ // get { return GetWorldTransform(); } // set { SetWorldTransform(value); } //} //private XFORM GetWorldTransform() //{ // XFORM aTransform = new XFORM(); // bool result = GDI32.GetWorldTransform(DeviceContext, out aTransform); // return aTransform; //} public override void SetWorldTransform(XFORM aTransform) { BufferChunk chunk = new BufferChunk(1024); chunk += GDI32.EMR_SETWORLDTRANSFORM; Pack(chunk, aTransform); PackCommand(chunk); }
public static extern bool GetWorldTransform([In] SafeHandle hdc, [Out] out TOAPI.Types.XFORM lpXform);