|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.math.Matrix4f
public class Matrix4f
A 4 by 4 floating point matrix representing a 3D transformation.
Vectors are treated as columns, resulting in a matrix that is represented as follows, where x, y and z are the translation components of the matrix:
1 0 0 x 0 1 0 y 0 0 1 z 0 0 0 1
This matrix class is directly compatible with OpenGL since its elements are laid out in memory exactly as they are expected by OpenGL. The matrix uses column-major format such that array indices increase down column first.
Since matrix multiplication is not commutative, multiplication must be done in the correct order when combining transformations. Suppose we have a translation matrix T and a rotation matrix R. To first rotate an object around the origin and then translate it, you would multiply the two matrices as TR. Likewise, to first translate the object and then rotate it you would do RT. So generally, martices must be multiplied in the reverse order in which you want the transformations to take place.
Passing a matrix to OpenGL is a simple and efficient operation since the underlying array for the matrix is stored in a format that is directly compatible with OpenGL.
// Create a matrix to translate by (10, 2, -20)
Matrix translation =new
Matrix(); translation.set(1, 0, 0, 10, 0, 1, 0, 2, 0, 0, 1, -20, 0, 0, 0, 1 );// Pass our matrix to OpenGL
gl.glLoadMatrixf(translation.getArray());
Constructor Summary | ||
---|---|---|
Matrix4f()
Constructs a matrix initialized to the identity matrix. |
||
Matrix4f(float m00,
float m01,
float m02,
float m03,
float m10,
float m11,
float m12,
float m13,
float m20,
float m21,
float m22,
float m23,
float m30,
float m31,
float m32,
float m33)
Constructs a matrix initialized to the specified values. |
||
Matrix4f(float[] m)
Constructs a matrix initialized to the specified column-major array. |
||
Matrix4f(Matrix4f m)
Constructs a new matrix by copying the values from the specified matrix. |
Method Summary | ||
---|---|---|
void |
add(float scalar)
Adds a scalar value to each component of this matrix. |
|
void |
add(float scalar,
Matrix4f dst)
Adds a scalar value to this matrix and stores the result in dst. |
|
void |
add(Matrix4f m)
Adds the specified matrix to this matrix. |
|
static void |
add(Matrix4f m1,
Matrix4f m2,
Matrix4f dst)
Adds the specified matrices and stores the result in dst . |
|
static void |
createLookAt(Vector3f cameraPos,
Vector3f cameraTarget,
Vector3f cameraUpVector,
Matrix4f dst)
Creates a view matrix based on the specified input parameters. |
|
static void |
createRotation(Quaternion4f quat,
Matrix4f dst)
Creates a rotation matrix from the specified quaternion. |
|
static void |
createRotation(Vector3f axis,
float angle,
Matrix4f dst)
Creates a rotation matrix from the specified axis and angle. |
|
static void |
createRotationX(float angle,
Matrix4f dst)
Creates a matrix describing a rotation around the x-axis. |
|
static void |
createRotationY(float angle,
Matrix4f dst)
Creates a matrix describing a rotation around the y-axis. |
|
static void |
createRotationZ(float angle,
Matrix4f dst)
Creates a matrix describing a rotation around the z-axis. |
|
static void |
createScale(float xScale,
float yScale,
float zScale,
Matrix4f dst)
Creates a scale matrix. |
|
static void |
createTranslation(float xTrans,
float yTrans,
float zTrans,
Matrix4f dst)
Creates a translation matrix. |
|
boolean |
decompose(Vector3f scale,
Quaternion4f rotation,
Vector3f translation)
Decomposes the scale, rotation and translation components of this matrix. |
|
float |
determinant()
Computes the determinant of this matrix. |
|
boolean |
equals(Object obj)
Determines if this matrix is equal to the specified object. |
|
boolean |
equals(Matrix4f m)
Determines if this matrix is equal to the specified one. |
|
void |
get(float[] m)
Copies the values of this matrix into the given array in column-major order. |
|
float |
get(int index)
Gets the matrix element at the specified position. |
|
float |
get(int row,
int column)
Gets the matrix element at the specified row and column. |
|
float[] |
getArray()
Returns the underlying array for this matrix in column-major order. |
|
void |
getColumn(int column,
float[] v)
Stores the four elements of the specified column into v . |
|
void |
getColumn(int column,
Vector3f v)
Stores the first three elements of the specified column into v . |
|
boolean |
getRotation(Quaternion4f rotation)
Stores the rotational component of this matrix in the specified quaternion. |
|
void |
getRow(int row,
float[] v)
Stores the four elements of the specified row into v . |
|
void |
getRow(int row,
Vector3f v)
Stores the first three elements of the specified row into v . |
|
void |
getScale(Vector3f scale)
Stores the scalar component of this matrix in the specified vector. |
|
void |
getTranslation(Vector3f translation)
Stores the translational component of this matrix in the specified vector. |
|
int |
hashCode()
Returns the hash code of the matrix, based on the values stored in it. |
|
boolean |
invert()
Inverts this matrix. |
|
boolean |
invert(Matrix4f dst)
Inverts this matrix and stores the result in dst. |
|
boolean |
isIdentity()
Determines if this matrix is equal to the identity matrix. |
|
void |
multiply(float scalar)
Multiplies the components of this matrix by the specified scalar. |
|
void |
multiply(float scalar,
Matrix4f dst)
Multiplies the components of this matrix by a scalar and stores the result in dst. |
|
void |
multiply(Matrix4f m)
Multiplies this matrix by the specified one. |
|
static void |
multiply(Matrix4f m1,
Matrix4f m2,
Matrix4f dst)
Multiplies m1 by m2 and stores the result in dst. |
|
void |
negate()
Negates this matrix. |
|
void |
negate(Matrix4f dst)
Stores the negate of this matrix in dst. |
|
void |
rotate(Quaternion4f q)
Rotates this matrix by the specified quaternon. |
|
void |
rotate(Quaternion4f q,
Matrix4f dst)
Rotates this matrix by the specified quaternion and stores the result in dst . |
|
void |
rotate(Vector3f axis,
float angle)
Rotates this matrix about the specified axis. |
|
void |
rotate(Vector3f axis,
float angle,
Matrix4f dst)
Rotates this matrix about the specified axis and stores the result in dst . |
|
void |
rotateX(float angle)
Rotates this matrix by the specified amount around the x-axis. |
|
void |
rotateX(float angle,
Matrix4f dst)
Rotates this matrix by the specified amount around the x-axis and stores the result in dst . |
|
void |
rotateY(float angle)
Rotates this matrix by the specified amount around the y-axis. |
|
void |
rotateY(float angle,
Matrix4f dst)
Rotates this matrix by the specified amount around the y-axis and stores the result in dst . |
|
void |
rotateZ(float angle)
Rotates this matrix by the specified amount around the z-axis. |
|
void |
rotateZ(float angle,
Matrix4f dst)
Rotates this matrix by the specified amount around the z-axis and stores the result in dst . |
|
void |
scale(float value)
Scales this matrix by the specified amount along all axes. |
|
void |
scale(float xScale,
float yScale,
float zScale)
Scales this matrix by the specified amounts along each axis. |
|
void |
scale(float xScale,
float yScale,
float zScale,
Matrix4f dst)
Scales this matrix by the specified amounts along each axis and stores the result in dst . |
|
void |
scale(float value,
Matrix4f dst)
Scales this matrix by the specified amount along all axes and stores the result in dst . |
|
void |
set(float m00,
float m01,
float m02,
float m03,
float m10,
float m11,
float m12,
float m13,
float m20,
float m21,
float m22,
float m23,
float m30,
float m31,
float m32,
float m33)
Sets the values of this matrix. |
|
void |
set(float[] m)
Sets the values of this matrix to those in the specified column-major array. |
|
void |
set(int index,
float value)
Sets the specified element of this matrix to the specified value. |
|
void |
set(int row,
int column,
float value)
Sets the specified element of this matrix to the specified value. |
|
void |
set(Matrix4f m)
Sets the values of this matrix to those of the specified matrix. |
|
void |
setIdentity()
Sets this matrix to the identity matrix. |
|
void |
setZero()
Sets all elements of the current matrix to zero. |
|
void |
subtract(Matrix4f m)
Subtracts the specified matrix from the current matrix. |
|
static void |
subtract(Matrix4f m1,
Matrix4f m2,
Matrix4f dst)
Subtracts the specified matrices and stores the result in dst . |
|
String |
toString()
Returns a string representation of this matrix. |
|
void |
transformNormal(Vector3f normal)
Transforms the specified normal vector by this matrix by treating the fourth (w) coordinate as zero. |
|
void |
transformNormal(Vector3f normal,
Vector3f dst)
Transforms the specified normal vector by this matrix by treating the fourth (w) coordinate as zero, and stores the result in dst . |
|
void |
transformPoint(Vector3f point)
Transforms the specified vector that represents a point by this matrix by treating the fourth (w) coordinate as one. |
|
void |
transformPoint(Vector3f point,
Vector3f dst)
Transforms the specified vector that represents a point by this matrix by treating the fourth (w) coordinate as one, and stores the result in dst . |
|
void |
translate(float x,
float y,
float z)
Translates this matrix by the specified values. |
|
void |
translate(float x,
float y,
float z,
Matrix4f dst)
Translates this matrix by the specified values and stores the result in dst . |
|
void |
transpose()
Transposes this matrix. |
|
void |
transpose(Matrix4f dst)
Stores the transpose of this matrix in dst . |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Matrix4f()
public Matrix4f(float[] m)
The passed in array is in column-major order, so the memory layout of the array is as follows:
0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15
m
- a 16-element array, stored in column-major orderpublic Matrix4f(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
m00
- the first element of the first rowm01
- the second element of the first rowm02
- the third element of the first rowm03
- the fourth element of the first rowm10
- the first element of the second rowm11
- the second element of the second rowm12
- the third element of the second rowm13
- the fourth element of the second rowm20
- the first element of the third rowm21
- the second element of the third rowm22
- the third element of the third rowm23
- the fourth element of the third rowm30
- the first element of the fourth rowm31
- the second element of the fourth rowm32
- the third element of the fourth rowm33
- the fourth element of the fourth rowpublic Matrix4f(Matrix4f m)
m
- the source matrixMethod Detail |
---|
public final void add(float scalar)
scalar
- the scalar to addpublic final void add(float scalar, Matrix4f dst)
scalar
- the scalar value to adddst
- a matrix to store the result inpublic final void add(Matrix4f m)
m
- the matrix to addpublic static void add(Matrix4f m1, Matrix4f m2, Matrix4f dst)
dst
.
m1
- the first matrixm2
- the second matrixdst
- a matrix to store the result inpublic final boolean decompose(Vector3f scale, Quaternion4f rotation, Vector3f translation)
scale
- a vector to store the decomposed scale values inrotation
- a quaternion to store the decomposed rotation intranslation
- a vector to store the decomposed translation in
public final float determinant()
public boolean equals(Object obj)
equals
in class Object
obj
- the matrix to compare
Boolean.hashCode()
,
Hashtable
public boolean equals(Matrix4f m)
m
- the matrix to compare
public final void get(float[] m)
m
- a 16-element array to populate with the values from this matrixpublic final float get(int index)
This method indexes the internal array in column-major order. See the description of this class for more information on this topic.
index
- the zero-based index of the element to retrieve
public final float get(int row, int column)
row
- the zero-based row of the element to retrievecolumn
- the zero-based column of the element to retrieve
public final float[] getArray()
The returned array is in column-major order and therefore compatible with systems such as OpenGL that expect data in this order. The memory layout of the array is therefore as follows:
0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15
Note that modifying the elements of the returned array will modify the matrix itself.
public final void getColumn(int column, float[] v)
v
.
column
- the index of the column to retrieve (zero-based)v
- a four-element array to store the column inpublic final void getColumn(int column, Vector3f v)
v
.
column
- the index of the column to retrieve (zero-based)v
- a vector to store the column inpublic final boolean getRotation(Quaternion4f rotation)
rotation
- a quaternion to receive the rotation
public final void getRow(int row, float[] v)
v
.
row
- the index of the row to retrieve (zero-based)v
- a four-element array to store the row inpublic final void getRow(int row, Vector3f v)
v
.
row
- the index of the row to retrieve (zero-based)v
- a vector to store the row inpublic final void getScale(Vector3f scale)
scale
- a vector to receive the scalepublic final void getTranslation(Vector3f translation)
translation
- a vector to receive the translationpublic int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
Hashtable
public final boolean invert()
public final boolean invert(Matrix4f dst)
dst
- a matrix to store the invert of this matrix in
public final boolean isIdentity()
public final void multiply(float scalar)
scalar
- the scalar valuepublic final void multiply(float scalar, Matrix4f dst)
scalar
- the scalar valuedst
- a matrix to store the result inpublic final void multiply(Matrix4f m)
m
- the matrix to multiplypublic static void multiply(Matrix4f m1, Matrix4f m2, Matrix4f dst)
m1
- the first matrix to multiplym2
- the second matrix to multiplydst
- a matrix to store the result inpublic final void negate()
public final void negate(Matrix4f dst)
dst
- a matrix to store the result inpublic final void rotate(Quaternion4f q)
q
- the quaternion to rotate bypublic final void rotate(Quaternion4f q, Matrix4f dst)
dst
.
q
- the quaternion to rotate bydst
- a matrix to store the result inpublic final void rotate(Vector3f axis, float angle)
axis
- the axis to rotate aboutangle
- the angle, in radianspublic final void rotate(Vector3f axis, float angle, Matrix4f dst)
dst
.
axis
- the axis to rotate aboutangle
- the angle, in radiansdst
- a matrix to store the result inpublic final void rotateX(float angle)
angle
- the angle to rotate by, in radianspublic final void rotateX(float angle, Matrix4f dst)
dst
.
angle
- the angle to rotate by, in radiansdst
- a matrix to store the result inpublic final void rotateY(float angle)
angle
- the angle to rotate by, in radianspublic final void rotateY(float angle, Matrix4f dst)
dst
.
angle
- the angle to rotate by, in radiansdst
- a matrix to store the result inpublic final void rotateZ(float angle)
angle
- the angle to rotate by, in radianspublic final void rotateZ(float angle, Matrix4f dst)
dst
.
angle
- the angle to rotate by, in radiansdst
- a matrix to store the result inpublic final void scale(float value)
value
- the amount to scale this matrix bypublic final void scale(float value, Matrix4f dst)
dst
.
value
- the amount to scale the matrix bydst
- a matrix to store the result inpublic final void scale(float xScale, float yScale, float zScale)
xScale
- the amount to scale along the x-axisyScale
- the amount to scale along the y-axiszScale
- the amount to scale along the z-axispublic final void scale(float xScale, float yScale, float zScale, Matrix4f dst)
dst
.
xScale
- the amount to scale along the x-axisyScale
- the amount to scale along the y-axiszScale
- the amount to scale along the z-axisdst
- a matrix to store the result inpublic final void set(float[] m)
m
- a 16-element array, stored in column-major formatpublic final void set(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
m00
- the first element of the first rowm01
- the second element of the first rowm02
- the third element of the first rowm03
- the fourth element of the first rowm10
- the first element of the second rowm11
- the second element of the second rowm12
- the third element of the second rowm13
- the fourth element of the second rowm20
- the first element of the third rowm21
- the second element of the third rowm22
- the third element of the third rowm23
- the fourth element of the third rowm30
- the first element of the fourth rowm31
- the second element of the fourth rowm32
- the third element of the fourth rowm33
- the fourth element of the fourth rowpublic final void set(Matrix4f m)
m
- the source matrixpublic final void set(int index, float value)
index
- the index of the element to set (0-15)value
- the value to setpublic final void set(int row, int column, float value)
row
- the row of the element (0-3)column
- the column of the element (0-3)value
- the value to setpublic final void setIdentity()
public final void setZero()
public final void subtract(Matrix4f m)
m
- the matrix to subtractpublic static void subtract(Matrix4f m1, Matrix4f m2, Matrix4f dst)
dst
.
m1
- the first matrixm2
- the second matrixdst
- a matrix to store the result inpublic final void transformNormal(Vector3f normal)
The result of the transformation is stored directly into normal
.
normal
- the normal vector to transformpublic final void transformNormal(Vector3f normal, Vector3f dst)
dst
.
normal
- the normal vector to transformdst
- a vector to store the transformed normal inpublic final void transformPoint(Vector3f point)
The result of the transformation is stored directly into point
.
point
- the point to transformpublic final void transformPoint(Vector3f point, Vector3f dst)
dst
.
point
- the point to transformdst
- a vector to store the transformed point inpublic final void translate(float x, float y, float z)
x
- amount to translate along the x-axisy
- amount to translate along the y-axisz
- amount to translate along the z-axispublic final void translate(float x, float y, float z, Matrix4f dst)
dst
.
x
- amount to translate along the x-axisy
- amount to translate along the y-axisz
- amount to translate along the z-axisdst
- a matrix to store the result inpublic final void transpose()
public final void transpose(Matrix4f dst)
dst
.
dst
- a matrix to store the transpose inpublic String toString()
toString
in class Object
public static void createScale(float xScale, float yScale, float zScale, Matrix4f dst)
xScale
- the scale on the x-axisyScale
- the scale on the y-axiszScale
- the scale on the z-axisdst
- a matrix to store the result inpublic static void createTranslation(float xTrans, float yTrans, float zTrans, Matrix4f dst)
xTrans
- the translation on the x-axisyTrans
- the translation on the y-axiszTrans
- the translation on the z-axisdst
- a matrix to store the result inpublic static void createRotation(Quaternion4f quat, Matrix4f dst)
quat
- a quaternion describing a 3D orientationdst
- a matrix to store the result inpublic static void createRotation(Vector3f axis, float angle, Matrix4f dst)
axis
- a vector describing the axis to rotate aboutangle
- the angle, in radiansdst
- a matrix to store the result inpublic static void createRotationX(float angle, Matrix4f dst)
angle
- the angle of rotation, in radiansdst
- a matrix to store the result inpublic static void createRotationY(float angle, Matrix4f dst)
angle
- the angle of rotation, in radiansdst
- a matrix to store the result inpublic static void createRotationZ(float angle, Matrix4f dst)
angle
- the angle of rotation, in radiansdst
- a matrix to store the result inpublic static void createLookAt(Vector3f cameraPos, Vector3f cameraTarget, Vector3f cameraUpVector, Matrix4f dst)
cameraPos
- the position of the cameracameraTarget
- the position of the target that the camera is pointing atcameraUpVector
- a vector describing the "up" direction of the cameradst
- a matrix to store the result in
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.