📄 matrix4.java
字号:
}
/**
* Computes the x component of this*(x,y,z,0).
*
* @param x x coordinate of the vector to multiply
* @param y y coordinate of the vector to multiply
* @param z z coordinate of the vector to multiply
* @return x coordinate transformation result
*/
public final float transformVX(float x, float y, float z) {
return m00 * x + m01 * y + m02 * z;
}
/**
* Computes the y component of this*(x,y,z,0).
*
* @param x x coordinate of the vector to multiply
* @param y y coordinate of the vector to multiply
* @param z z coordinate of the vector to multiply
* @return y coordinate transformation result
*/
public final float transformVY(float x, float y, float z) {
return m10 * x + m11 * y + m12 * z;
}
/**
* Computes the z component of this*(x,y,z,0).
*
* @param x x coordinate of the vector to multiply
* @param y y coordinate of the vector to multiply
* @param z z coordinate of the vector to multiply
* @return z coordinate transformation result
*/
public final float transformVZ(float x, float y, float z) {
return m20 * x + m21 * y + m22 * z;
}
/**
* Computes the x component of (this^T)*(x,y,z,0).
*
* @param x x coordinate of the vector to multiply
* @param y y coordinate of the vector to multiply
* @param z z coordinate of the vector to multiply
* @return x coordinate transformation result
*/
public final float transformTransposeVX(float x, float y, float z) {
return m00 * x + m10 * y + m20 * z;
}
/**
* Computes the y component of (this^T)*(x,y,z,0).
*
* @param x x coordinate of the vector to multiply
* @param y y coordinate of the vector to multiply
* @param z z coordinate of the vector to multiply
* @return y coordinate transformation result
*/
public final float transformTransposeVY(float x, float y, float z) {
return m01 * x + m11 * y + m21 * z;
}
/**
* Computes the z component of (this^T)*(x,y,z,0).
*
* @param x x coordinate of the vector to multiply
* @param y y coordinate of the vector to multiply
* @param z z coordinate of the vector to multiply
* @return zcoordinate transformation result
*/
public final float transformTransposeVZ(float x, float y, float z) {
return m02 * x + m12 * y + m22 * z;
}
/**
* Computes the x component of this*(x,y,z,1).
*
* @param x x coordinate of the vector to multiply
* @param y y coordinate of the vector to multiply
* @param z z coordinate of the vector to multiply
* @return x coordinate transformation result
*/
public final float transformPX(float x, float y, float z) {
return m00 * x + m01 * y + m02 * z + m03;
}
/**
* Computes the y component of this*(x,y,z,1).
*
* @param x x coordinate of the vector to multiply
* @param y y coordinate of the vector to multiply
* @param z z coordinate of the vector to multiply
* @return y coordinate transformation result
*/
public final float transformPY(float x, float y, float z) {
return m10 * x + m11 * y + m12 * z + m13;
}
/**
* Computes the z component of this*(x,y,z,1).
*
* @param x x coordinate of the vector to multiply
* @param y y coordinate of the vector to multiply
* @param z z coordinate of the vector to multiply
* @return z coordinate transformation result
*/
public final float transformPZ(float x, float y, float z) {
return m20 * x + m21 * y + m22 * z + m23;
}
/**
* Create a translation matrix for the specified vector.
*
* @param x x component of translation
* @param y y component of translation
* @param z z component of translation
* @return a new Matrix4 object representing the translation
*/
public final static Matrix4 translation(float x, float y, float z) {
Matrix4 m = new Matrix4();
m.m00 = m.m11 = m.m22 = m.m33 = 1;
m.m03 = x;
m.m13 = y;
m.m23 = z;
return m;
}
/**
* Creates a rotation matrix about the X axis.
*
* @param theta angle to rotate about the X axis in radians
* @return a new Matrix4 object representing the rotation
*/
public final static Matrix4 rotateX(float theta) {
Matrix4 m = new Matrix4();
float s = (float) Math.sin(theta);
float c = (float) Math.cos(theta);
m.m00 = m.m33 = 1;
m.m11 = m.m22 = c;
m.m12 = -s;
m.m21 = +s;
return m;
}
/**
* Creates a rotation matrix about the Y axis.
*
* @param theta angle to rotate about the Y axis in radians
* @return a new Matrix4 object representing the rotation
*/
public final static Matrix4 rotateY(float theta) {
Matrix4 m = new Matrix4();
float s = (float) Math.sin(theta);
float c = (float) Math.cos(theta);
m.m11 = m.m33 = 1;
m.m00 = m.m22 = c;
m.m02 = +s;
m.m20 = -s;
return m;
}
/**
* Creates a rotation matrix about the Z axis.
*
* @param theta angle to rotate about the Z axis in radians
* @return a new Matrix4 object representing the rotation
*/
public final static Matrix4 rotateZ(float theta) {
Matrix4 m = new Matrix4();
float s = (float) Math.sin(theta);
float c = (float) Math.cos(theta);
m.m22 = m.m33 = 1;
m.m00 = m.m11 = c;
m.m01 = -s;
m.m10 = +s;
return m;
}
/**
* Creates a rotation matrix about the specified axis. The axis vector need
* not be normalized.
*
* @param x x component of the axis vector
* @param y y component of the axis vector
* @param z z component of the axis vector
* @param theta angle to rotate about the axis in radians
* @return a new Matrix4 object representing the rotation
*/
public final static Matrix4 rotate(float x, float y, float z, float theta) {
Matrix4 m = new Matrix4();
float invLen = 1 / (float) Math.sqrt(x * x + y * y + z * z);
x *= invLen;
y *= invLen;
z *= invLen;
float s = (float) Math.sin(theta);
float c = (float) Math.cos(theta);
float t = 1 - c;
m.m00 = t * x * x + c;
m.m11 = t * y * y + c;
m.m22 = t * z * z + c;
float txy = t * x * y;
float sz = s * z;
m.m01 = txy - sz;
m.m10 = txy + sz;
float txz = t * x * z;
float sy = s * y;
m.m02 = txz + sy;
m.m20 = txz - sy;
float tyz = t * y * z;
float sx = s * x;
m.m12 = tyz - sx;
m.m21 = tyz + sx;
m.m33 = 1;
return m;
}
/**
* Create a uniform scaling matrix.
*
* @param s scale factor for all three axes
* @return a new Matrix4 object representing the uniform scale
*/
public final static Matrix4 scale(float s) {
Matrix4 m = new Matrix4();
m.m00 = m.m11 = m.m22 = s;
m.m33 = 1;
return m;
}
/**
* Creates a non-uniform scaling matrix.
*
* @param sx scale factor in the x dimension
* @param sy scale factor in the y dimension
* @param sz scale factor in the z dimension
* @return a new Matrix4 object representing the non-uniform scale
*/
public final static Matrix4 scale(float sx, float sy, float sz) {
Matrix4 m = new Matrix4();
m.m00 = sx;
m.m11 = sy;
m.m22 = sz;
m.m33 = 1;
return m;
}
/**
* Creates a rotation matrix from an OrthonormalBasis.
*
* @param basis
*/
public final static Matrix4 fromBasis(OrthoNormalBasis basis) {
Matrix4 m = new Matrix4();
Vector3 u = basis.transform(new Vector3(1, 0, 0));
Vector3 v = basis.transform(new Vector3(0, 1, 0));
Vector3 w = basis.transform(new Vector3(0, 0, 1));
m.m00 = u.x;
m.m01 = v.x;
m.m02 = w.x;
m.m10 = u.y;
m.m11 = v.y;
m.m12 = w.y;
m.m20 = u.z;
m.m21 = v.z;
m.m22 = w.z;
m.m33 = 1;
return m;
}
public final static Matrix4 blend(Matrix4 m0, Matrix4 m1, float t) {
Matrix4 m = new Matrix4();
m.m00 = (1 - t) * m0.m00 + t * m1.m00;
m.m01 = (1 - t) * m0.m01 + t * m1.m01;
m.m02 = (1 - t) * m0.m02 + t * m1.m02;
m.m03 = (1 - t) * m0.m03 + t * m1.m03;
m.m10 = (1 - t) * m0.m10 + t * m1.m10;
m.m11 = (1 - t) * m0.m11 + t * m1.m11;
m.m12 = (1 - t) * m0.m12 + t * m1.m12;
m.m13 = (1 - t) * m0.m13 + t * m1.m13;
m.m20 = (1 - t) * m0.m20 + t * m1.m20;
m.m21 = (1 - t) * m0.m21 + t * m1.m21;
m.m22 = (1 - t) * m0.m22 + t * m1.m22;
m.m23 = (1 - t) * m0.m23 + t * m1.m23;
m.m30 = (1 - t) * m0.m30 + t * m1.m30;
m.m31 = (1 - t) * m0.m31 + t * m1.m31;
m.m32 = (1 - t) * m0.m32 + t * m1.m32;
m.m33 = (1 - t) * m0.m33 + t * m1.m33;
return m;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -