Class Matrix2

3DS Max Plug-In SDK

Class Matrix2

See Also: Class Point2, Class Point3, Class Matrix3.

class Matrix2

Description:

This class defines a 3x2 2D transformation matrix. Methods are provided to zero the matrix, set it to the identity matrix, translate, rotate and scale it, and compute its inverse. Operators are available for matrix addition, subtraction and multiplication. All methods of this class are implemented by the system.

Data Members:

public:

float m[3][2];

Methods:

Prototype:

Matrix2()

Remarks:

Constructor. No initialization is done in this constructor. Use Zero() or IdentityMatrix() to initialize the matrix.

Prototype:

Matrix2(float (*fp)[2]);

Remarks:

Constructor. The matrix is initialized using fp.

Operators:

Prototype:

Matrix2& operator-=( const Matrix2& M);

Remarks:

Subtracts a Matrix2 from this Matrix2.

Prototype:

Matrix2& operator+=( const Matrix2& M);

Remarks:

Adds a Matrix2 to this Matrix2.

Prototype:

Matrix2& operator*=( const Matrix2& M);

Remarks:

Matrix multiplication between this Matrix2 and M.

Prototype:

operator float*()

Remarks:

Returns the address of the Matrix2.

Prototype:

void IdentityMatrix();

Remarks:

Sets this Matrix2 to the Identity Matrix.

Prototype:

void Zero();

Remarks:

Set all elements of this Matrix2 to 0.0f

Prototype:

Point2 GetRow(int i) const;

Remarks:

Returns the specified row of this matrix.

Parameters:

int i

Specifies the row to retrieve (0-2).

Prototype:

void SetRow(int i, Point2 p);

Remarks:

Sets the specified row of this matrix.

Parameters:

int i

Specifies the row to set (0-2).

Point2 p

The values to set.

Prototype:

Point3 GetColumn(int i);

Remarks:

Returns the specified column of this matrix.

Parameters:

int i

Specifies the column to retrieve (0 or 1).

Prototype:

void SetColumn(int i, Point3 col);

Remarks:

Sets the specified column of this matrix.

Parameters:

int i

Specifies the column to set (0 or 1).

Point3 col

The values to set.

Prototype:

Point2 GetColumn2(int i);

Remarks:

This method returns a Point2 containing the upper two rows of the specified column.

Parameters:

int i

Specifies the column to get (0 or 1).

Prototype:

void SetTrans(const Point2 p);

Remarks:

Sets the translation row of the matrix to the specified values.

Parameters:

const Point2 p

The values to set.

Prototype:

void SetTrans(int i, float v);

Remarks:

Sets the specified element of the translation row of this matrix to the specified value.

Parameters:

int i

Specifies which column to set (0 or 1)

float v

The value to store.

Prototype:

Point2 GetTrans();

Remarks:

Returns the translation row of this matrix.

Prototype:

void SetTranslate(const Point2& s);

Remarks:

This method is available in release 3.0 and later only.

Initializes the matrix to the identity then sets the translation row to the specified values.

Parameters:

const Point2& s

The values to store.

Prototype:

void SetRotate(float angle);

Remarks:

This method is available in release 3.0 and later only.

Initializes the matrix to the identity then sets the rotation to the specified value.

Parameters:

float angle

The rotation angle in radians.

Prototype:

void Invert();

Remarks:

This method is available in release 3.0 and later only.

This matrix may be used to invert the matrix in place.

Prototype:

void Translate(const Point2& p);

Remarks:

Apply an incremental translation to this matrix.

Parameters:

const Point2& p

Specifies the amount to translate the matrix.

Prototype:

void Rotate(float angle);

Remarks:

Apply an incremental rotation to this matrix using the specified angle.

Parameters:

float angle

Specifies the angle of rotation.

Prototype:

void Scale(const Point2& s, BOOL trans);

Remarks:

Apply an incremental scaling to this matrix using the specified scale factors.

Parameters:

const Point2& s

The scale factors.

BOOL trans = FALSE

If set to TRUE, the translation component is scaled. If trans = FALSE the translation component is unaffected. When 3ds max was originally written there was a bug in the code for this method where the translation portion of the matrix was not being scaled. This meant that when a matrix was scaled the bottom row was not scaled. Thus it would always scale about the local origin of the object, but it would scale the world axes. When this bug was discovered, dependencies existed in the code upon this bug. Thus it could not simply be fixed because it would break the existing code that depended upon it working the incorrect way. To correct this the trans parameter was added. If this is set to TRUE, the translation component will be scaled correctly. The existing plug-ins don't use this parameter, it defaults to FALSE, and the code behaves the old way.

Prototype:

Matrix2 operator*(const Matrix2& B) const;

Remarks:

Perform matrix multiplication.

Prototype:

Matrix2 operator+(const Matrix2& B) const;

Remarks:

Perform matrix addition.

Prototype:

Matrix2 operator-(const Matrix2& B) const;

Remarks:

Perform matrix subtraction.

 

The following functions are not members of Matrix2 but are available for use:

Function:

Matrix2 RotateMatrix(float angle);

Remarks:

Builds an identity matrix and sets the rotation components based on the specified angle.

Parameters:

float angle

Specifies the angle of rotation.

Return Value:

A new Matrix2 object with the specified rotation angle.

Function

Matrix2 TransMatrix(const Point2& p);

Remarks:

Builds an identity matrix and sets the specified translation components.

Parameters:

const Point2& p

Specifies the translation.

Return Value:

A new Matrix2 object with the specified translation.

Function:

Matrix2 ScaleMatrix(const Point2& s);

Remarks:

Builds an identity matrix and sets the specified scaling components.

Parameters:

const Point2& s

Specifies the scale factors.

Return Value:

A new Matrix2 object with the specified scale.

Function:

Matrix2 Inverse(const Matrix2& M);

Remarks:

Returns the inverse of the specified Matrix2.

Parameters:

const Matrix2& M

Specifies the matrix to return the inverse of.

Return Value:

The inverse of the specified Matrix2.

Function:

Point2 operator*(const Matrix2& A, const Point2& V);

Point2 operator*(const Point2& V, const Matrix2& A);

Remarks:

Transforms the specified Point2 with the specified Matrix2.

Parameters:

const Matrix2& A

The matrix to transform the point with.

const Point2& V

The point to transform.

Return Value:

The transformed Point2.

Function:

Point2 VectorTransform(const Matrix2& M, const Point2& V);

Remarks:

This method transforms a 2D point by a 2x3 matrix. This is analogous to the 3D case.

Parameters:

const Matrix2& M

The matrix to transform the point with.

const Point2& V

The point to transform.

Return Value:

The transformed Point2.

Function:

ostream &operator<< (ostream& s, const Matrix2& A);

Remarks:

Formats the matrix for output.