You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(134) |
Sep
(52) |
Oct
(13) |
Nov
(342) |
Dec
(163) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(44) |
Feb
(62) |
Mar
(158) |
Apr
(38) |
May
(70) |
Jun
(58) |
Jul
(104) |
Aug
(207) |
Sep
(83) |
Oct
(122) |
Nov
(23) |
Dec
(49) |
2004 |
Jan
(119) |
Feb
(132) |
Mar
(192) |
Apr
(140) |
May
(77) |
Jun
(74) |
Jul
(201) |
Aug
(63) |
Sep
(102) |
Oct
(70) |
Nov
(173) |
Dec
(78) |
2005 |
Jan
(174) |
Feb
(197) |
Mar
(105) |
Apr
(59) |
May
(77) |
Jun
(43) |
Jul
(21) |
Aug
(18) |
Sep
(47) |
Oct
(37) |
Nov
(74) |
Dec
(50) |
2006 |
Jan
(44) |
Feb
(19) |
Mar
(32) |
Apr
(24) |
May
(31) |
Jun
(55) |
Jul
(138) |
Aug
(28) |
Sep
(12) |
Oct
(41) |
Nov
(58) |
Dec
(24) |
2007 |
Jan
(28) |
Feb
(14) |
Mar
(10) |
Apr
(68) |
May
(30) |
Jun
(26) |
Jul
(18) |
Aug
(63) |
Sep
(19) |
Oct
(29) |
Nov
(20) |
Dec
(10) |
2008 |
Jan
(38) |
Feb
(7) |
Mar
(37) |
Apr
(120) |
May
(41) |
Jun
(36) |
Jul
(39) |
Aug
(24) |
Sep
(28) |
Oct
(30) |
Nov
(36) |
Dec
(75) |
2009 |
Jan
(46) |
Feb
(22) |
Mar
(50) |
Apr
(70) |
May
(134) |
Jun
(105) |
Jul
(75) |
Aug
(34) |
Sep
(38) |
Oct
(34) |
Nov
(19) |
Dec
(20) |
2010 |
Jan
(11) |
Feb
(20) |
Mar
(65) |
Apr
(83) |
May
(104) |
Jun
(73) |
Jul
(78) |
Aug
(57) |
Sep
(43) |
Oct
(35) |
Nov
(9) |
Dec
(4) |
2011 |
Jan
(21) |
Feb
(11) |
Mar
(18) |
Apr
(10) |
May
(18) |
Jun
(15) |
Jul
(48) |
Aug
(25) |
Sep
(17) |
Oct
(45) |
Nov
(15) |
Dec
(12) |
2012 |
Jan
(21) |
Feb
(9) |
Mar
(12) |
Apr
(9) |
May
(9) |
Jun
(5) |
Jul
(1) |
Aug
(10) |
Sep
(12) |
Oct
(1) |
Nov
(28) |
Dec
(5) |
2013 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
2016 |
Jan
(2) |
Feb
(1) |
Mar
(1) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(1) |
Aug
(2) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
|
|
|
|
1
|
2
|
3
(7) |
4
|
5
|
6
(2) |
7
(2) |
8
|
9
|
10
(3) |
11
|
12
(6) |
13
|
14
|
15
(5) |
16
(6) |
17
(1) |
18
(2) |
19
|
20
(1) |
21
|
22
(1) |
23
(3) |
24
|
25
|
26
(5) |
27
(3) |
28
(2) |
29
|
30
(6) |
|
From: <eli...@us...> - 2006-06-16 13:30:32
|
Revision: 2377 Author: elias_naur Date: 2006-06-16 06:30:27 -0700 (Fri, 16 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2377&view=rev Log Message: ----------- Added missing static methods to Quaternion for consistency. Cleaned up handling of src == dest aliasing Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/vector/Quaternion.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/vector/Quaternion.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/vector/Quaternion.java 2006-06-16 12:44:53 UTC (rev 2376) +++ trunk/LWJGL/src/java/org/lwjgl/util/vector/Quaternion.java 2006-06-16 13:30:27 UTC (rev 2377) @@ -43,16 +43,16 @@ import java.nio.FloatBuffer; public class Quaternion extends Vector implements ReadableVector4f { - private static final long serialVersionUID = 1L; - private float x, y, z, w; + public float x, y, z, w; /** - * C'tor + * C'tor. The quaternion will be initialized to the identity. */ public Quaternion() { super(); + setIdentity(); } /** @@ -124,6 +124,27 @@ } /** + * Set this quaternion to the multiplication identity. + * @return this + */ + public Quaternion setIdentity() { + return setIdentity(this); + } + + /** + * Set the given quaternion to the multiplication identity. + * @param q The quaternion + * @return q + */ + public static Quaternion setIdentity(Quaternion q) { + q.x = 0; + q.y = 0; + q.z = 0; + q.w = 1; + return q; + } + + /** * @return the length squared of the quaternion */ public float lengthSquared() { @@ -131,25 +152,39 @@ } /** - * Normalise this vector and place the result in another vector. + * Normalise the source quaternion and place the result in another quaternion. * + * @param src + * The source quaternion * @param dest - * The destination vector, or null if a new vector is to be + * The destination quaternion, or null if a new quaternion is to be * created - * @return the normalised vector + * @return The normalised quaternion */ - public Quaternion normalise(Quaternion dest) { - float l = length(); + public static Quaternion normalise(Quaternion src, Quaternion dest) { + float inv_l = 1f/src.length(); if (dest == null) - dest = new Quaternion(x / l, y / l, z / l, w / l); - else - dest.set(x / l, y / l, z / l, w / l); + dest = new Quaternion(); + dest.set(src.x * inv_l, src.y * inv_l, src.z * inv_l, src.w * inv_l); + return dest; } /** + * Normalise this quaternion and place the result in another quaternion. + * + * @param dest + * The destination quaternion, or null if a new quaternion is to be + * created + * @return the normalised quaternion + */ + public Quaternion normalise(Quaternion dest) { + return normalise(this, dest); + } + + /** * The dot product of two quaternions * * @param left @@ -171,13 +206,26 @@ * quaternion */ public Quaternion negate(Quaternion dest) { + return negate(this, dest); + } + + /** + * Calculate the conjugate of this quaternion and put it into the given one + * + * @param src + * The source quaternion + * @param dest + * The quaternion which should be set to the conjugate of this + * quaternion + */ + public static Quaternion negate(Quaternion src, Quaternion dest) { if (dest == null) dest = new Quaternion(); - dest.x = -x; - dest.y = -y; - dest.z = -z; - dest.w = w; + dest.x = -src.x; + dest.y = -src.y; + dest.z = -src.z; + dest.w = src.w; return dest; } @@ -186,11 +234,7 @@ * Calculate the conjugate of this quaternion */ public Vector negate() { - x = -x; - y = -y; - z = -z; - - return this; + return negate(this, this); } /* (non-Javadoc) @@ -210,12 +254,25 @@ * @see org.lwjgl.vector.Vector#scale(float) */ public Vector scale(float scale) { - x *= scale; - y *= scale; - z *= scale; - w *= scale; - return this; + return scale(scale, this, this); } + + /** + * Scale the source quaternion by scale and put the result in the destination + * @param scale The amount to scale by + * @param src The source quaternion + * @param dest The destination quaternion, or null if a new quaternion is to be created + * @return The scaled quaternion + */ + public static Quaternion scale(float scale, Quaternion src, Quaternion dest) { + if (dest == null) + dest = new Quaternion(); + dest.x = src.x * scale; + dest.y = src.y * scale; + dest.z = src.z * scale; + dest.w = src.w * scale; + return dest; + } /* (non-Javadoc) * @see org.lwjgl.util.vector.ReadableVector#store(java.nio.FloatBuffer) @@ -314,21 +371,14 @@ public static Quaternion mul(Quaternion left, Quaternion right, Quaternion dest) { if (dest == null) - return new Quaternion(left.x * right.w + left.w * right.x + left.y - * right.z - left.z * right.y, left.y * right.w + left.w - * right.y + left.z * right.x - left.x * right.z, left.z - * right.w + left.w * right.z + left.x * right.y - left.y - * right.x, left.w * right.w - left.x * right.x - left.y - * right.y - left.z * right.z); - else { - dest.set(left.x * right.w + left.w * right.x + left.y * right.z - - left.z * right.y, left.y * right.w + left.w * right.y - + left.z * right.x - left.x * right.z, left.z * right.w - + left.w * right.z + left.x * right.y - left.y * right.x, - left.w * right.w - left.x * right.x - left.y * right.y - - left.z * right.z); - return dest; - } + dest = new Quaternion(); + dest.set(left.x * right.w + left.w * right.x + left.y * right.z + - left.z * right.y, left.y * right.w + left.w * right.y + + left.z * right.x - left.x * right.z, left.z * right.w + + left.w * right.z + left.x * right.y - left.y * right.x, + left.w * right.w - left.x * right.x - left.y * right.y + - left.z * right.z); + return dest; } /** @@ -349,29 +399,19 @@ n = (n == 0.0 ? n : 1 / n); // store on stack once for aliasing-safty if (dest == null) - return new Quaternion((left.x * right.w - left.w * right.x - left.y - * right.z + left.z * right.y) + dest = new Quaternion(); + dest + .set((left.x * right.w - left.w * right.x - left.y + * right.z + left.z * right.y) * n, (left.y * right.w - left.w * right.y - left.z - * right.x + left.x * right.z) + * right.x + left.x * right.z) * n, (left.z * right.w - left.w * right.z - left.x - * right.y + left.y * right.x) + * right.y + left.y * right.x) * n, (left.w * right.w + left.x * right.x + left.y - * right.y + left.z * right.z) + * right.y + left.z * right.z) * n); - else { - dest - .set((left.x * right.w - left.w * right.x - left.y - * right.z + left.z * right.y) - * n, (left.y * right.w - left.w * right.y - left.z - * right.x + left.x * right.z) - * n, (left.z * right.w - left.w * right.z - left.x - * right.y + left.y * right.x) - * n, (left.w * right.w + left.x * right.x + left.y - * right.y + left.z * right.z) - * n); - return dest; - } + return dest; } /** @@ -399,29 +439,58 @@ * passed matrix. * * @param m1 - * the matrix4f + * The matrix + * @return this */ - public final void setFromMatrix(Matrix4f m1) { - setFromMat(m1.m00, m1.m01, m1.m02, m1.m10, m1.m11, m1.m12, m1.m20, - m1.m21, m1.m22); + public final Quaternion setFromMatrix(Matrix4f m) { + return setFromMatrix(m, this); } /** + * Sets the value of the source quaternion using the rotational component of the + * passed matrix. + * + * @param m + * The source matrix + * @param q + * The destination quaternion, or null if a new quaternion is to be created + * @return + */ + public final static Quaternion setFromMatrix(Matrix4f m, Quaternion q) { + return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, + m.m21, m.m22); + } + + /** * Sets the value of this quaternion using the rotational component of the * passed matrix. * - * @param m1 - * the matrix3f + * @param m + * The source matrix */ - public final void setFromMatrix(Matrix3f m1) { - setFromMat(m1.m00, m1.m01, m1.m02, m1.m10, m1.m11, m1.m12, m1.m20, - m1.m21, m1.m22); + public final Quaternion setFromMatrix(Matrix3f m) { + return setFromMatrix(m, this); } /** + * Sets the value of the source quaternion using the rotational component of the + * passed matrix. + * + * @param m + * The source matrix + * @param q + * The destination quaternion, or null if a new quaternion is to be created + * @return + */ + public static final Quaternion setFromMatrix(Matrix3f m, Quaternion q) { + return q.setFromMat(m.m00, m.m01, m.m02, m.m10, m.m11, m.m12, m.m20, + m.m21, m.m22); + } + + /** * Private method to perform the matrix-to-quaternion conversion */ - private void setFromMat(float m00, float m01, float m02, float m10, + private Quaternion setFromMat(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22) { float s; @@ -458,6 +527,6 @@ w = (m10 - m01) * s; } } + return this; } - -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-16 12:45:29
|
Revision: 2376 Author: elias_naur Date: 2006-06-16 05:44:53 -0700 (Fri, 16 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2376&view=rev Log Message: ----------- Added missing static methods to Matrix4f for consistency. Cleaned up handling of src == dest aliasing Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix3f.java trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix4f.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java 2006-06-16 08:20:21 UTC (rev 2375) +++ trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java 2006-06-16 12:44:53 UTC (rev 2376) @@ -76,7 +76,7 @@ * Copy the source matrix to the destination matrix. * @param src The source matrix * @param dest The destination matrix, or null if a new one should be created. - * @return dest + * @return The copied matrix */ public static Matrix2f load(Matrix2f src, Matrix2f dest) { if (dest == null) @@ -286,14 +286,14 @@ * @return The inverted matrix, or null if source can't be reverted. */ public static Matrix2f invert(Matrix2f src, Matrix2f dest) { - if (dest == null) - dest = new Matrix2f(); /* *inv(A) = 1/det(A) * adj(A); */ float determinant = src.determinant(); if (determinant != 0) { + if (dest == null) + dest = new Matrix2f(); float determinant_inv = 1f/determinant; float t00 = src.m11*determinant_inv; float t01 = -src.m01*determinant_inv; Modified: trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix3f.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix3f.java 2006-06-16 08:20:21 UTC (rev 2375) +++ trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix3f.java 2006-06-16 12:44:53 UTC (rev 2376) @@ -78,7 +78,7 @@ * Copy source matrix to destination matrix * @param src The source matrix * @param dest The destination matrix, or null of a new matrix is to be created - * @return dest + * @return The copied matrix */ public static Matrix3f load(Matrix3f src, Matrix3f dest) { if (dest == null) @@ -372,13 +372,15 @@ /** * Invert the source matrix and put the result into the destination matrix * @param src The source matrix to be inverted - * @param dest The destination matrix - * @return dest if successful, null otherwise + * @param dest The destination matrix, or null if a new one is to be created + * @return The inverted matrix if successful, null otherwise */ public static Matrix3f invert(Matrix3f src, Matrix3f dest) { float determinant = src.determinant(); if (determinant != 0) { + if (dest == null) + dest = new Matrix3f(); /* do it the ordinary way * * inv(A) = 1/det(A) * adj(T), where adj(T) = transpose(Conjugate Matrix) Modified: trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix4f.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix4f.java 2006-06-16 08:20:21 UTC (rev 2375) +++ trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix4f.java 2006-06-16 12:44:53 UTC (rev 2376) @@ -40,16 +40,16 @@ * @author foo */ public class Matrix4f extends Matrix implements Serializable { - private static final long serialVersionUID = 1L; - public float m00 = 1.0f, m01, m02, m03, m10, m11 = 1.0f, m12, m13, m20, m21, m22 = 1.0f, m23, m30, m31, m32, m33 = 1.0f; + public float m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33; /** - * Construct a Matrix4f + * Construct a new matrix, initialized to the identity. */ public Matrix4f() { super(); + setIdentity(); } /** @@ -69,78 +69,105 @@ * @return this */ public Matrix setIdentity() { - m00 = 1.0f; - m01 = 0.0f; - m02 = 0.0f; - m03 = 0.0f; - m10 = 0.0f; - m11 = 1.0f; - m12 = 0.0f; - m13 = 0.0f; - m20 = 0.0f; - m21 = 0.0f; - m22 = 1.0f; - m23 = 0.0f; - m30 = 0.0f; - m31 = 0.0f; - m32 = 0.0f; - m33 = 1.0f; + return setIdentity(this); + } + + /** + * Set the given matrix to be the identity matrix. + * @param m The matrix to set to the identity + * @return m + */ + public static Matrix4f setIdentity(Matrix4f m) { + m.m00 = 1.0f; + m.m01 = 0.0f; + m.m02 = 0.0f; + m.m03 = 0.0f; + m.m10 = 0.0f; + m.m11 = 1.0f; + m.m12 = 0.0f; + m.m13 = 0.0f; + m.m20 = 0.0f; + m.m21 = 0.0f; + m.m22 = 1.0f; + m.m23 = 0.0f; + m.m30 = 0.0f; + m.m31 = 0.0f; + m.m32 = 0.0f; + m.m33 = 1.0f; - return this; + return m; } - /** * Set this matrix to 0. * @return this */ public Matrix setZero() { - m00 = 0.0f; - m01 = 0.0f; - m02 = 0.0f; - m03 = 0.0f; - m10 = 0.0f; - m11 = 0.0f; - m12 = 0.0f; - m13 = 0.0f; - m20 = 0.0f; - m21 = 0.0f; - m22 = 0.0f; - m23 = 0.0f; - m30 = 0.0f; - m31 = 0.0f; - m32 = 0.0f; - m33 = 0.0f; + return setZero(this); + } + + /** + * Set the given matrix to 0. + * @param m The matrix to set to 0 + * @return m + */ + public static Matrix4f setZero(Matrix4f m) { + m.m00 = 0.0f; + m.m01 = 0.0f; + m.m02 = 0.0f; + m.m03 = 0.0f; + m.m10 = 0.0f; + m.m11 = 0.0f; + m.m12 = 0.0f; + m.m13 = 0.0f; + m.m20 = 0.0f; + m.m21 = 0.0f; + m.m22 = 0.0f; + m.m23 = 0.0f; + m.m30 = 0.0f; + m.m31 = 0.0f; + m.m32 = 0.0f; + m.m33 = 0.0f; - return this; + return m; } - /** * Load from another matrix4f * @param src The source matrix * @return this */ public Matrix4f load(Matrix4f src) { + return load(src, this); + } + + /** + * Copy the source matrix to the destination matrix + * @param src The source matrix + * @param dest The destination matrix, or null of a new one is to be created + * @return The copied matrix + */ + public static Matrix4f load(Matrix4f src, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + dest.m00 = src.m00; + dest.m01 = src.m01; + dest.m02 = src.m02; + dest.m03 = src.m03; + dest.m10 = src.m10; + dest.m11 = src.m11; + dest.m12 = src.m12; + dest.m13 = src.m13; + dest.m20 = src.m20; + dest.m21 = src.m21; + dest.m22 = src.m22; + dest.m23 = src.m23; + dest.m30 = src.m30; + dest.m31 = src.m31; + dest.m32 = src.m32; + dest.m33 = src.m33; - m00 = src.m00; - m01 = src.m01; - m02 = src.m02; - m03 = src.m03; - m10 = src.m10; - m11 = src.m11; - m12 = src.m12; - m13 = src.m13; - m20 = src.m20; - m21 = src.m21; - m22 = src.m22; - m23 = src.m23; - m30 = src.m30; - m31 = src.m31; - m32 = src.m32; - m33 = src.m33; - - return this; + return dest; } /** @@ -260,15 +287,8 @@ * @return the destination matrix */ public static Matrix4f add(Matrix4f left, Matrix4f right, Matrix4f dest) { - - Matrix4f temp = null; - if (dest == null) dest = new Matrix4f(); - else if (dest == left || dest == right) { - temp = dest; - dest = new Matrix4f(); - } dest.m00 = left.m00 + right.m00; dest.m01 = left.m01 + right.m01; @@ -286,13 +306,8 @@ dest.m31 = left.m31 + right.m31; dest.m32 = left.m32 + right.m32; dest.m33 = left.m33 + right.m33; - - - if (temp != null) { - temp.load(dest); - return temp; - } else - return dest; + + return dest; } /** @@ -303,15 +318,8 @@ * @return the destination matrix */ public static Matrix4f sub(Matrix4f left, Matrix4f right, Matrix4f dest) { - - Matrix4f temp = null; - if (dest == null) dest = new Matrix4f(); - else if (dest == left || dest == right) { - temp = dest; - dest = new Matrix4f(); - } dest.m00 = left.m00 - right.m00; dest.m01 = left.m01 - right.m01; @@ -330,11 +338,7 @@ dest.m32 = left.m32 - right.m32; dest.m33 = left.m33 - right.m33; - if (temp != null) { - temp.load(dest); - return temp; - } else - return dest; + return dest; } /** @@ -345,39 +349,44 @@ * @return the destination matrix */ public static Matrix4f mul(Matrix4f left, Matrix4f right, Matrix4f dest) { - - Matrix4f temp = null; - if (dest == null) dest = new Matrix4f(); - else if (dest == left || dest == right) { - temp = dest; - dest = new Matrix4f(); - } - - - dest.m00 = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02 + left.m30 * right.m03; - dest.m01 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02 + left.m31 * right.m03; - dest.m02 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02 + left.m32 * right.m03; - dest.m03 = left.m03 * right.m00 + left.m13 * right.m01 + left.m23 * right.m02 + left.m33 * right.m03; - dest.m10 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12 + left.m30 * right.m13; - dest.m11 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12 + left.m31 * right.m13; - dest.m12 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12 + left.m32 * right.m13; - dest.m13 = left.m03 * right.m10 + left.m13 * right.m11 + left.m23 * right.m12 + left.m33 * right.m13; - dest.m20 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22 + left.m30 * right.m23; - dest.m21 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22 + left.m31 * right.m23; - dest.m22 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22 + left.m32 * right.m23; - dest.m23 = left.m03 * right.m20 + left.m13 * right.m21 + left.m23 * right.m22 + left.m33 * right.m23; - dest.m30 = left.m00 * right.m30 + left.m10 * right.m31 + left.m20 * right.m32 + left.m30 * right.m33; - dest.m31 = left.m01 * right.m30 + left.m11 * right.m31 + left.m21 * right.m32 + left.m31 * right.m33; - dest.m32 = left.m02 * right.m30 + left.m12 * right.m31 + left.m22 * right.m32 + left.m32 * right.m33; - dest.m33 = left.m03 * right.m30 + left.m13 * right.m31 + left.m23 * right.m32 + left.m33 * right.m33; - if (temp != null) { - temp.load(dest); - return temp; - } else - return dest; + float m00 = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02 + left.m30 * right.m03; + float m01 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02 + left.m31 * right.m03; + float m02 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02 + left.m32 * right.m03; + float m03 = left.m03 * right.m00 + left.m13 * right.m01 + left.m23 * right.m02 + left.m33 * right.m03; + float m10 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12 + left.m30 * right.m13; + float m11 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12 + left.m31 * right.m13; + float m12 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12 + left.m32 * right.m13; + float m13 = left.m03 * right.m10 + left.m13 * right.m11 + left.m23 * right.m12 + left.m33 * right.m13; + float m20 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22 + left.m30 * right.m23; + float m21 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22 + left.m31 * right.m23; + float m22 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22 + left.m32 * right.m23; + float m23 = left.m03 * right.m20 + left.m13 * right.m21 + left.m23 * right.m22 + left.m33 * right.m23; + float m30 = left.m00 * right.m30 + left.m10 * right.m31 + left.m20 * right.m32 + left.m30 * right.m33; + float m31 = left.m01 * right.m30 + left.m11 * right.m31 + left.m21 * right.m32 + left.m31 * right.m33; + float m32 = left.m02 * right.m30 + left.m12 * right.m31 + left.m22 * right.m32 + left.m32 * right.m33; + float m33 = left.m03 * right.m30 + left.m13 * right.m31 + left.m23 * right.m32 + left.m33 * right.m33; + + dest.m00 = m00; + dest.m01 = m01; + dest.m02 = m02; + dest.m03 = m03; + dest.m10 = m10; + dest.m11 = m11; + dest.m12 = m12; + dest.m13 = m13; + dest.m20 = m20; + dest.m21 = m21; + dest.m22 = m22; + dest.m23 = m23; + dest.m30 = m30; + dest.m31 = m31; + dest.m32 = m32; + dest.m33 = m33; + + return dest; } /** @@ -389,27 +398,20 @@ * @return the destination vector */ public static Vector4f transform(Matrix4f left, Vector4f right, Vector4f dest) { - - Vector4f temp = null; - if (dest == null) dest = new Vector4f(); - else if (dest == right) { - temp = dest; - dest = new Vector4f(); - } - - - dest.x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z + left.m30 * right.w; - dest.y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z + left.m31 * right.w; - dest.z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z + left.m32 * right.w; - dest.w = left.m03 * right.x + left.m13 * right.y + left.m23 * right.z + left.m33 * right.w; - if (temp != null) { - temp.set(dest); - return temp; - } else - return dest; + float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z + left.m30 * right.w; + float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z + left.m31 * right.w; + float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z + left.m32 * right.w; + float w = left.m03 * right.x + left.m13 * right.y + left.m23 * right.z + left.m33 * right.w; + + dest.x = x; + dest.y = y; + dest.z = z; + dest.w = w; + + return dest; } /** @@ -417,27 +419,7 @@ * @return this */ public Matrix transpose() { - - float f = m10; - m10 = m01; - m01 = f; - f = m20; - m20 = m02; - m02 = f; - f = m30; - m30 = m03; - m03 = f; - f = m21; - m21 = m12; - m12 = f; - f = m31; - m31 = m13; - m13 = f; - f = m32; - m32 = m23; - m23 = f; - - return this; + return transpose(this); } /** @@ -446,11 +428,7 @@ * @return this */ public Matrix4f translate(Vector2f vec) { - m30 += m00 * vec.x + m10 * vec.y; - m31 += m01 * vec.x + m11 * vec.y; - m32 += m02 * vec.x + m12 * vec.y; - m33 += m03 * vec.x + m13 * vec.y; - return this; + return translate(vec, this); } /** @@ -459,11 +437,7 @@ * @return this */ public Matrix4f translate(Vector3f vec) { - m30 += m00 * vec.x + m10 * vec.y + m20 * vec.z; - m31 += m01 * vec.x + m11 * vec.y + m21 * vec.z; - m32 += m02 * vec.x + m12 * vec.y + m22 * vec.z; - m33 += m03 * vec.x + m13 * vec.y + m23 * vec.z; - return this; + return translate(vec, this); } /** @@ -472,20 +446,33 @@ * @return this */ public Matrix4f scale(Vector3f vec) { - m00 *= vec.x; - m01 *= vec.x; - m02 *= vec.x; - m03 *= vec.x; - m10 *= vec.y; - m11 *= vec.y; - m12 *= vec.y; - m13 *= vec.y; - m20 *= vec.z; - m21 *= vec.z; - m22 *= vec.z; - m23 *= vec.z; - return this; + return scale(vec, this, this); } + + /** + * Scales the source matrix and put the result in the destination matrix + * @param vec The vector to scale by + * @param src The source matrix + * @param dest The destination matrix, or null if a new matrix is to be created + * @return The scaled matrix + */ + public static Matrix4f scale(Vector3f vec, Matrix4f src, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); + dest.m00 = src.m00 * vec.x; + dest.m01 = src.m01 * vec.x; + dest.m02 = src.m02 * vec.x; + dest.m03 = src.m03 * vec.x; + dest.m10 = src.m10 * vec.y; + dest.m11 = src.m11 * vec.y; + dest.m12 = src.m12 * vec.y; + dest.m13 = src.m13 * vec.y; + dest.m20 = src.m20 * vec.z; + dest.m21 = src.m21 * vec.z; + dest.m22 = src.m22 * vec.z; + dest.m23 = src.m23 * vec.z; + return dest; + } /** * Rotates the matrix around the given axis the specified angle @@ -494,6 +481,32 @@ * @return this */ public Matrix4f rotate(float angle, Vector3f axis) { + return rotate(angle, axis, this); + } + + /** + * Rotates the matrix around the given axis the specified angle + * @param angle the angle, in radians. + * @param axis The vector representing the rotation axis. Must be normalized. + * @param dest The matrix to put the result, or null if a new matrix is to be created + * @return The rotated matrix + */ + public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) { + return rotate(angle, axis, this, dest); + } + + /** + * Rotates the source matrix around the given axis the specified angle and + * put the result in the destination matrix. + * @param angle the angle, in radians. + * @param axis The vector representing the rotation axis. Must be normalized. + * @param src The matrix to rotate + * @param dest The matrix to put the result, or null if a new matrix is to be created + * @return The rotated matrix + */ + public static Matrix4f rotate(float angle, Vector3f axis, Matrix4f src, Matrix4f dest) { + if (dest == null) + dest = new Matrix4f(); float c = (float) Math.cos(angle); float s = (float) Math.sin(angle); float oneminusc = 1.0f - c; @@ -516,95 +529,54 @@ float f21 = yz*oneminusc-xs; float f22 = axis.z*axis.z*oneminusc+c; - float t00 = m00 * f00 + m10 * f01 + m20 * f02; - float t01 = m01 * f00 + m11 * f01 + m21 * f02; - float t02 = m02 * f00 + m12 * f01 + m22 * f02; - float t03 = m03 * f00 + m13 * f01 + m23 * f02; - float t10 = m00 * f10 + m10 * f11 + m20 * f12; - float t11 = m01 * f10 + m11 * f11 + m21 * f12; - float t12 = m02 * f10 + m12 * f11 + m22 * f12; - float t13 = m03 * f10 + m13 * f11 + m23 * f12; - m20 = m00 * f20 + m10 * f21 + m20 * f22; - m21 = m01 * f20 + m11 * f21 + m21 * f22; - m22 = m02 * f20 + m12 * f21 + m22 * f22; - m23 = m03 * f20 + m13 * f21 + m23 * f22; - m00 = t00; - m01 = t01; - m02 = t02; - m03 = t03; - m10 = t10; - m11 = t11; - m12 = t12; - m13 = t13; - return this; + float t00 = src.m00 * f00 + src.m10 * f01 + src.m20 * f02; + float t01 = src.m01 * f00 + src.m11 * f01 + src.m21 * f02; + float t02 = src.m02 * f00 + src.m12 * f01 + src.m22 * f02; + float t03 = src.m03 * f00 + src.m13 * f01 + src.m23 * f02; + float t10 = src.m00 * f10 + src.m10 * f11 + src.m20 * f12; + float t11 = src.m01 * f10 + src.m11 * f11 + src.m21 * f12; + float t12 = src.m02 * f10 + src.m12 * f11 + src.m22 * f12; + float t13 = src.m03 * f10 + src.m13 * f11 + src.m23 * f12; + dest.m20 = src.m00 * f20 + src.m10 * f21 + src.m20 * f22; + dest.m21 = src.m01 * f20 + src.m11 * f21 + src.m21 * f22; + dest.m22 = src.m02 * f20 + src.m12 * f21 + src.m22 * f22; + dest.m23 = src.m03 * f20 + src.m13 * f21 + src.m23 * f22; + dest.m00 = t00; + dest.m01 = t01; + dest.m02 = t02; + dest.m03 = t03; + dest.m10 = t10; + dest.m11 = t11; + dest.m12 = t12; + dest.m13 = t13; + return dest; } /** - * Rotates the matrix around the given axis the specified angle, and stores it in the specified destination - * @param angle the angle, in radians. - * @param axis The vector representing the rotation axis. Must be normalized. + * Translate this matrix and stash the result in another matrix + * @param vec The vector to translate by * @param dest The destination matrix or null if a new matrix is to be created - * @return The rotated matrix + * @return the translated matrix */ - public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) { - if (dest == null) - dest = new Matrix4f(); - else if (dest == this) - return rotate(angle, axis); - float c = (float) Math.cos(angle); - float s = (float) Math.sin(angle); - float oneminusc = 1.0f - c; - float xy = axis.x*axis.y; - float yz = axis.y*axis.z; - float xz = axis.x*axis.z; - float xs = axis.x*s; - float ys = axis.y*s; - float zs = axis.z*s; - - float f0 = axis.x*axis.x*oneminusc+c; - float f1 = xy*oneminusc+zs; - float f2 = xz*oneminusc-ys; - // n[3] not used - float f4 = xy*oneminusc-zs; - float f5 = axis.y*axis.y*oneminusc+c; - float f6 = yz*oneminusc+xs; - // n[7] not used - float f8 = xz*oneminusc+ys; - float f9 = yz*oneminusc-xs; - float f10 = axis.z*axis.z*oneminusc+c; - - /* m[12] to m[15] are not changed by a rotate */ - dest.m00 = m00 * f0 + m10 * f1 + m20 * f2; - dest.m01 = m01 * f0 + m11 * f1 + m21 * f2; - dest.m02 = m02 * f0 + m12 * f1 + m22 * f2; - dest.m03 = m03 * f0 + m13 * f1 + m23 * f2; - dest.m10 = m00 * f4 + m10 * f5 + m20 * f6; - dest.m11 = m01 * f4 + m11 * f5 + m21 * f6; - dest.m12 = m02 * f4 + m12 * f5 + m22 * f6; - dest.m13 = m03 * f4 + m13 * f5 + m23 * f6; - dest.m20 = m00 * f8 + m10 * f9 + m20 * f10; - dest.m21 = m01 * f8 + m11 * f9 + m21 * f10; - dest.m22 = m02 * f8 + m12 * f9 + m22 * f10; - dest.m23 = m03 * f8 + m13 * f9 + m23 * f10; - return dest; + public Matrix4f translate(Vector3f vec, Matrix4f dest) { + return translate(vec, this, dest); } /** - * Translate this matrix and stash the result in another matrix + * Translate the source matrix and stash the result in the destination matrix * @param vec The vector to translate by + * @param src The source matrix * @param dest The destination matrix or null if a new matrix is to be created - * @return the translated matrix + * @return The translated matrix */ - public Matrix4f translate(Vector3f vec, Matrix4f dest) { + public static Matrix4f translate(Vector3f vec, Matrix4f src, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); - else if (dest == this) - return translate(vec); - dest.m30 += m00 * vec.x + m10 * vec.y + m20 * vec.z; - dest.m31 += m01 * vec.x + m11 * vec.y + m21 * vec.z; - dest.m32 += m02 * vec.x + m12 * vec.y + m22 * vec.z; - dest.m33 += m03 * vec.x + m13 * vec.y + m23 * vec.z; + dest.m30 += src.m00 * vec.x + src.m10 * vec.y + src.m20 * vec.z; + dest.m31 += src.m01 * vec.x + src.m11 * vec.y + src.m21 * vec.z; + dest.m32 += src.m02 * vec.x + src.m12 * vec.y + src.m22 * vec.z; + dest.m33 += src.m03 * vec.x + src.m13 * vec.y + src.m23 * vec.z; return dest; } @@ -616,57 +588,83 @@ * @return the translated matrix */ public Matrix4f translate(Vector2f vec, Matrix4f dest) { + return translate(vec, this, dest); + } + + /** + * Translate the source matrix and stash the result in the destination matrix + * @param vec The vector to translate by + * @param src The source matrix + * @param dest The destination matrix or null if a new matrix is to be created + * @return The translated matrix + */ + public static Matrix4f translate(Vector2f vec, Matrix4f src, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); - else if (dest == this) - return translate(vec); - dest.m30 += m00 * vec.x + m10 * vec.y; - dest.m31 += m01 * vec.x + m11 * vec.y; - dest.m32 += m02 * vec.x + m12 * vec.y; - dest.m33 += m03 * vec.x + m13 * vec.y; + dest.m30 += src.m00 * vec.x + src.m10 * vec.y; + dest.m31 += src.m01 * vec.x + src.m11 * vec.y; + dest.m32 += src.m02 * vec.x + src.m12 * vec.y; + dest.m33 += src.m03 * vec.x + src.m13 * vec.y; return dest; } - - /** * Transpose this matrix and place the result in another matrix * @param dest The destination matrix or null if a new matrix is to be created * @return the transposed matrix */ public Matrix4f transpose(Matrix4f dest) { - if (dest == null) { - // New matrix needed to store transpose + return transpose(this, dest); + } + + /** + * Transpose the source matrix and place the result in the destination matrix + * @param src The source matrix + * @param dest The destination matrix or null if a new matrix is to be created + * @return the transposed matrix + */ + public static Matrix4f transpose(Matrix4f src, Matrix4f dest) { + if (dest == null) dest = new Matrix4f(); - } - if (this == dest) { - // Destination and source are the same! Run the in-place - // transpose instead as the copy transpose will be destructive. - transpose(); - } else { - // Destination differs from source. Perform copy transpose - dest.m00 = m00; - dest.m01 = m10; - dest.m02 = m20; - dest.m03 = m30; - dest.m10 = m01; - dest.m11 = m11; - dest.m12 = m21; - dest.m13 = m31; - dest.m20 = m02; - dest.m21 = m12; - dest.m22 = m22; - dest.m23 = m32; - dest.m30 = m03; - dest.m31 = m13; - dest.m32 = m23; - dest.m33 = m33; - } - return dest; - } + float m00 = src.m00; + float m01 = src.m10; + float m02 = src.m20; + float m03 = src.m30; + float m10 = src.m01; + float m11 = src.m11; + float m12 = src.m21; + float m13 = src.m31; + float m20 = src.m02; + float m21 = src.m12; + float m22 = src.m22; + float m23 = src.m32; + float m30 = src.m03; + float m31 = src.m13; + float m32 = src.m23; + float m33 = src.m33; + dest.m00 = m00; + dest.m01 = m01; + dest.m02 = m02; + dest.m03 = m03; + dest.m10 = m10; + dest.m11 = m11; + dest.m12 = m12; + dest.m13 = m13; + dest.m20 = m20; + dest.m21 = m21; + dest.m22 = m22; + dest.m23 = m23; + dest.m30 = m30; + dest.m31 = m31; + dest.m32 = m32; + dest.m33 = m33; + + return dest; + } + /** * @return the determinant of the matrix */ @@ -700,7 +698,7 @@ * @return result */ - private float determinant3x3(float t00, float t01, float t02, + private static float determinant3x3(float t00, float t01, float t02, float t10, float t11, float t12, float t20, float t21, float t22) { @@ -714,58 +712,68 @@ * @return this if successful, null otherwise */ public Matrix invert() { + return invert(this, this); + } + + /** + * Invert the source matrix and put the result in the destination + * @param src The source matrix + * @param dest The destination matrix, or null if a new matrix is to be created + * @return The inverted matrix if successful, null otherwise + */ + public static Matrix4f invert(Matrix4f src, Matrix4f dest) { + float determinant = src.determinant(); - float determinant = determinant(); - - if (determinant != 0) - { + if (determinant != 0) { /* * m00 m01 m02 m03 * m10 m11 m12 m13 * m20 m21 m22 m23 * m30 m31 m32 m33 */ + if (dest == null) + dest = new Matrix4f(); float determinant_inv = 1f/determinant; // first row - float t00 = determinant3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33); - float t01 = -determinant3x3(m10, m12, m13, m20, m22, m23, m30, m32, m33); - float t02 = determinant3x3(m10, m11, m13, m20, m21, m23, m30, m31, m33); - float t03 = -determinant3x3(m10, m11, m12, m20, m21, m22, m30, m31, m32); + float t00 = determinant3x3(src.m11, src.m12, src.m13, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33); + float t01 = -determinant3x3(src.m10, src.m12, src.m13, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33); + float t02 = determinant3x3(src.m10, src.m11, src.m13, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33); + float t03 = -determinant3x3(src.m10, src.m11, src.m12, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32); // second row - float t10 = -determinant3x3(m01, m02, m03, m21, m22, m23, m31, m32, m33); - float t11 = determinant3x3(m00, m02, m03, m20, m22, m23, m30, m32, m33); - float t12 = -determinant3x3(m00, m01, m03, m20, m21, m23, m30, m31, m33); - float t13 = determinant3x3(m00, m01, m02, m20, m21, m22, m30, m31, m32); + float t10 = -determinant3x3(src.m01, src.m02, src.m03, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33); + float t11 = determinant3x3(src.m00, src.m02, src.m03, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33); + float t12 = -determinant3x3(src.m00, src.m01, src.m03, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33); + float t13 = determinant3x3(src.m00, src.m01, src.m02, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32); // third row - float t20 = determinant3x3(m01, m02, m03, m11, m12, m13, m31, m32, m33); - float t21 = -determinant3x3(m00, m02, m03, m10, m12, m13, m30, m32, m33); - float t22 = determinant3x3(m00, m01, m03, m10, m11, m13, m30, m31, m33); - float t23 = -determinant3x3(m00, m01, m02, m10, m11, m12, m30, m31, m32); + float t20 = determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m31, src.m32, src.m33); + float t21 = -determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m30, src.m32, src.m33); + float t22 = determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m30, src.m31, src.m33); + float t23 = -determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m30, src.m31, src.m32); // fourth row - float t30 = -determinant3x3(m01, m02, m03, m11, m12, m13, m21, m22, m23); - float t31 = determinant3x3(m00, m02, m03, m10, m12, m13, m20, m22, m23); - float t32 = -determinant3x3(m00, m01, m03, m10, m11, m13, m20, m21, m23); - float t33 = determinant3x3(m00, m01, m02, m10, m11, m12, m20, m21, m22); + float t30 = -determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m21, src.m22, src.m23); + float t31 = determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m20, src.m22, src.m23); + float t32 = -determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m20, src.m21, src.m23); + float t33 = determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m20, src.m21, src.m22); // transpose and divide by the determinant - m00 = t00*determinant_inv; - m11 = t11*determinant_inv; - m22 = t22*determinant_inv; - m33 = t33*determinant_inv; - m01 = t10*determinant_inv; - m10 = t01*determinant_inv; - m20 = t02*determinant_inv; - m02 = t20*determinant_inv; - m12 = t21*determinant_inv; - m21 = t12*determinant_inv; - m03 = t30*determinant_inv; - m30 = t03*determinant_inv; - m13 = t31*determinant_inv; - m31 = t13*determinant_inv; - m32 = t23*determinant_inv; - m23 = t32*determinant_inv; - return this; + dest.m00 = t00*determinant_inv; + dest.m11 = t11*determinant_inv; + dest.m22 = t22*determinant_inv; + dest.m33 = t33*determinant_inv; + dest.m01 = t10*determinant_inv; + dest.m10 = t01*determinant_inv; + dest.m20 = t02*determinant_inv; + dest.m02 = t20*determinant_inv; + dest.m12 = t21*determinant_inv; + dest.m21 = t12*determinant_inv; + dest.m03 = t30*determinant_inv; + dest.m30 = t03*determinant_inv; + dest.m13 = t31*determinant_inv; + dest.m31 = t13*determinant_inv; + dest.m32 = t23*determinant_inv; + dest.m23 = t32*determinant_inv; + return dest; } else return null; } @@ -775,23 +783,7 @@ * @return this */ public Matrix negate() { - m00 = -m00; - m01 = -m01; - m02 = -m02; - m03 = -m03; - m10 = -m10; - m11 = -m11; - m12 = -m12; - m13 = -m13; - m20 = -m20; - m21 = -m21; - m22 = -m22; - m23 = -m23; - m30 = -m30; - m31 = -m31; - m32 = -m32; - m33 = -m33; - return this; + return negate(this); } /** @@ -800,27 +792,36 @@ * @return the negated matrix */ public Matrix4f negate(Matrix4f dest) { + return negate(this, this); + } + + /** + * Negate this matrix and place the result in a destination matrix. + * @param src The source matrix + * @param dest The destination matrix, or null if a new matrix is to be created + * @return The negated matrix + */ + public static Matrix4f negate(Matrix4f src, Matrix4f dest) { if (dest == null) dest = new Matrix4f(); - dest.m00 = -m00; - dest.m01 = -m01; - dest.m02 = -m02; - dest.m03 = -m03; - dest.m10 = -m10; - dest.m11 = -m11; - dest.m12 = -m12; - dest.m13 = -m13; - dest.m20 = -m20; - dest.m21 = -m21; - dest.m22 = -m22; - dest.m23 = -m23; - dest.m30 = -m30; - dest.m31 = -m31; - dest.m32 = -m32; - dest.m33 = -m33; + dest.m00 = -src.m00; + dest.m01 = -src.m01; + dest.m02 = -src.m02; + dest.m03 = -src.m03; + dest.m10 = -src.m10; + dest.m11 = -src.m11; + dest.m12 = -src.m12; + dest.m13 = -src.m13; + dest.m20 = -src.m20; + dest.m21 = -src.m21; + dest.m22 = -src.m22; + dest.m23 = -src.m23; + dest.m30 = -src.m30; + dest.m31 = -src.m31; + dest.m32 = -src.m32; + dest.m33 = -src.m33; return dest; } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-16 08:20:29
|
Revision: 2375 Author: elias_naur Date: 2006-06-16 01:20:21 -0700 (Fri, 16 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2375&view=rev Log Message: ----------- Added missing static methods to Matrix3f for consistency. Cleaned up handling of src == dest aliasing Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix3f.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java 2006-06-16 07:54:47 UTC (rev 2374) +++ trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java 2006-06-16 08:20:21 UTC (rev 2375) @@ -73,10 +73,10 @@ } /** - * Copy src matrix to the dest matrix. + * Copy the source matrix to the destination matrix. * @param src The source matrix * @param dest The destination matrix, or null if a new one should be created. - * @return this + * @return dest */ public static Matrix2f load(Matrix2f src, Matrix2f dest) { if (dest == null) @@ -253,7 +253,7 @@ } /** - * Transpose source matrix and place the result in dest matrix. + * Transpose the source matrix and place the result in the destination matrix. * @param src The source matrix or null if a new matrix is to be created * @param dest The destination matrix or null if a new matrix is to be created * @return the transposed matrix @@ -280,19 +280,19 @@ } /** - * Invert the source matrix and place the result in the dest matrix. + * Invert the source matrix and place the result in the destination matrix. * @param src The source matrix to be inverted * @param dest The destination matrix or null if a new matrix is to be created * @return The inverted matrix, or null if source can't be reverted. */ - public Matrix2f invert(Matrix2f src, Matrix2f dest) { + public static Matrix2f invert(Matrix2f src, Matrix2f dest) { if (dest == null) dest = new Matrix2f(); /* *inv(A) = 1/det(A) * adj(A); */ - float determinant = determinant(); + float determinant = src.determinant(); if (determinant != 0) { float determinant_inv = 1f/determinant; float t00 = src.m11*determinant_inv; @@ -337,7 +337,7 @@ } /** - * Negate src matrix and stash the result in dest matrix. + * Negate the source matrix and stash the result in the destination matrix. * @param src The source matrix to be negated * @param dest The destination matrix, or null if a new matrix is to be created * @return the negated matrix @@ -363,7 +363,7 @@ } /** - * Set the ssrc matrix to be the identity matrix. + * Set the source matrix to be the identity matrix. * @param src The matrix to set to the identity. * @return The source matrix */ Modified: trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix3f.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix3f.java 2006-06-16 07:54:47 UTC (rev 2374) +++ trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix3f.java 2006-06-16 08:20:21 UTC (rev 2375) @@ -47,40 +47,54 @@ private static final long serialVersionUID = 1L; - public float m00 = 1.0f, + public float m00, m01, m02, m10, - m11 = 1.0f, + m11, m12, m20, m21, - m22 = 1.0f; + m22; /** - * Constructor for Matrix3f. + * Constructor for Matrix3f. Matrix is initialised to the identity. */ public Matrix3f() { super(); + setIdentity(); } + /** - * Load from another matrix3f + * Load from another matrix * @param src The source matrix * @return this */ public Matrix3f load(Matrix3f src) { + return load(src, this); + } + + /** + * Copy source matrix to destination matrix + * @param src The source matrix + * @param dest The destination matrix, or null of a new matrix is to be created + * @return dest + */ + public static Matrix3f load(Matrix3f src, Matrix3f dest) { + if (dest == null) + dest = new Matrix3f(); - m00 = src.m00; - m10 = src.m10; - m20 = src.m20; - m01 = src.m01; - m11 = src.m11; - m21 = src.m21; - m02 = src.m02; - m12 = src.m12; - m22 = src.m22; + dest.m00 = src.m00; + dest.m10 = src.m10; + dest.m20 = src.m20; + dest.m01 = src.m01; + dest.m11 = src.m11; + dest.m21 = src.m21; + dest.m02 = src.m02; + dest.m12 = src.m12; + dest.m22 = src.m22; - return this; + return dest; } /** @@ -162,8 +176,6 @@ buf.put(m22); return this; } - - /** * Add two matrices together and place the result in a third matrix. @@ -173,15 +185,8 @@ * @return the destination matrix */ public static Matrix3f add(Matrix3f left, Matrix3f right, Matrix3f dest) { - - Matrix3f temp = null; - if (dest == null) dest = new Matrix3f(); - else if (dest == left || dest == right) { - temp = dest; - dest = new Matrix3f(); - } dest.m00 = left.m00 + right.m00; dest.m01 = left.m01 + right.m01; @@ -193,11 +198,7 @@ dest.m21 = left.m21 + right.m21; dest.m22 = left.m22 + right.m22; - if (temp != null) { - temp.load(dest); - return temp; - } else - return dest; + return dest; } /** @@ -208,15 +209,8 @@ * @return the destination matrix */ public static Matrix3f sub(Matrix3f left, Matrix3f right, Matrix3f dest) { - - Matrix3f temp = null; - if (dest == null) dest = new Matrix3f(); - else if (dest == left || dest == right) { - temp = dest; - dest = new Matrix3f(); - } dest.m00 = left.m00 - right.m00; dest.m01 = left.m01 - right.m01; @@ -228,11 +222,7 @@ dest.m21 = left.m21 - right.m21; dest.m22 = left.m22 - right.m22; - if (temp != null) { - temp.load(dest); - return temp; - } else - return dest; + return dest; } /** @@ -243,40 +233,39 @@ * @return the destination matrix */ public static Matrix3f mul(Matrix3f left, Matrix3f right, Matrix3f dest) { - - Matrix3f temp = null; - if (dest == null) dest = new Matrix3f(); - else if (dest == left || dest == right) { - temp = dest; - dest = new Matrix3f(); - } - dest.m00 = + float m00 = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02; - dest.m01 = + float m01 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02; - dest.m02 = + float m02 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02; - dest.m10 = + float m10 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12; - dest.m11 = + float m11 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12; - dest.m12 = + float m12 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12; - dest.m20 = + float m20 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22; - dest.m21 = + float m21 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22; - dest.m22 = + float m22 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22; - if (temp != null) { - temp.load(dest); - return temp; - } else - return dest; + dest.m00 = m00; + dest.m01 = m01; + dest.m02 = m02; + dest.m10 = m10; + dest.m11 = m11; + dest.m12 = m12; + dest.m20 = m20; + dest.m21 = m21; + dest.m22 = m22; + + return dest; } /** @@ -288,25 +277,18 @@ * @return the destination vector */ public static Vector3f transform(Matrix3f left, Vector3f right, Vector3f dest) { - - Vector3f temp = null; - if (dest == null) dest = new Vector3f(); - else if (dest == right) { - temp = dest; - dest = new Vector3f(); - } - dest.x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z; - dest.y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z; - dest.z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z; + float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z; + float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z; + float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z; - if (temp != null) { - temp.set(dest); - return temp; - } else - return dest; + dest.x = x; + dest.y = y; + dest.z = z; + + return dest; } /** @@ -314,16 +296,7 @@ * @return this */ public Matrix transpose() { - float f = m10; - m10 = m01; - m01 = f; - f = m20; - m20 = m02; - m02 = f; - f = m21; - m21 = m12; - m12 = f; - return this; + return transpose(this, this); } /** @@ -332,26 +305,37 @@ * @return the transposed matrix */ public Matrix3f transpose(Matrix3f dest) { - if (dest == null) { - // New matrix needed to store transpose + return transpose(this, dest); + } + + /** + * Transpose the source matrix and place the result into the destination matrix + * @param src The source matrix to be transposed + * @param dest The destination matrix or null if a new matrix is to be created + * @return the transposed matrix + */ + public static Matrix3f transpose(Matrix3f src, Matrix3f dest) { + if (dest == null) dest = new Matrix3f(); - } - if (this == dest) { - // Destination and source are the same! Run the in-place - // transpose instead as the copy transpose will be destructive. - transpose(); - } else { - // Destination differs from source. Perform copy transpose - dest.m00 = m00; - dest.m01 = m10; - dest.m02 = m20; - dest.m10 = m01; - dest.m11 = m11; - dest.m12 = m21; - dest.m20 = m02; - dest.m21 = m12; - dest.m22 = m22; - } + float m00 = src.m00; + float m01 = src.m10; + float m02 = src.m20; + float m10 = src.m01; + float m11 = src.m11; + float m12 = src.m21; + float m20 = src.m02; + float m21 = src.m12; + float m22 = src.m22; + + dest.m00 = m00; + dest.m01 = m01; + dest.m02 = m02; + dest.m10 = m10; + dest.m11 = m11; + dest.m12 = m12; + dest.m20 = m20; + dest.m21 = m21; + dest.m22 = m22; return dest; } @@ -381,12 +365,20 @@ * Invert this matrix * @return this if successful, null otherwise */ - public Matrix invert() - { - float determinant = determinant(); + public Matrix invert() { + return invert(this, this); + } + + /** + * Invert the source matrix and put the result into the destination matrix + * @param src The source matrix to be inverted + * @param dest The destination matrix + * @return dest if successful, null otherwise + */ + public static Matrix3f invert(Matrix3f src, Matrix3f dest) { + float determinant = src.determinant(); - if (determinant != 0) - { + if (determinant != 0) { /* do it the ordinary way * * inv(A) = 1/det(A) * adj(T), where adj(T) = transpose(Conjugate Matrix) @@ -398,46 +390,37 @@ float determinant_inv = 1f/determinant; // get the conjugate matrix - float t00 = m11 * m22 - m12* m21; - float t01 = - m10 * m22 + m12 *m20; - float t02 = m10 * m21 - m11 * m20; - float t10 = - m01 * m22 + m02 * m21; - float t11 = m00 * m22 - m02 * m20; - float t12 = - m00 * m21 + m01 * m20; - float t20 = m01 * m12 - m02 * m11; - float t21 = -m00 * m12 + m02 * m10; - float t22 = m00 * m11 - m01 * m10; - - - m00 = t00*determinant_inv; - m11 = t11*determinant_inv; - m22 = t22*determinant_inv; - m01 = t10*determinant_inv; - m10 = t01*determinant_inv; - m20 = t02*determinant_inv; - m02 = t20*determinant_inv; - m12 = t21*determinant_inv; - m21 = t12*determinant_inv; - return this; + float t00 = src.m11 * src.m22 - src.m12* src.m21; + float t01 = - src.m10 * src.m22 + src.m12 * src.m20; + float t02 = src.m10 * src.m21 - src.m11 * src.m20; + float t10 = - src.m01 * src.m22 + src.m02 * src.m21; + float t11 = src.m00 * src.m22 - src.m02 * src.m20; + float t12 = - src.m00 * src.m21 + src.m01 * src.m20; + float t20 = src.m01 * src.m12 - src.m02 * src.m11; + float t21 = -src.m00 * src.m12 + src.m02 * src.m10; + float t22 = src.m00 * src.m11 - src.m01 * src.m10; + + dest.m00 = t00*determinant_inv; + dest.m11 = t11*determinant_inv; + dest.m22 = t22*determinant_inv; + dest.m01 = t10*determinant_inv; + dest.m10 = t01*determinant_inv; + dest.m20 = t02*determinant_inv; + dest.m02 = t20*determinant_inv; + dest.m12 = t21*determinant_inv; + dest.m21 = t12*determinant_inv; + return dest; } else return null; } + /** * Negate this matrix * @return this */ public Matrix negate() { - m00 = -m00; - m01 = -m02; - m02 = -m01; - m10 = -m10; - m11 = -m12; - m12 = -m11; - m20 = -m20; - m21 = -m22; - m22 = -m21; - return this; + return negate(this); } /** @@ -446,18 +429,28 @@ * @return the negated matrix */ public Matrix3f negate(Matrix3f dest) { + return negate(this, this); + } + + /** + * Negate the source matrix and place the result in the destination matrix. + * @param src The source matrix + * @param dest The destination matrix, or null if a new matrix is to be created + * @return the negated matrix + */ + public static Matrix3f negate(Matrix3f src, Matrix3f dest) { if (dest == null) dest = new Matrix3f(); - dest.m00 = -m00; - dest.m01 = -m02; - dest.m02 = -m01; - dest.m10 = -m10; - dest.m11 = -m12; - dest.m12 = -m11; - dest.m20 = -m20; - dest.m21 = -m22; - dest.m22 = -m21; + dest.m00 = -src.m00; + dest.m01 = -src.m02; + dest.m02 = -src.m01; + dest.m10 = -src.m10; + dest.m11 = -src.m12; + dest.m12 = -src.m11; + dest.m20 = -src.m20; + dest.m21 = -src.m22; + dest.m22 = -src.m21; return dest; } @@ -466,33 +459,50 @@ * @return this */ public Matrix setIdentity() { - m00 = 1.0f; - m01 = 0.0f; - m02 = 0.0f; - m10 = 0.0f; - m11 = 1.0f; - m12 = 0.0f; - m20 = 0.0f; - m21 = 0.0f; - m22 = 1.0f; - return this; + return setIdentity(this); } + + /** + * Set the matrix to be the identity matrix. + * @param m The matrix to be set to the identity + * @return m + */ + public static Matrix3f setIdentity(Matrix3f m) { + m.m00 = 1.0f; + m.m01 = 0.0f; + m.m02 = 0.0f; + m.m10 = 0.0f; + m.m11 = 1.0f; + m.m12 = 0.0f; + m.m20 = 0.0f; + m.m21 = 0.0f; + m.m22 = 1.0f; + return m; + } /** * Set this matrix to 0. * @return this */ public Matrix setZero() { - m00 = 0.0f; - m01 = 0.0f; - m02 = 0.0f; - m10 = 0.0f; - m11 = 0.0f; - m12 = 0.0f; - m20 = 0.0f; - m21 = 0.0f; - m22 = 0.0f; - return this; + return setZero(this); } + /** + * Set the matrix matrix to 0. + * @param m The matrix to be set to 0 + * @return m + */ + public static Matrix3f setZero(Matrix3f m) { + m.m00 = 0.0f; + m.m01 = 0.0f; + m.m02 = 0.0f; + m.m10 = 0.0f; + m.m11 = 0.0f; + m.m12 = 0.0f; + m.m20 = 0.0f; + m.m21 = 0.0f; + m.m22 = 0.0f; + return m; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-16 07:54:52
|
Revision: 2374 Author: elias_naur Date: 2006-06-16 00:54:47 -0700 (Fri, 16 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2374&view=rev Log Message: ----------- Added missing static methods to Matrix2f for consistency. Cleaned up handling of src == dest aliasing Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java 2006-06-16 07:53:41 UTC (rev 2373) +++ trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java 2006-06-16 07:54:47 UTC (rev 2374) @@ -69,7 +69,7 @@ * @return this */ public Matrix2f load(Matrix2f src) { - return load(src); + return load(src, this); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-16 07:53:45
|
Revision: 2373 Author: elias_naur Date: 2006-06-16 00:53:41 -0700 (Fri, 16 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2373&view=rev Log Message: ----------- Added missing static methods to Matrix2f for consistency. Cleaned up handling of src == dest aliasing Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java 2006-06-16 07:48:40 UTC (rev 2372) +++ trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java 2006-06-16 07:53:41 UTC (rev 2373) @@ -47,12 +47,13 @@ private static final long serialVersionUID = 1L; - public float m00 = 1.0f, m01, m10, m11 = 1.0f; + public float m00, m01, m10, m11; /** - * Constructor for Matrix2f. + * Constructor for Matrix2f. The matrix is initialised to the identity. */ public Matrix2f() { + setIdentity(); } /** @@ -63,18 +64,30 @@ } /** - * Load from another matrix2f + * Load from another matrix * @param src The source matrix * @return this */ public Matrix2f load(Matrix2f src) { + return load(src); + } + + /** + * Copy src matrix to the dest matrix. + * @param src The source matrix + * @param dest The destination matrix, or null if a new one should be created. + * @return this + */ + public static Matrix2f load(Matrix2f src, Matrix2f dest) { + if (dest == null) + dest = new Matrix2f(); - m00 = src.m00; - m01 = src.m01; - m10 = src.m10; - m11 = src.m11; + dest.m00 = src.m00; + dest.m01 = src.m01; + dest.m10 = src.m10; + dest.m11 = src.m11; - return this; + return dest; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <eli...@us...> - 2006-06-16 07:48:44
|
Revision: 2372 Author: elias_naur Date: 2006-06-16 00:48:40 -0700 (Fri, 16 Jun 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2372&view=rev Log Message: ----------- Added missing static methods to Matrix2f for consistency. Cleaned up handling of src == dest aliasing Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java 2006-06-15 15:08:06 UTC (rev 2371) +++ trunk/LWJGL/src/java/org/lwjgl/util/vector/Matrix2f.java 2006-06-16 07:48:40 UTC (rev 2372) @@ -147,26 +147,15 @@ * @return the destination matrix */ public static Matrix2f add(Matrix2f left, Matrix2f right, Matrix2f dest) { - - Matrix2f temp = null; - if (dest == null) dest = new Matrix2f(); - else if (dest == left || dest == right) { - temp = dest; - dest = new Matrix2f(); - } dest.m00 = left.m00 + right.m00; dest.m01 = left.m01 + right.m01; dest.m10 = left.m10 + right.m10; dest.m11 = left.m11 + right.m11; - if (temp != null) { - temp.load(dest); - return temp; - } else - return dest; + return dest; } /** @@ -177,26 +166,15 @@ * @return the destination matrix */ public static Matrix2f sub(Matrix2f left, Matrix2f right, Matrix2f dest) { - - Matrix2f temp = null; - if (dest == null) dest = new Matrix2f(); - else if (dest == left || dest == right) { - temp = dest; - dest = new Matrix2f(); - } dest.m00 = left.m00 - right.m00; dest.m01 = left.m01 - right.m01; dest.m10 = left.m10 - right.m10; dest.m11 = left.m11 - right.m11; - if (temp != null) { - temp.load(dest); - return temp; - } else - return dest; + return dest; } /** @@ -207,26 +185,20 @@ * @return the destination matrix */ public static Matrix2f mul(Matrix2f left, Matrix2f right, Matrix2f dest) { - - Matrix2f temp = null; - if (dest == null) dest = new Matrix2f(); - else if (dest == left || dest == right) { - temp = dest; - dest = new Matrix2f(); - } - dest.m00 = left.m00 * right.m00 + left.m10 * right.m01; - dest.m01 = left.m01 * right.m00 + left.m11 * right.m01; - dest.m10 = left.m00 * right.m10 + left.m10 * right.m11; - dest.m11 = left.m01 * right.m10 + left.m11 * right.m11; + float m00 = left.m00 * right.m00 + left.m10 * right.m01; + float m01 = left.m01 * right.m00 + left.m11 * right.m01; + float m10 = left.m00 * right.m10 + left.m10 * right.m11; + float m11 = left.m01 * right.m10 + left.m11 * right.m11; + + dest.m00 = m00; + dest.m01 = m01; + dest.m10 = m10; + dest.m11 = m11; - if (temp != null) { - temp.load(dest); - return temp; - } else - return dest; + return dest; } /** @@ -238,24 +210,16 @@ * @return the destination vector */ public static Vector2f transform(Matrix2f left, Vector2f right, Vector2f dest) { - - Vector2f temp = null; - if (dest == null) dest = new Vector2f(); - else if (dest == right) { - temp = dest; - dest = new Vector2f(); - } - dest.x = left.m00 * right.x + left.m10 * right.y; - dest.y = left.m01 * right.x + left.m11 * right.y; + float x = left.m00 * right.x + left.m10 * right.y; + float y = left.m01 * right.x + left.m11 * right.y; + + dest.x = x; + dest.y = y; - if (temp != null) { - temp.set(dest); - return temp; - } else - return dest; + return dest; } /** @@ -263,12 +227,7 @@ * @return this */ public Matrix transpose() { - float temp; - - temp = m01; - m01 = m10; - m10 = temp; - return this; + return transpose(this); } /** @@ -277,27 +236,45 @@ * @return the transposed matrix */ public Matrix2f transpose(Matrix2f dest) { - + return transpose(this, dest); + } + + /** + * Transpose source matrix and place the result in dest matrix. + * @param src The source matrix or null if a new matrix is to be created + * @param dest The destination matrix or null if a new matrix is to be created + * @return the transposed matrix + */ + public static Matrix2f transpose(Matrix2f src, Matrix2f dest) { if (dest == null) dest = new Matrix2f(); + + float m01 = src.m10; + float m10 = src.m01; + + dest.m01 = m01; + dest.m10 = m10; - if (dest == this) - transpose(); - else { - dest.m01 = m10; - dest.m10 = m01; - } - return dest; - } + } /** * Invert this matrix * @return this if successful, null otherwise */ - public Matrix invert() - { - + public Matrix invert() { + return invert(this, this); + } + + /** + * Invert the source matrix and place the result in the dest matrix. + * @param src The source matrix to be inverted + * @param dest The destination matrix or null if a new matrix is to be created + * @return The inverted matrix, or null if source can't be reverted. + */ + public Matrix2f invert(Matrix2f src, Matrix2f dest) { + if (dest == null) + dest = new Matrix2f(); /* *inv(A) = 1/det(A) * adj(A); */ @@ -305,18 +282,18 @@ float determinant = determinant(); if (determinant != 0) { float determinant_inv = 1f/determinant; - float t00 = m11*determinant_inv; - float t01 = -m01*determinant_inv; - float t11 = m00*determinant_inv; - float t10 = -m10*determinant_inv; + float t00 = src.m11*determinant_inv; + float t01 = -src.m01*determinant_inv; + float t11 = src.m00*determinant_inv; + float t10 = -src.m10*determinant_inv; - m00 = t00; - m01 = t01; - m10 = t10; - m11 = t11; - return this; + dest.m00 = t00; + dest.m01 = t01; + dest.m10 = t10; + dest.m11 = t11; + return dest; } else - return null; + return null; } /** @@ -334,13 +311,7 @@ * @return this */ public Matrix negate() { - - m00 = -m00; - m01 = -m01; - m10 = -m10; - m11 = -m11; - - return this; + return negate(this); } /** @@ -349,41 +320,63 @@ * @return the negated matrix */ public Matrix2f negate(Matrix2f dest) { - + return negate(this, this); + } + + /** + * Negate src matrix and stash the result in dest matrix. + * @param src The source matrix to be negated + * @param dest The destination matrix, or null if a new matrix is to be created + * @return the negated matrix + */ + public static Matrix2f negate(Matrix2f src, Matrix2f dest) { if (dest == null) dest = new Matrix2f(); - dest.m00 = -m00; - dest.m01 = -m01; - dest.m10 = -m10; - dest.m11 = -m11; + dest.m00 = -src.m00; + dest.m01 = -src.m01; + dest.m10 = -src.m10; + dest.m11 = -src.m11; return dest; } - + /** * Set this matrix to be the identity matrix. * @return this */ public Matrix setIdentity() { - m00 = 1.0f; - m01 = 0.0f; - m10 = 0.0f; - m11 = 1.0f; - return this; + return setIdentity(this); } + + /** + * Set the ssrc matrix to be the identity matrix. + * @param src The matrix to set to the identity. + * @return The source matrix + */ + public static Matrix2f setIdentity(Matrix2f src) { + src.m00 = 1.0f; + src.m01 = 0.0f; + src.m10 = 0.0f; + src.m11 = 1.0f; + return src; + } /** * Set this matrix to 0. * @return this */ public Matrix setZero() { - m00 = 0.0f; - m01 = 0.0f; - m10 = 0.0f; - m11 = 0.0f; - return this; + return setZero(this); } + + public static Matrix2f setZero(Matrix2f src) { + src.m00 = 0.0f; + src.m01 = 0.0f; + src.m10 = 0.0f; + src.m11 = 0.0f; + return src; + } /* (non-Javadoc) * @see org.lwjgl.vector.Matrix#determinant() @@ -391,5 +384,4 @@ public float determinant() { return m00 * m11 - m01*m10; } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |