Added Vector4.mult(Matrix4) and Matrix4.transform(Vector4).
This commit is contained in:
@@ -247,6 +247,21 @@ public interface IMatrix4
|
|||||||
*/
|
*/
|
||||||
Vector3 transformVector (IVector3 vector, Vector3 result);
|
Vector3 transformVector (IVector3 vector, Vector3 result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms {@code vector} by this matrix (M * V).
|
||||||
|
*
|
||||||
|
* @return a new vector containing the result.
|
||||||
|
*/
|
||||||
|
Vector4 transform (IVector4 vector);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms {@code vector} by this matrix (M * V) and stores the result in the object
|
||||||
|
* provided.
|
||||||
|
*
|
||||||
|
* @return a reference to the result vector, for chaining.
|
||||||
|
*/
|
||||||
|
Vector4 transform (IVector4 vector, Vector4 result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the rotation component of the matrix.
|
* Extracts the rotation component of the matrix.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -34,4 +34,18 @@ public interface IVector4
|
|||||||
* Compares this vector to another with the provided epsilon.
|
* Compares this vector to another with the provided epsilon.
|
||||||
*/
|
*/
|
||||||
boolean epsilonEquals (IVector4 other, double epsilon);
|
boolean epsilonEquals (IVector4 other, double epsilon);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiplies this vector by a matrix (V * M).
|
||||||
|
*
|
||||||
|
* @return a new vector containing the result.
|
||||||
|
*/
|
||||||
|
IVector4 mult (IMatrix4 matrix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiplies this vector by a matrix (V * M) and stores the result in the object provided.
|
||||||
|
*
|
||||||
|
* @return a reference to the result vector, for chaining.
|
||||||
|
*/
|
||||||
|
IVector4 mult (IMatrix4 matrix, Vector4 result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -916,6 +916,20 @@ public final class Matrix4 implements IMatrix4, Serializable
|
|||||||
m02*vx + m12*vy + m22*vz);
|
m02*vx + m12*vy + m22*vz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from IMatrix4
|
||||||
|
public Vector4 transform (IVector4 vector) {
|
||||||
|
return transform(vector, new Vector4());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from IMatrix4
|
||||||
|
public Vector4 transform (IVector4 vector, Vector4 result) {
|
||||||
|
double vx = vector.x(), vy = vector.y(), vz = vector.z(), vw = vector.w();
|
||||||
|
return result.set(m00*vx + m10*vy + m20*vz + m30*vw,
|
||||||
|
m01*vx + m11*vy + m21*vz + m31*vw,
|
||||||
|
m02*vx + m12*vy + m22*vz + m32*vw,
|
||||||
|
m03*vx + m13*vy + m23*vz + m33*vw);
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from IMatrix4
|
@Override // from IMatrix4
|
||||||
public Quaternion extractRotation () {
|
public Quaternion extractRotation () {
|
||||||
return extractRotation(new Quaternion());
|
return extractRotation(new Quaternion());
|
||||||
|
|||||||
@@ -92,6 +92,15 @@ public class Vector4 implements IVector4, Serializable
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiplies this vector by a matrix (V * M) and stores the result back in this vector.
|
||||||
|
*
|
||||||
|
* @return a reference to this vector, for chaining.
|
||||||
|
*/
|
||||||
|
public IVector4 multLocal (IMatrix4 matrix) {
|
||||||
|
return mult(matrix, this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from IVector4
|
@Override // from IVector4
|
||||||
public double x () {
|
public double x () {
|
||||||
return x;
|
return x;
|
||||||
@@ -125,6 +134,24 @@ public class Vector4 implements IVector4, Serializable
|
|||||||
Math.abs(w - other.w()) < epsilon);
|
Math.abs(w - other.w()) < epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from IVector4
|
||||||
|
public IVector4 mult (IMatrix4 matrix) {
|
||||||
|
return mult(matrix, new Vector4());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from IVector4
|
||||||
|
public IVector4 mult (IMatrix4 matrix, Vector4 result) {
|
||||||
|
double m00 = matrix.m00(), m10 = matrix.m10(), m20 = matrix.m20(), m30 = matrix.m30();
|
||||||
|
double m01 = matrix.m01(), m11 = matrix.m11(), m21 = matrix.m21(), m31 = matrix.m31();
|
||||||
|
double m02 = matrix.m02(), m12 = matrix.m12(), m22 = matrix.m22(), m32 = matrix.m32();
|
||||||
|
double m03 = matrix.m03(), m13 = matrix.m13(), m23 = matrix.m23(), m33 = matrix.m33();
|
||||||
|
double vx = x, vy = y, vz = z, vw = w;
|
||||||
|
return result.set(m00*vx + m01*vy + m02*vz + m03*vw,
|
||||||
|
m10*vx + m11*vy + m12*vz + m13*vw,
|
||||||
|
m20*vx + m21*vy + m22*vz + m23*vw,
|
||||||
|
m30*vx + m31*vy + m32*vz + m33*vw);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
|
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
|
||||||
|
|||||||
@@ -247,6 +247,21 @@ public interface IMatrix4
|
|||||||
*/
|
*/
|
||||||
Vector3 transformVector (IVector3 vector, Vector3 result);
|
Vector3 transformVector (IVector3 vector, Vector3 result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms {@code vector} by this matrix (M * V).
|
||||||
|
*
|
||||||
|
* @return a new vector containing the result.
|
||||||
|
*/
|
||||||
|
Vector4 transform (IVector4 vector);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms {@code vector} by this matrix (M * V) and stores the result in the object
|
||||||
|
* provided.
|
||||||
|
*
|
||||||
|
* @return a reference to the result vector, for chaining.
|
||||||
|
*/
|
||||||
|
Vector4 transform (IVector4 vector, Vector4 result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the rotation component of the matrix.
|
* Extracts the rotation component of the matrix.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -34,4 +34,18 @@ public interface IVector4
|
|||||||
* Compares this vector to another with the provided epsilon.
|
* Compares this vector to another with the provided epsilon.
|
||||||
*/
|
*/
|
||||||
boolean epsilonEquals (IVector4 other, float epsilon);
|
boolean epsilonEquals (IVector4 other, float epsilon);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiplies this vector by a matrix (V * M).
|
||||||
|
*
|
||||||
|
* @return a new vector containing the result.
|
||||||
|
*/
|
||||||
|
IVector4 mult (IMatrix4 matrix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiplies this vector by a matrix (V * M) and stores the result in the object provided.
|
||||||
|
*
|
||||||
|
* @return a reference to the result vector, for chaining.
|
||||||
|
*/
|
||||||
|
IVector4 mult (IMatrix4 matrix, Vector4 result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -916,6 +916,20 @@ public final class Matrix4 implements IMatrix4, Serializable
|
|||||||
m02*vx + m12*vy + m22*vz);
|
m02*vx + m12*vy + m22*vz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from IMatrix4
|
||||||
|
public Vector4 transform (IVector4 vector) {
|
||||||
|
return transform(vector, new Vector4());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from IMatrix4
|
||||||
|
public Vector4 transform (IVector4 vector, Vector4 result) {
|
||||||
|
float vx = vector.x(), vy = vector.y(), vz = vector.z(), vw = vector.w();
|
||||||
|
return result.set(m00*vx + m10*vy + m20*vz + m30*vw,
|
||||||
|
m01*vx + m11*vy + m21*vz + m31*vw,
|
||||||
|
m02*vx + m12*vy + m22*vz + m32*vw,
|
||||||
|
m03*vx + m13*vy + m23*vz + m33*vw);
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from IMatrix4
|
@Override // from IMatrix4
|
||||||
public Quaternion extractRotation () {
|
public Quaternion extractRotation () {
|
||||||
return extractRotation(new Quaternion());
|
return extractRotation(new Quaternion());
|
||||||
|
|||||||
@@ -92,6 +92,15 @@ public class Vector4 implements IVector4, Serializable
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multiplies this vector by a matrix (V * M) and stores the result back in this vector.
|
||||||
|
*
|
||||||
|
* @return a reference to this vector, for chaining.
|
||||||
|
*/
|
||||||
|
public IVector4 multLocal (IMatrix4 matrix) {
|
||||||
|
return mult(matrix, this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override // from IVector4
|
@Override // from IVector4
|
||||||
public float x () {
|
public float x () {
|
||||||
return x;
|
return x;
|
||||||
@@ -125,6 +134,24 @@ public class Vector4 implements IVector4, Serializable
|
|||||||
Math.abs(w - other.w()) < epsilon);
|
Math.abs(w - other.w()) < epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from IVector4
|
||||||
|
public IVector4 mult (IMatrix4 matrix) {
|
||||||
|
return mult(matrix, new Vector4());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override // from IVector4
|
||||||
|
public IVector4 mult (IMatrix4 matrix, Vector4 result) {
|
||||||
|
float m00 = matrix.m00(), m10 = matrix.m10(), m20 = matrix.m20(), m30 = matrix.m30();
|
||||||
|
float m01 = matrix.m01(), m11 = matrix.m11(), m21 = matrix.m21(), m31 = matrix.m31();
|
||||||
|
float m02 = matrix.m02(), m12 = matrix.m12(), m22 = matrix.m22(), m32 = matrix.m32();
|
||||||
|
float m03 = matrix.m03(), m13 = matrix.m13(), m23 = matrix.m23(), m33 = matrix.m33();
|
||||||
|
float vx = x, vy = y, vz = z, vw = w;
|
||||||
|
return result.set(m00*vx + m01*vy + m02*vz + m03*vw,
|
||||||
|
m10*vx + m11*vy + m12*vz + m13*vw,
|
||||||
|
m20*vx + m21*vy + m22*vz + m23*vw,
|
||||||
|
m30*vx + m31*vy + m32*vz + m33*vw);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString () {
|
public String toString () {
|
||||||
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
|
return "[" + x + ", " + y + ", " + z + ", " + w + "]";
|
||||||
|
|||||||
Reference in New Issue
Block a user