Added a bunch of stuff at Stefan's request.

- Matrix3: add, addLocal, setToZero
- Matrix4: extractRotationScale, setToRotationScale, setToZero
- Vector3: abs, absLocal
- Vector4: negate, negateLocal, abs, absLocal, mult(v), multLocal(v)
This commit is contained in:
Michael Bayne
2012-05-18 13:42:45 -07:00
parent 00df755904
commit 278a947de1
16 changed files with 450 additions and 16 deletions
+14
View File
@@ -77,6 +77,20 @@ interface IMatrix3
*/
Matrix3 mult (IMatrix3 other, Matrix3 result);
/**
* Adds this matrix to another.
*
* @return a new matrix containing the result.
*/
Matrix3 add (IMatrix3 other);
/**
* Adds this matrix to another and stores the result in the object provided.
*
* @return a reference to the result matrix, for chaining.
*/
Matrix3 add (IMatrix3 other, Matrix3 result);
/**
* Determines whether this matrix represents an affine transformation.
*/
+7
View File
@@ -277,6 +277,13 @@ public interface IMatrix4
*/
Quaternion extractRotation (Quaternion result);
/**
* Extracts the rotation and scale components and places them in the provided result.
*
* @return a reference to {@code result}, for chaining.
*/
Matrix3 extractRotationScale (Matrix3 result);
/**
* Extracts the scale component of the matrix.
*
+16 -1
View File
@@ -60,6 +60,20 @@ public interface IVector3
*/
Vector3 negate (Vector3 result);
/**
* Absolute-values this vector.
*
* @return a new vector containing the result.
*/
Vector3 abs ();
/**
* Absolute-values this vector, storing the result in the supplied object.
*
* @return a reference to the result, for chaining.
*/
Vector3 abs (Vector3 result);
/**
* Normalizes this vector.
*
@@ -138,12 +152,13 @@ public interface IVector3
* @return a new vector containing the result.
*/
Vector3 add (IVector3 other);
/**
* Adds a vector to this one, storing the result in the object provided.
*
* @return a reference to the result, for chaining.
*/
public IVector3 add (IVector3 other, Vector3 result);
Vector3 add (IVector3 other, Vector3 result);
/**
* Subtracts a vector from this one.
+44 -2
View File
@@ -35,17 +35,59 @@ public interface IVector4
*/
boolean epsilonEquals (IVector4 other, double epsilon);
/**
* Negates this vector.
*
* @return a new vector containing the result.
*/
Vector4 negate ();
/**
* Negates this vector, storing the result in the supplied object.
*
* @return a reference to the result, for chaining.
*/
Vector4 negate (Vector4 result);
/**
* Absolute-values this vector.
*
* @return a new vector containing the result.
*/
Vector4 abs ();
/**
* Absolute-values this vector, storing the result in the supplied object.
*
* @return a reference to the result, for chaining.
*/
Vector4 abs (Vector4 result);
/**
* Multiplies this vector by a scalar.
*
* @return a new vector containing the result.
*/
Vector4 mult (double v);
/**
* Multiplies this vector by a scalar and places the result in the supplied object.
*
* @return a reference to the result, for chaining.
*/
Vector4 mult (double v, Vector4 result);
/**
* Multiplies this vector by a matrix (V * M).
*
* @return a new vector containing the result.
*/
IVector4 mult (IMatrix4 matrix);
Vector4 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);
Vector4 mult (IMatrix4 matrix, Vector4 result);
}
+32
View File
@@ -134,6 +134,17 @@ public class Matrix3 implements IMatrix3, Serializable
0f, 0f, 1f);
}
/**
* Sets this matrix to all zeroes.
*
* @return a reference to this matrix, for chaining.
*/
public Matrix3 setToZero () {
return set(0f, 0f, 0f,
0f, 0f, 0f,
0f, 0f, 0f);
}
/**
* Sets this to a rotation matrix that rotates one vector onto another.
*
@@ -337,6 +348,15 @@ public class Matrix3 implements IMatrix3, Serializable
return mult(other, this);
}
/**
* Adds {@code other} to this matrix, in place.
*
* @return a reference to this matrix, for chaining.
*/
public Matrix3 addLocal (IMatrix3 other) {
return add(other, this);
}
/**
* Multiplies this matrix in-place by another, treating the matricees as affine.
*
@@ -552,6 +572,18 @@ public class Matrix3 implements IMatrix3, Serializable
m02*om20 + m12*om21 + m22*om22);
}
@Override // from IMatrix3
public Matrix3 add (IMatrix3 other) {
return add(other, new Matrix3());
}
@Override // from IMatrix3
public Matrix3 add (IMatrix3 other, Matrix3 result) {
return result.set(m00 + other.m00(), m01 + other.m01(), m02 + other.m02(),
m10 + other.m10(), m11 + other.m11(), m12 + other.m12(),
m20 + other.m20(), m21 + other.m21(), m22 + other.m22());
}
@Override // from IMatrix3
public boolean isAffine () {
return (m02 == 0f && m12 == 0f && m22 == 1f);
+33 -2
View File
@@ -81,6 +81,18 @@ public final class Matrix4 implements IMatrix4, Serializable
0f, 0f, 0f, 1f);
}
/**
* Sets this matrix to all zeroes.
*
* @return a reference to this matrix, for chaining.
*/
public Matrix4 setToZero () {
return set(0f, 0f, 0f, 0f,
0f, 0f, 0f, 0f,
0f, 0f, 0f, 0f,
0f, 0f, 0f, 0f);
}
/**
* Sets this to a matrix that first rotates, then translates.
*
@@ -221,6 +233,18 @@ public final class Matrix4 implements IMatrix4, Serializable
0f, 0f, 0f, 1f);
}
/**
* Sets this to a rotation plus scale matrix.
*
* @return a reference to this matrix, for chaining.
*/
public Matrix4 setToRotationScale (IMatrix3 rotScale) {
return set(rotScale.m00(), rotScale.m01(), rotScale.m02(), 0f,
rotScale.m10(), rotScale.m11(), rotScale.m12(), 0f,
rotScale.m20(), rotScale.m21(), rotScale.m22(), 0f,
0, 0, 0, 1);
}
/**
* Sets this to a scale matrix.
*
@@ -424,7 +448,7 @@ public final class Matrix4 implements IMatrix4, Serializable
}
/**
* Copies the elements of an array.
* Copies the elements of a row-major array.
*
* @return a reference to this matrix, for chaining.
*/
@@ -436,7 +460,7 @@ public final class Matrix4 implements IMatrix4, Serializable
}
/**
* Sets the contents of this matrix from the supplied buffer.
* Sets the contents of this matrix from the supplied (column-major) buffer.
*
* @return a reference to this matrix, for chaining.
*/
@@ -997,6 +1021,13 @@ public final class Matrix4 implements IMatrix4, Serializable
return result;
}
@Override // from IMatrix4
public Matrix3 extractRotationScale (Matrix3 result) {
return result.set(m00, m01, m02,
m10, m11, m12,
m20, m21, m22);
}
@Override // from IMatrix4
public Vector3 extractScale () {
return extractScale(new Vector3());
+19
View File
@@ -90,6 +90,15 @@ public class Vector3 implements IVector3, Serializable
return negate(this);
}
/**
* Absolute-values this vector in-place.
*
* @return a reference to this vector, for chaining.
*/
public Vector3 absLocal () {
return abs(this);
}
/**
* Normalizes this vector in-place.
*
@@ -241,6 +250,16 @@ public class Vector3 implements IVector3, Serializable
return result.set(-x, -y, -z);
}
@Override // from interface IVector3
public Vector3 abs () {
return abs(new Vector3());
}
@Override // from interface IVector3
public Vector3 abs (Vector3 result) {
return result.set(Math.abs(x), Math.abs(y), Math.abs(z));
}
@Override // from interface IVector3
public Vector3 normalize () {
return normalize(new Vector3());
+60 -3
View File
@@ -92,12 +92,39 @@ public class Vector4 implements IVector4, Serializable
return this;
}
/**
* Negates this vector in-place.
*
* @return a reference to this vector, for chaining.
*/
public Vector4 negateLocal () {
return negate(this);
}
/**
* Absolute-values this vector in-place.
*
* @return a reference to this vector, for chaining.
*/
public Vector4 absLocal () {
return abs(this);
}
/**
* Multiplies this vector by a scalar and stores the result back in this vector.
*
* @return a reference to this vector, for chaining.
*/
public Vector4 multLocal (double v) {
return mult(v, 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) {
public Vector4 multLocal (IMatrix4 matrix) {
return mult(matrix, this);
}
@@ -134,13 +161,43 @@ public class Vector4 implements IVector4, Serializable
Math.abs(w - other.w()) < epsilon);
}
@Override // from interface IVector4
public Vector4 negate () {
return negate(new Vector4());
}
@Override // from interface IVector4
public Vector4 negate (Vector4 result) {
return result.set(-x, -y, -z, -w);
}
@Override // from interface IVector4
public Vector4 abs () {
return abs(new Vector4());
}
@Override // from interface IVector4
public Vector4 abs (Vector4 result) {
return result.set(Math.abs(x), Math.abs(y), Math.abs(z), Math.abs(w));
}
@Override // from interface IVector4
public Vector4 mult (double v) {
return mult(v, new Vector4());
}
@Override // from interface IVector4
public Vector4 mult (double v, Vector4 result) {
return result.set(x*v, y*v, z*v, w*v);
}
@Override // from IVector4
public IVector4 mult (IMatrix4 matrix) {
public Vector4 mult (IMatrix4 matrix) {
return mult(matrix, new Vector4());
}
@Override // from IVector4
public IVector4 mult (IMatrix4 matrix, Vector4 result) {
public Vector4 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();
+14
View File
@@ -77,6 +77,20 @@ interface IMatrix3
*/
Matrix3 mult (IMatrix3 other, Matrix3 result);
/**
* Adds this matrix to another.
*
* @return a new matrix containing the result.
*/
Matrix3 add (IMatrix3 other);
/**
* Adds this matrix to another and stores the result in the object provided.
*
* @return a reference to the result matrix, for chaining.
*/
Matrix3 add (IMatrix3 other, Matrix3 result);
/**
* Determines whether this matrix represents an affine transformation.
*/
+7
View File
@@ -277,6 +277,13 @@ public interface IMatrix4
*/
Quaternion extractRotation (Quaternion result);
/**
* Extracts the rotation and scale components and places them in the provided result.
*
* @return a reference to {@code result}, for chaining.
*/
Matrix3 extractRotationScale (Matrix3 result);
/**
* Extracts the scale component of the matrix.
*
+16 -1
View File
@@ -60,6 +60,20 @@ public interface IVector3
*/
Vector3 negate (Vector3 result);
/**
* Absolute-values this vector.
*
* @return a new vector containing the result.
*/
Vector3 abs ();
/**
* Absolute-values this vector, storing the result in the supplied object.
*
* @return a reference to the result, for chaining.
*/
Vector3 abs (Vector3 result);
/**
* Normalizes this vector.
*
@@ -138,12 +152,13 @@ public interface IVector3
* @return a new vector containing the result.
*/
Vector3 add (IVector3 other);
/**
* Adds a vector to this one, storing the result in the object provided.
*
* @return a reference to the result, for chaining.
*/
public IVector3 add (IVector3 other, Vector3 result);
Vector3 add (IVector3 other, Vector3 result);
/**
* Subtracts a vector from this one.
+44 -2
View File
@@ -35,17 +35,59 @@ public interface IVector4
*/
boolean epsilonEquals (IVector4 other, float epsilon);
/**
* Negates this vector.
*
* @return a new vector containing the result.
*/
Vector4 negate ();
/**
* Negates this vector, storing the result in the supplied object.
*
* @return a reference to the result, for chaining.
*/
Vector4 negate (Vector4 result);
/**
* Absolute-values this vector.
*
* @return a new vector containing the result.
*/
Vector4 abs ();
/**
* Absolute-values this vector, storing the result in the supplied object.
*
* @return a reference to the result, for chaining.
*/
Vector4 abs (Vector4 result);
/**
* Multiplies this vector by a scalar.
*
* @return a new vector containing the result.
*/
Vector4 mult (float v);
/**
* Multiplies this vector by a scalar and places the result in the supplied object.
*
* @return a reference to the result, for chaining.
*/
Vector4 mult (float v, Vector4 result);
/**
* Multiplies this vector by a matrix (V * M).
*
* @return a new vector containing the result.
*/
IVector4 mult (IMatrix4 matrix);
Vector4 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);
Vector4 mult (IMatrix4 matrix, Vector4 result);
}
+32
View File
@@ -134,6 +134,17 @@ public class Matrix3 implements IMatrix3, Serializable
0f, 0f, 1f);
}
/**
* Sets this matrix to all zeroes.
*
* @return a reference to this matrix, for chaining.
*/
public Matrix3 setToZero () {
return set(0f, 0f, 0f,
0f, 0f, 0f,
0f, 0f, 0f);
}
/**
* Sets this to a rotation matrix that rotates one vector onto another.
*
@@ -337,6 +348,15 @@ public class Matrix3 implements IMatrix3, Serializable
return mult(other, this);
}
/**
* Adds {@code other} to this matrix, in place.
*
* @return a reference to this matrix, for chaining.
*/
public Matrix3 addLocal (IMatrix3 other) {
return add(other, this);
}
/**
* Multiplies this matrix in-place by another, treating the matricees as affine.
*
@@ -552,6 +572,18 @@ public class Matrix3 implements IMatrix3, Serializable
m02*om20 + m12*om21 + m22*om22);
}
@Override // from IMatrix3
public Matrix3 add (IMatrix3 other) {
return add(other, new Matrix3());
}
@Override // from IMatrix3
public Matrix3 add (IMatrix3 other, Matrix3 result) {
return result.set(m00 + other.m00(), m01 + other.m01(), m02 + other.m02(),
m10 + other.m10(), m11 + other.m11(), m12 + other.m12(),
m20 + other.m20(), m21 + other.m21(), m22 + other.m22());
}
@Override // from IMatrix3
public boolean isAffine () {
return (m02 == 0f && m12 == 0f && m22 == 1f);
+33 -2
View File
@@ -81,6 +81,18 @@ public final class Matrix4 implements IMatrix4, Serializable
0f, 0f, 0f, 1f);
}
/**
* Sets this matrix to all zeroes.
*
* @return a reference to this matrix, for chaining.
*/
public Matrix4 setToZero () {
return set(0f, 0f, 0f, 0f,
0f, 0f, 0f, 0f,
0f, 0f, 0f, 0f,
0f, 0f, 0f, 0f);
}
/**
* Sets this to a matrix that first rotates, then translates.
*
@@ -221,6 +233,18 @@ public final class Matrix4 implements IMatrix4, Serializable
0f, 0f, 0f, 1f);
}
/**
* Sets this to a rotation plus scale matrix.
*
* @return a reference to this matrix, for chaining.
*/
public Matrix4 setToRotationScale (IMatrix3 rotScale) {
return set(rotScale.m00(), rotScale.m01(), rotScale.m02(), 0f,
rotScale.m10(), rotScale.m11(), rotScale.m12(), 0f,
rotScale.m20(), rotScale.m21(), rotScale.m22(), 0f,
0, 0, 0, 1);
}
/**
* Sets this to a scale matrix.
*
@@ -424,7 +448,7 @@ public final class Matrix4 implements IMatrix4, Serializable
}
/**
* Copies the elements of an array.
* Copies the elements of a row-major array.
*
* @return a reference to this matrix, for chaining.
*/
@@ -436,7 +460,7 @@ public final class Matrix4 implements IMatrix4, Serializable
}
/**
* Sets the contents of this matrix from the supplied buffer.
* Sets the contents of this matrix from the supplied (column-major) buffer.
*
* @return a reference to this matrix, for chaining.
*/
@@ -997,6 +1021,13 @@ public final class Matrix4 implements IMatrix4, Serializable
return result;
}
@Override // from IMatrix4
public Matrix3 extractRotationScale (Matrix3 result) {
return result.set(m00, m01, m02,
m10, m11, m12,
m20, m21, m22);
}
@Override // from IMatrix4
public Vector3 extractScale () {
return extractScale(new Vector3());
+19
View File
@@ -90,6 +90,15 @@ public class Vector3 implements IVector3, Serializable
return negate(this);
}
/**
* Absolute-values this vector in-place.
*
* @return a reference to this vector, for chaining.
*/
public Vector3 absLocal () {
return abs(this);
}
/**
* Normalizes this vector in-place.
*
@@ -241,6 +250,16 @@ public class Vector3 implements IVector3, Serializable
return result.set(-x, -y, -z);
}
@Override // from interface IVector3
public Vector3 abs () {
return abs(new Vector3());
}
@Override // from interface IVector3
public Vector3 abs (Vector3 result) {
return result.set(Math.abs(x), Math.abs(y), Math.abs(z));
}
@Override // from interface IVector3
public Vector3 normalize () {
return normalize(new Vector3());
+60 -3
View File
@@ -92,12 +92,39 @@ public class Vector4 implements IVector4, Serializable
return this;
}
/**
* Negates this vector in-place.
*
* @return a reference to this vector, for chaining.
*/
public Vector4 negateLocal () {
return negate(this);
}
/**
* Absolute-values this vector in-place.
*
* @return a reference to this vector, for chaining.
*/
public Vector4 absLocal () {
return abs(this);
}
/**
* Multiplies this vector by a scalar and stores the result back in this vector.
*
* @return a reference to this vector, for chaining.
*/
public Vector4 multLocal (float v) {
return mult(v, 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) {
public Vector4 multLocal (IMatrix4 matrix) {
return mult(matrix, this);
}
@@ -134,13 +161,43 @@ public class Vector4 implements IVector4, Serializable
Math.abs(w - other.w()) < epsilon);
}
@Override // from interface IVector4
public Vector4 negate () {
return negate(new Vector4());
}
@Override // from interface IVector4
public Vector4 negate (Vector4 result) {
return result.set(-x, -y, -z, -w);
}
@Override // from interface IVector4
public Vector4 abs () {
return abs(new Vector4());
}
@Override // from interface IVector4
public Vector4 abs (Vector4 result) {
return result.set(Math.abs(x), Math.abs(y), Math.abs(z), Math.abs(w));
}
@Override // from interface IVector4
public Vector4 mult (float v) {
return mult(v, new Vector4());
}
@Override // from interface IVector4
public Vector4 mult (float v, Vector4 result) {
return result.set(x*v, y*v, z*v, w*v);
}
@Override // from IVector4
public IVector4 mult (IMatrix4 matrix) {
public Vector4 mult (IMatrix4 matrix) {
return mult(matrix, new Vector4());
}
@Override // from IVector4
public IVector4 mult (IMatrix4 matrix, Vector4 result) {
public Vector4 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();