This do not have complete functionality, Rotate method is not implemented,
but should give you a quick start:
<code>
/// <summary>
/// Stores a 3 row by 3 column matrix representing a geometric transform.
/// Not inheritable.
/// </summary>
public sealed
class AffineMatrix
{
/// <summary>
/// Creates an <code>AffineMatrix</code> with the elements of the identity
matrix.
/// </summary>
public AffineMatrix ( )
: this ( new float [0x6] { 1F, 0F, 0F, 1F, 0F, 0F } )
{
}
/// <summary>
/// Creates an <code>AffineMatrix</code> with the specified elements.
/// </summary>
/// <param name="m11">The value in the first row and first column.</param>
/// <param name="m12">The value in the first row and second
column.</param>
/// <param name="m21">The value in the second row and first
column.</param>
/// <param name="m22">The value in the second row and second
column.</param>
/// <param name="m31">The value in the third row and first column.</param>
/// <param name="m32">The value in the third row and second
column.</param>
public AffineMatrix
( float m11, float m12, float m21, float m22, float m31, float m32 )
: this ( new float [0x6] { m11, m12, m21, m22, m31, m32 } )
{
}
private AffineMatrix ( float [] matrix )
{
this.matrix = matrix;
}
~AffineMatrix ( )
{
matrix = null;
}
#region Internal Members
/// <summary>
/// The six-element array that represent this <code>AffineMatrix</code>.
/// </summary>
internal float [] matrix = null;
#endregion
/// <summary>
/// Gets a six-element array that represent this
<code>AffineMatrix</code>.
/// </summary>
public float [] Elements
{
get
{
return matrix;
}
}
/// <summary>
/// Gets the current translation on the horizontal axis.
/// </summary>
public float OffsetX
{
get
{
return matrix [0x4];
}
}
/// <summary>
/// Gets the current translation on the vertical axis.
/// </summary>
public float OffsetY
{
get
{
return matrix [0x5];
}
}
/// <summary>
/// Gets a value indicating whether this <code>AffineMatrix</code>
/// equals the identity matrix.
/// </summary>
public bool IsIdentity
{
get
{
return 1F == matrix [0x0] && 0F == matrix [0x1]
&& 0F == matrix [0x2] && 1F == matrix [0x3]
&& 0F == matrix [0x4] && 0F == matrix [0x5];
}
}
/// <summary>
/// Resets this <code>AffineMatrix</code> to have the elements of the
identity matrix.
/// </summary>
public void Reset ( )
{
matrix [0x5]
= matrix [0x4]
= matrix [0x2]
= matrix [0x1]
= 0F;
matrix [0x3]
= matrix [0x0]
= 1F;
}
/// <summary>
/// Offsets the coordinates of this <code>AffineMatrix</code>.
/// </summary>
/// <param name="dx">Specifies the horizontal translation.</param>
/// <param name="dy">Specifies the vertical translation.</param>
public void Translate ( float dx, float dy )
{
matrix [0x4] = dx;
matrix [0x5] = dy;
}
/// <summary>
/// Applies a scale vector to this <code>AffineMatrix</code>.
/// </summary>
/// <param name="sx">Specifies the horizontal scale factor.</param>
/// <param name="sy">Specifies the vertical scale factor.</param>
public void Scale ( float sx, float sy )
{
matrix [0x0] = sx;
matrix [0x3] = sy;
}
/// <summary>
/// Applies a rotation to this <code>AffineMatrix</code>.
/// </summary>
/// <param name="sx">Specifies the horizontal scale factor.</param>
/// <param name="sy">Specifies the vertical scale factor.</param>
public void Rotate ( float sx, float sy )
{
/*
Rotations are produced by [cos 0 sin 0 -sin 0 cos 0 0 0], which has the
effect
of rotating the coordinate system axes by an angle 0 counterclockwise.
*/
// matrix [0x0] = sx;
// matrix [0x3] = sy;
throw new System.NotImplementedException();
}
/// <summary>
/// Creates an exact copy of this <code>AffineMatrix</code>.
/// </summary>
/// <returns>An instance copy.</returns>
public AffineMatrix Clone ( )
{
return new AffineMatrix( new float [0x6]
{ matrix [0x0], matrix [0x1]
, matrix [0x2], matrix [0x3]
, matrix [0x4], matrix [0x5] } );
}
}
</code>
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
David Sobey said:
well for example how would i define a matrix data type, and so it is
available to other source files. In C or C++ it's something like
typedef int[][] matrix;
easy as pie. But in C#?
cheers
dave