Exemple #1
0
        public bool EqualsAffine(Affine2f affine)
        {
            int count = 0;

            if (affine.m00 == val[M00])
            {
                count++;
            }
            if (affine.m01 == val[M01])
            {
                count++;
            }
            if (affine.m10 == val[M10])
            {
                count++;
            }
            if (affine.m11 == val[M11])
            {
                count++;
            }
            if (affine.tx == val[M03])
            {
                count++;
            }
            if (affine.ty == val[M13])
            {
                count++;
            }
            return(count == 6);
        }
Exemple #2
0
        public Affine2f Concat(Affine2f other)
        {
            float a  = this.m00 * other.m00;
            float b  = 0f;
            float c  = 0f;
            float d  = this.m11 * other.m11;
            float tx = this.tx * other.m00 + other.tx;
            float ty = this.ty * other.m11 + other.ty;

            if (this.m10 != 0f || this.m01 != 0f || other.m10 != 0f || other.m01 != 0f)
            {
                a  += this.m10 * other.m01;
                d  += this.m01 * other.m10;
                b  += this.m00 * other.m10 + this.m10 * other.m11;
                c  += this.m01 * other.m00 + this.m11 * other.m01;
                tx += this.ty * other.m01;
                ty += this.tx * other.m10;
            }

            this.m00 = a;
            this.m01 = b;
            this.m10 = c;
            this.m11 = d;
            this.tx  = tx;
            this.ty  = ty;
            return(this);
        }
Exemple #3
0
        public Matrix4 Mul(Affine2f aff)
        {
            Matrix4 m = new Matrix4();

            m.Set(aff);
            //support.Mul(val, m.val);
            return(this);
        }
Exemple #4
0
        public Vector2f MulSelf(Affine2f mat)
        {
            float nx = this.x * mat.m00 + this.y * mat.m01 + mat.tx;
            float ny = this.x * mat.m10 + this.y * mat.m11 + mat.ty;

            this.x = nx;
            this.y = ny;
            return(this);
        }
Exemple #5
0
        public Matrix4 NewCombine(Affine2f affine)
        {
            float m00 = affine.m00;
            float m10 = affine.m10;
            float m20 = 0;
            float m30 = 0;
            float m01 = affine.m01;
            float m11 = affine.m11;
            float m21 = 0;
            float m31 = 0;
            float m02 = 0;
            float m12 = 0;
            float m22 = 1;
            float m32 = 0;
            float m03 = affine.tx;
            float m13 = affine.ty;
            float m23 = 0;
            float m33 = 1;

            float nm00 = val[M00] * m00 + val[M01] * m10 + val[M02] * m20 + val[M03] * m30;
            float nm01 = val[M00] * m01 + val[M01] * m11 + val[M02] * m21 + val[M03] * m31;
            float nm02 = val[M00] * m02 + val[M01] * m12 + val[M02] * m22 + val[M03] * m32;
            float nm03 = val[M00] * m03 + val[M01] * m13 + val[M02] * m23 + val[M03] * m33;
            float nm10 = val[M10] * m00 + val[M11] * m10 + val[M12] * m20 + val[M13] * m30;
            float nm11 = val[M10] * m01 + val[M11] * m11 + val[M12] * m21 + val[M13] * m31;
            float nm12 = val[M10] * m02 + val[M11] * m12 + val[M12] * m22 + val[M13] * m32;
            float nm13 = val[M10] * m03 + val[M11] * m13 + val[M12] * m23 + val[M13] * m33;
            float nm20 = val[M20] * m00 + val[M21] * m10 + val[M22] * m20 + val[M23] * m30;
            float nm21 = val[M20] * m01 + val[M21] * m11 + val[M22] * m21 + val[M23] * m31;
            float nm22 = val[M20] * m02 + val[M21] * m12 + val[M22] * m22 + val[M23] * m32;
            float nm23 = val[M20] * m03 + val[M21] * m13 + val[M22] * m23 + val[M23] * m33;
            float nm30 = val[M30] * m00 + val[M31] * m10 + val[M32] * m20 + val[M33] * m30;
            float nm31 = val[M30] * m01 + val[M31] * m11 + val[M32] * m21 + val[M33] * m31;
            float nm32 = val[M30] * m02 + val[M31] * m12 + val[M32] * m22 + val[M33] * m32;
            float nm33 = val[M30] * m03 + val[M31] * m13 + val[M32] * m23 + val[M33] * m33;

            Matrix4 m = new Matrix4();

            m.val[M00] = nm00;
            m.val[M10] = nm10;
            m.val[M20] = nm20;
            m.val[M30] = nm30;
            m.val[M01] = nm01;
            m.val[M11] = nm11;
            m.val[M21] = nm21;
            m.val[M31] = nm31;
            m.val[M02] = nm02;
            m.val[M12] = nm12;
            m.val[M22] = nm22;
            m.val[M32] = nm32;
            m.val[M03] = nm03;
            m.val[M13] = nm13;
            m.val[M23] = nm23;
            m.val[M33] = nm33;

            return(m);
        }
Exemple #6
0
 public Affine2f CpyTo(Affine2f other)
 {
     other.m00 = this.m00;
     other.m01 = this.m01;
     other.m10 = this.m10;
     other.m11 = this.m11;
     other.tx  = this.tx;
     other.ty  = this.ty;
     return(this);
 }
Exemple #7
0
 public Matrix4 SetAsAffine(Affine2f affine)
 {
     val[M00] = affine.m00;
     val[M10] = affine.m10;
     val[M01] = affine.m01;
     val[M11] = affine.m11;
     val[M03] = affine.tx;
     val[M13] = affine.ty;
     return(this);
 }
Exemple #8
0
 public Affine2f Cpy(Affine2f other)
 {
     this.m00 = other.m00;
     this.m01 = other.m01;
     this.m10 = other.m10;
     this.m11 = other.m11;
     this.tx  = other.tx;
     this.ty  = other.ty;
     return(this);
 }
Exemple #9
0
 public Affine2f SetThis(Affine2f aff)
 {
     this.m00 = aff.m00;
     this.m11 = aff.m11;
     this.m01 = aff.m01;
     this.m10 = aff.m10;
     this.tx  = aff.tx;
     this.ty  = aff.ty;
     return(this);
 }
Exemple #10
0
 public bool Equals(Affine2f a2f)
 {
     if (a2f == null)
     {
         return(false);
     }
     if (a2f == this)
     {
         return(true);
     }
     return(a2f.m00 == m00 && a2f.m01 == m01 && a2f.tx == tx && a2f.ty == ty && a2f.m10 == m10 && a2f.m11 == m11);
 }
Exemple #11
0
        public Affine2f Lerp(Affine2f other, float t)
        {
            if (Generality() < other.Generality())
            {
                return(other.Lerp(this, -t));
            }

            Affine2f ot = (other is Affine2f) ? (Affine2f)other : new Affine2f(other);

            return(new Affine2f(m00 + t * (ot.m00 - m00), m01 + t * (ot.m01 - m01), m10 + t * (ot.m10 - m10),
                                m11 + t * (ot.m11 - m11), tx + t * (ot.tx - tx), ty + t * (ot.ty - ty)));
        }
Exemple #12
0
        public Affine2f Combined(Affine2f aff)
        {
            float a  = aff.m00 * this.m00 + aff.m01 * this.m10;
            float b  = aff.m00 * this.m11 + aff.m11 * this.m10;
            float tx = aff.m00 * this.m01 + aff.m01 * this.m11;
            float c  = aff.m00 * this.tx + aff.m01 * this.ty + aff.tx;
            float d  = aff.m10 * this.tx + aff.m11 * this.ty + aff.ty;

            this.m00 = a;
            this.m01 = b;
            this.tx  = tx;
            this.m10 = c;
            this.m11 = d;
            return(this);
        }
Exemple #13
0
 public Affine2f PreConcatenate(Affine2f other)
 {
     if (Generality() < other.Generality())
     {
         return(other.Concatenate(this));
     }
     if (other is Affine2f)
     {
         return(Multiply((Affine2f)other, this, new Affine2f()));
     }
     else
     {
         Affine2f oaff = new Affine2f(other);
         return(Multiply(oaff, this, oaff));
     }
 }
Exemple #14
0
        public Matrix3 Set(Affine2f affine)
        {
            float[] val = this.val;

            val[M00] = affine.m00;
            val[M10] = affine.m10;
            val[M20] = 0;
            val[M01] = affine.m01;
            val[M11] = affine.m11;
            val[M21] = 0;
            val[M02] = affine.tx;
            val[M12] = affine.ty;
            val[M22] = 1;

            return(this);
        }
Exemple #15
0
 public override bool Equals(object o)
 {
     if (null == o)
     {
         return(false);
     }
     if (o == this)
     {
         return(true);
     }
     if (o is Affine2f)
     {
         Affine2f a2f = (Affine2f)o;
         if (a2f.m00 == m00 && a2f.m01 == m01 && a2f.tx == tx && a2f.ty == ty && a2f.m10 == m10 && a2f.m11 == m11)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #16
0
 public Matrix4 Set(Affine2f affine)
 {
     val[M00] = affine.m00;
     val[M10] = affine.m10;
     val[M20] = 0;
     val[M30] = 0;
     val[M01] = affine.m01;
     val[M11] = affine.m11;
     val[M21] = 0;
     val[M31] = 0;
     val[M02] = 0;
     val[M12] = 0;
     val[M22] = 1;
     val[M32] = 0;
     val[M03] = affine.tx;
     val[M13] = affine.ty;
     val[M23] = 0;
     val[M33] = 1;
     return(this);
 }
Exemple #17
0
 protected Affine2f(Affine2f other) : this(other.ScaleX(), other.ScaleY(), other.Rotation(), other.Tx(), other.Ty())
 {
 }
Exemple #18
0
 public static Affine2f Multiply(float am00, float am01, float am10, float am11, float atx, float aty,
                                 float bm00, float bm01, float bm10, float bm11, float btx, float bty, Affine2f into)
 {
     into.SetTransform(am00 * bm00 + am10 * bm01, am01 * bm00 + am11 * bm01, am00 * bm10 + am10 * bm11,
                       am01 * bm10 + am11 * bm11, am00 * btx + am10 * bty + atx, am01 * btx + am11 * bty + aty);
     return(into);
 }
Exemple #19
0
        public static Affine2f transform(Affine2f tx, float x, float y, int transform)
        {
            switch (transform)
            {
            case TRANS_ROT90:
            {
                tx.Translate(x, y);
                tx.Rotate(ANGLE_90);
                tx.Translate(-x, -y);
                break;
            }

            case TRANS_ROT180:
            {
                tx.Translate(x, y);
                tx.Rotate(MathUtils.PI);
                tx.Translate(-x, -y);
                break;
            }

            case TRANS_ROT270:
            {
                tx.Translate(x, y);
                tx.Rotate(ANGLE_270);
                tx.Translate(-x, -y);
                break;
            }

            case TRANS_MIRROR:
            {
                tx.Translate(x, y);
                tx.Scale(-1, 1);
                tx.Translate(-x, -y);
                break;
            }

            case TRANS_MIRROR_ROT90:
            {
                tx.Translate(x, y);
                tx.Rotate(ANGLE_90);
                tx.Translate(-x, -y);
                tx.Scale(-1, 1);
                break;
            }

            case TRANS_MIRROR_ROT180:
            {
                tx.Translate(x, y);
                tx.Scale(-1, 1);
                tx.Translate(-x, -y);
                tx.Translate(x, y);
                tx.Rotate(MathUtils.PI);
                tx.Translate(-x, -y);
                break;
            }

            case TRANS_MIRROR_ROT270:
            {
                tx.Translate(x, y);
                tx.Rotate(ANGLE_270);
                tx.Translate(-x, -y);
                tx.Scale(-1, 1);
                break;
            }
            }
            return(tx);
        }
Exemple #20
0
 public static Affine2f Multiply(Affine2f a, Affine2f b, Affine2f into)
 {
     return(Multiply(a.m00, a.m01, a.m10, a.m11, a.tx, a.ty, b.m00, b.m01, b.m10, b.m11, b.tx, b.ty, into));
 }
Exemple #21
0
 public Affine2f Append(Affine2f other)
 {
     return(Append(other.m00, other.m10, other.m01, other.m11, other.tx, other.ty));
 }
Exemple #22
0
 public Affine2f PostConcatenate(Affine2f t)
 {
     return(PostConcatenate(t.m00, t.m01, t.m10, t.m11, t.tx, t.ty));
 }
Exemple #23
0
 public Affine2f Set(Affine2f other)
 {
     return(SetTransform(other.m00, other.m01, other.m10, other.m11, other.tx, other.ty));
 }
Exemple #24
0
 public static Affine2f Multiply(Affine2f a, float m00, float m01, float m10, float m11, float tx, float ty,
                                 Affine2f into)
 {
     return(Multiply(a.m00, a.m01, a.m10, a.m11, a.tx, a.ty, m00, m01, m10, m11, tx, ty, into));
 }
Exemple #25
0
        public static Affine2f Transform(Affine2f tx, float x, float y, int transform, float width, float height)
        {
            switch (transform)
            {
            case TRANS_ROT90:
            {
                float w = x + width / 2;
                float h = y + height / 2;
                tx.Translate(w, h);
                tx.Rotate(ANGLE_90);
                tx.Translate(-w, -h);
                break;
            }

            case TRANS_ROT180:
            {
                float w = x + width / 2;
                float h = y + height / 2;
                tx.Translate(w, h);
                tx.Rotate(MathUtils.PI);
                tx.Translate(-w, -h);
                break;
            }

            case TRANS_ROT270:
            {
                float w = x + width / 2;
                float h = y + height / 2;
                tx.Translate(w, h);
                tx.Rotate(ANGLE_270);
                tx.Translate(-w, -h);
                break;
            }

            case TRANS_MIRROR:
            {
                float w = x + width / 2;
                float h = y + height / 2;
                tx.Translate(w, h);
                tx.Scale(-1, 1);
                tx.Translate(-w, -h);
                break;
            }

            case TRANS_MIRROR_ROT90:
            {
                float w = x + width / 2;
                float h = y + height / 2;
                tx.Translate(w, h);
                tx.Rotate(ANGLE_90);
                tx.Translate(-w, -h);
                tx.Scale(-1, 1);
                break;
            }

            case TRANS_MIRROR_ROT180:
            {
                float w = x + width / 2;
                float h = y + height / 2;
                tx.Translate(w, h);
                tx.Scale(-1, 1);
                tx.Translate(-w, -h);
                w = x + width / 2;
                h = y + height / 2;
                tx.Translate(w, h);
                tx.Rotate(MathUtils.PI);
                tx.Translate(-w, -h);
                break;
            }

            case TRANS_MIRROR_ROT270:
            {
                float w = x + width / 2;
                float h = y + height / 2;
                tx.Translate(w, h);
                tx.Rotate(ANGLE_270);
                tx.Translate(-w, -h);
                tx.Scale(-1, 1);
                break;
            }
            }
            return(tx);
        }
Exemple #26
0
 public static Affine2f Multiply(float m00, float m01, float m10, float m11, float tx, float ty, Affine2f b,
                                 Affine2f into)
 {
     return(Multiply(m00, m01, m10, m11, tx, ty, b.m00, b.m01, b.m10, b.m11, b.tx, b.ty, into));
 }