/** * @return An instance of Matrix3 that is intended for temporary use in calculations and so forth. Multiple calls to * the method should return instances of this class that are not currently in use. */ public final static Matrix3 fetchTempInstance() { if (MathConstants.useMathPools) { return Matrix3.MAT_POOL.fetch(); } else { return new Matrix3(); } }
/** * @return An instance of Matrix3 that is intended for temporary use in calculations and so forth. Multiple calls to * the method should return instances of this class that are not currently in use. */ public final static Matrix3 fetchTempInstance() { if (MathConstants.useMathPools) { return Matrix3.MAT_POOL.fetch(); } else { return new Matrix3(); } }
@Test public void testAngleAxis() { final Matrix3 mat3A = new Matrix3(); // rotate identity 90 degrees around X final double angle = MathUtils.HALF_PI; mat3A.fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_X); assertEquals(new Matrix3( // 1, 0, 0, // 0, Math.cos(angle), -Math.sin(angle), // 0, Math.sin(angle), Math.cos(angle)), mat3A); }
@Test(expected = IllegalArgumentException.class) public void testBadArray() { final Matrix3 mat3A = new Matrix3(); mat3A.toArray(new double[4]); }
@Test(expected = IllegalArgumentException.class) public void testBadAnglesArray() { final Matrix3 mat3A = new Matrix3(); mat3A.toAngles(new double[2]); }
@Test public void testSimpleHash() { // Just a simple sanity check. final Matrix3 mat1 = new Matrix3(1, 2, 3, 4, 5, 6, 7, 8, 9); final Matrix3 mat2 = new Matrix3(1, 2, 3, 4, 5, 6, 7, 8, 9); final Matrix3 mat3 = new Matrix3(1, 2, 3, 4, 5, 6, 7, 8, 0); assertTrue(mat1.hashCode() == mat2.hashCode()); assertTrue(mat1.hashCode() != mat3.hashCode()); }
@Override public void write(final OutputCapsule capsule) throws IOException { super.write(capsule); capsule.write(_orient, "orient", new Matrix3()); capsule.write(_look, "look", new Vector3(Vector3.ZERO)); capsule.write(_left, "left", new Vector3(Vector3.ZERO)); capsule.write(_alignment, "alignment", BillboardAlignment.ScreenAligned); }
@Override public void write(final OutputCapsule capsule) throws IOException { capsule.write(_matrix, "rotation", new Matrix3(Matrix3.IDENTITY)); capsule.write(_scale, "scale", new Vector3(Vector3.ONE)); capsule.write(_translation, "translation", new Vector3(Vector3.ZERO)); capsule.write(_identity, "identity", true); capsule.write(_rotationMatrix, "rotationMatrix", true); capsule.write(_uniformScale, "uniformScale", true); }
@Override public void write(final OutputCapsule capsule) throws IOException { super.write(capsule); capsule.write(_orient, "orient", new Matrix3()); capsule.write(_look, "look", new Vector3(Vector3.ZERO)); capsule.write(_left, "left", new Vector3(Vector3.ZERO)); capsule.write(_alignment, "alignment", BillboardAlignment.ScreenAligned); capsule.write(_updateBounds, "updateBounds", true); }
@Override public void write(final OutputCapsule capsule) throws IOException { capsule.write(_matrix, "rotation", new Matrix3(Matrix3.IDENTITY)); capsule.write(_scale, "scale", new Vector3(Vector3.ONE)); capsule.write(_translation, "translation", new Vector3(Vector3.ZERO)); capsule.write(_identity, "identity", true); capsule.write(_rotationMatrix, "rotationMatrix", true); capsule.write(_uniformScale, "uniformScale", true); }
@Test(expected = TransformException.class) public void testFailScale3A() { final Transform trans = new Transform(new Matrix3(), new Vector3(), new Vector3(), false, false, false); trans.setScale(1); }
@Test(expected = TransformException.class) public void testFailScale2A() { final Transform trans = new Transform(new Matrix3(), new Vector3(), new Vector3(), false, false, false); trans.setScale(1, 1, 1); }
@Test public void testClone() { final Matrix3 mat1 = new Matrix3(); final Matrix3 mat2 = mat1.clone(); assertEquals(mat1, mat2); assertNotSame(mat1, mat2); }
@Override public void read(final InputCapsule capsule) throws IOException { super.read(capsule); _orient.set((Matrix3) capsule.readSavable("orient", new Matrix3(Matrix3.IDENTITY))); _look.set((Vector3) capsule.readSavable("look", new Vector3(Vector3.ZERO))); _left.set((Vector3) capsule.readSavable("left", new Vector3(Vector3.ZERO))); _alignment = capsule.readEnum("alignment", BillboardAlignment.class, BillboardAlignment.ScreenAligned); } }
@Override public void read(final InputCapsule capsule) throws IOException { _matrix.set((Matrix3) capsule.readSavable("rotation", new Matrix3(Matrix3.IDENTITY))); _scale.set((Vector3) capsule.readSavable("scale", new Vector3(Vector3.ONE))); _translation.set((Vector3) capsule.readSavable("translation", new Vector3(Vector3.ZERO))); _identity = capsule.readBoolean("identity", true); _rotationMatrix = capsule.readBoolean("rotationMatrix", true); _uniformScale = capsule.readBoolean("uniformScale", true); }
@Override public void read(final InputCapsule capsule) throws IOException { _matrix.set((Matrix3) capsule.readSavable("rotation", new Matrix3(Matrix3.IDENTITY))); _scale.set((Vector3) capsule.readSavable("scale", new Vector3(Vector3.ONE))); _translation.set((Vector3) capsule.readSavable("translation", new Vector3(Vector3.ZERO))); _identity = capsule.readBoolean("identity", true); _rotationMatrix = capsule.readBoolean("rotationMatrix", true); _uniformScale = capsule.readBoolean("uniformScale", true); }
@Override public void read(final InputCapsule capsule) throws IOException { super.read(capsule); _orient.set((Matrix3) capsule.readSavable("orient", new Matrix3(Matrix3.IDENTITY))); _look.set((Vector3) capsule.readSavable("look", new Vector3(Vector3.ZERO))); _left.set((Vector3) capsule.readSavable("left", new Vector3(Vector3.ZERO))); _alignment = capsule.readEnum("alignment", BillboardAlignment.class, BillboardAlignment.ScreenAligned); _updateBounds = capsule.readBoolean("updateBounds", true); } }
@Test public void testConstructor() { final ValidatingTransform vt1 = new ValidatingTransform(); assertEquals(Transform.IDENTITY, vt1); vt1.translate(0, 1, 2); vt1.setRotation(new Matrix3().fromAngleAxis(Math.PI, Vector3.UNIT_X)); final ValidatingTransform vt2 = new ValidatingTransform(vt1); assertEquals(vt1, vt2); }
@Test public void testInvert() { final Transform trans1 = new Transform(); trans1.setRotation(new Matrix3().applyRotationZ(3 * MathUtils.QUARTER_PI)); final Transform trans2 = trans1.invert(null); assertEquals(Transform.IDENTITY, trans1.multiply(trans2, null)); trans1.setIdentity().invert(trans1); assertEquals(Transform.IDENTITY, trans1); }
@Test public void testAxes() { final Matrix3 rot = new Matrix3().applyRotationX(MathUtils.QUARTER_PI).applyRotationY(MathUtils.HALF_PI); final Quaternion quat1 = new Quaternion().fromAxes(rot.getColumn(0, null), rot.getColumn(1, null), rot.getColumn(2, null)); final Quaternion quat2 = new Quaternion().fromRotationMatrix(rot); assertEquals(quat2, quat1); final Vector3[] axes = quat1.toAxes(new Vector3[3]); quat1.fromAxes(axes[0], axes[1], axes[2]); assertEquals(quat2, quat1); }