|
|
|
|
|
|
return m; |
|
|
|
} |
|
|
|
|
|
|
|
public static Matrix3 makeRotate(float degree) |
|
|
|
{ |
|
|
|
var m = new Matrix3(); |
|
|
|
m.setRotate(degree); |
|
|
|
return m; |
|
|
|
} |
|
|
|
|
|
|
|
public static Matrix3 makeTrans(Vector2 vector) |
|
|
|
{ |
|
|
|
return makeTrans((float) vector.x, (float) vector.y); |
|
|
|
} |
|
|
|
|
|
|
|
public static Matrix3 makeAll( |
|
|
|
float scaleX, float skewX, float transX, |
|
|
|
float skewY, float scaleY, float transY, |
|
|
|
|
|
|
public void copyFrom(Matrix3 other) { |
|
|
|
Array.Copy(other.fMat, this.fMat, 9); |
|
|
|
this.fTypeMask = other.fTypeMask; |
|
|
|
} |
|
|
|
|
|
|
|
public Matrix3 Value |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
var m = new Matrix3(); |
|
|
|
m.copyFrom(this); |
|
|
|
return m; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Flags] |
|
|
|
|
|
|
return !(a == b); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Matrix3 _identity = null; |
|
|
|
|
|
|
|
public static Matrix3 identity |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
if (_identity != null) return _identity; |
|
|
|
_identity = new Matrix3(); |
|
|
|
_identity.reset(); |
|
|
|
return _identity; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static Matrix3 operator *(Matrix3 a, Matrix3 b) |
|
|
|
{ |
|
|
|
return concat(a, b); |
|
|
|
} |
|
|
|
|
|
|
|
public Offset getAsTranslation() |
|
|
|
{ |
|
|
|
if (isTranslate()) return new Offset(fMat[kMTransX], fMat[kMTransY]); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
{ |
|
|
|
return "Matrix3(" + string.Join(",", Array.ConvertAll(fMat, i => i.ToString())) + ")"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Rect inverseTransformRect(Rect rect) |
|
|
|
{ |
|
|
|
D.assert(rect != null); |
|
|
|
D.assert(this.determinant != 0.0); |
|
|
|
|
|
|
|
if (this.isIdentity()) { |
|
|
|
return rect; |
|
|
|
} |
|
|
|
|
|
|
|
var inverse = this.inverse; |
|
|
|
return inverse.transformRect(rect); |
|
|
|
|
|
|
|
//var matrix4 = this.toMatrix4x4();
|
|
|
|
//return matrix4.inverseTransformRect(rect);
|
|
|
|
} |
|
|
|
|
|
|
|
public Rect transformRect(Rect rect) |
|
|
|
{ |
|
|
|
//var matrix4 = this.toMatrix4x4();
|
|
|
|
//return matrix4.transformRect(rect);
|
|
|
|
return mapRect(rect); |
|
|
|
} |
|
|
|
|
|
|
|
public float determinant |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
TypeMask mask = this.getType(); |
|
|
|
int isPersp = (int) (mask & TypeMask.kPerspective_Mask); |
|
|
|
double invDet = ScalarUtils.inv_determinant(fMat, isPersp); |
|
|
|
D.assert(invDet != 0); |
|
|
|
return (float)(1.0 / invDet); |
|
|
|
|
|
|
|
//var matrix4 = this.toMatrix4x4();
|
|
|
|
//return matrix4.determinant;
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Matrix3 inverse |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
//return this.toMatrix4x4().inverse.toMatrix3();
|
|
|
|
var m = new Matrix3(); |
|
|
|
var invertable = this.invert(m); |
|
|
|
D.assert(invertable); |
|
|
|
return m; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Offset transformPoint(Offset point) |
|
|
|
{ |
|
|
|
//return this.toMatrix4x4().transformPoint(point);
|
|
|
|
return this.mapXY((float)point.dx, (float)point.dy); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Matrix3 I() { |
|
|
|
var m = new Matrix3(); |
|
|
|
m.reset(); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return hash; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static Matrix3 operator *(Matrix3 a, Matrix3 b) |
|
|
|
{ |
|
|
|
return concat(a, b); |
|
|
|
} |
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
{ |
|
|
|
return "Matrix3(" + string.Join(",", Array.ConvertAll(fMat, i => i.ToString())) + ")"; |
|
|
|
} |
|
|
|
|
|
|
|
public float determinant |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
TypeMask mask = this.getType(); |
|
|
|
int isPersp = (int) (mask & TypeMask.kPerspective_Mask); |
|
|
|
double invDet = ScalarUtils.inv_determinant(fMat, isPersp); |
|
|
|
D.assert(invDet != 0); |
|
|
|
return (float)(1.0 / invDet); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|