box._center.addLocal(translate); final Matrix3 transMatrix = Matrix3.fetchTempInstance(); transMatrix.set(rotate); transMatrix.setValue(0, 0, Math.abs(transMatrix.getM00())); transMatrix.setValue(0, 1, Math.abs(transMatrix.getM01())); transMatrix.setValue(0, 2, Math.abs(transMatrix.getM02())); transMatrix.setValue(1, 0, Math.abs(transMatrix.getM10())); transMatrix.setValue(1, 1, Math.abs(transMatrix.getM11())); transMatrix.setValue(1, 2, Math.abs(transMatrix.getM12())); transMatrix.setValue(2, 0, Math.abs(transMatrix.getM20())); transMatrix.setValue(2, 1, Math.abs(transMatrix.getM21())); transMatrix.setValue(2, 2, Math.abs(transMatrix.getM22())); transMatrix.applyPost(_compVect1, _compVect1); box.setZExtent(Math.abs(_compVect1.getZ())); Matrix3.releaseTempInstance(transMatrix);
@Test public void testInvert() { final Matrix3 mat3A = new Matrix3().applyRotationX(MathUtils.QUARTER_PI); final Matrix3 inverted = mat3A.invert(null); assertEquals(Matrix3.IDENTITY, mat3A.multiply(inverted, null)); assertEquals(mat3A, inverted.invertLocal()); }
/** * Converts this quaternion to a rotation matrix and then extracts rotation axes. * * @param axes * the array of vectors to be filled. * @throws ArrayIndexOutOfBoundsException * if the given axes array is smaller than 3 elements. * @return the axes */ @Override public Vector3[] toAxes(final Vector3[] axes) { final Matrix3 tempMat = toRotationMatrix(Matrix3.fetchTempInstance()); axes[2] = tempMat.getColumn(2, axes[2]); axes[1] = tempMat.getColumn(1, axes[1]); axes[0] = tempMat.getColumn(0, axes[0]); Matrix3.releaseTempInstance(tempMat); return axes; }
/** * Apply the rotation matrix to a given vector representing a particle velocity. * * @param pSpeed * the velocity vector to be modified. */ protected void rotateVectorSpeed(final Vector3 pSpeed) { final double x = pSpeed.getX(), y = pSpeed.getY(), z = pSpeed.getZ(); pSpeed.setX(-1 * ((_rotMatrix.getM00() * x) + (_rotMatrix.getM10() * y) + (_rotMatrix.getM20() * z))); pSpeed.setY((_rotMatrix.getM01() * x) + (_rotMatrix.getM11() * y) + (_rotMatrix.getM21() * z)); pSpeed.setZ(-1 * ((_rotMatrix.getM02() * x) + (_rotMatrix.getM12() * y) + (_rotMatrix.getM22() * z))); }
private void rotateNone() { if(_localRot != null) { _orient.set(getRotation()); _orient.multiplyLocal(_localRot); _worldTransform.setRotation(_orient); } }
@Test public void testGetSet() { final Matrix3 mat3A = new Matrix3(); assertEquals(Matrix3.IDENTITY, mat3A); mat3A.setM00(0.0); mat3A.setM01(0.1); mat3A.setM02(0.2); mat3A.setM10(1.0); mat3A.setM11(1.1); mat3A.setM12(1.2); mat3A.setM20(2.0); mat3A.setM21(2.1); mat3A.setM22(2.2); assertTrue(0.0 == mat3A.getM00()); assertTrue(0.1 == mat3A.getM01()); assertTrue(0.2 == mat3A.getM02()); assertTrue(1.0 == mat3A.getM10()); assertTrue(1.1 == mat3A.getM11()); assertTrue(1.2 == mat3A.getM12()); assertTrue(2.0 == mat3A.getM20()); assertTrue(2.1 == mat3A.getM21()); assertTrue(2.2 == mat3A.getM22()); final Matrix3 mat3B = new Matrix3(mat3A); assertTrue(0.0 == mat3B.getM00()); assertTrue(0.1 == mat3B.getM01()); assertTrue(0.2 == mat3B.getM02()); assertTrue(1.0 == mat3B.getM10());
@Test public void testMultiply() { final Matrix3 mat3A = new Matrix3( // 0.01, 0.1, 0.2, // 1.0, 1.1, 1.2, // 2.0, 2.1, 2.2); mat3A.multiplyLocal(2); assertEquals(new Matrix3( // 0.02, 0.2, 0.4, // 2.0, 2.2, 2.4, // 4.0, 4.2, 4.4), mat3A); final Matrix3 mat3B = new Matrix3( // 0.5, 1, 2, // 4, 5, 6, // 8, 9, 10); final Matrix3 result = mat3A.multiply(mat3B, null); assertTrue(0.02 * 0.5 + 0.2 * 4 + 0.4 * 8 == result.getM00()); assertTrue(0.02 * 1 + 0.2 * 5 + 0.4 * 9 == result.getM01()); assertTrue(0.02 * 2 + 0.2 * 6 + 0.4 * 10 == result.getM02()); assertTrue(2.0 * 0.5 + 2.2 * 4 + 2.4 * 8 == result.getM10()); assertTrue(2.0 * 1 + 2.2 * 5 + 2.4 * 9 == result.getM11()); assertTrue(2.0 * 2 + 2.2 * 6 + 2.4 * 10 == result.getM12()); assertTrue(4.0 * 0.5 + 4.2 * 4 + 4.4 * 8 == result.getM20()); assertTrue(4.0 * 1 + 4.2 * 5 + 4.4 * 9 == result.getM21()); assertTrue(4.0 * 2 + 4.2 * 6 + 4.4 * 10 == result.getM22()); mat3A.multiplyLocal(mat3B); assertTrue(0.02 * 0.5 + 0.2 * 4 + 0.4 * 8 == mat3A.getM00()); assertTrue(0.02 * 1 + 0.2 * 5 + 0.4 * 9 == mat3A.getM01()); assertTrue(0.02 * 2 + 0.2 * 6 + 0.4 * 10 == mat3A.getM02());
@Test public void testFromArray() { final double[] values = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; final Matrix3 mat3A = new Matrix3(); // row major mat3A.fromArray(values); assertTrue(0 == mat3A.getM00()); assertTrue(1 == mat3A.getM01()); assertTrue(2 == mat3A.getM02()); assertTrue(3 == mat3A.getM10()); assertTrue(4 == mat3A.getM11()); assertTrue(5 == mat3A.getM12()); assertTrue(6 == mat3A.getM20()); assertTrue(7 == mat3A.getM21()); assertTrue(8 == mat3A.getM22()); // column major mat3A.setIdentity(); mat3A.fromArray(values, false); assertTrue(0 == mat3A.getM00()); assertTrue(3 == mat3A.getM01()); assertTrue(6 == mat3A.getM02()); assertTrue(1 == mat3A.getM10()); assertTrue(4 == mat3A.getM11()); assertTrue(7 == mat3A.getM12()); assertTrue(2 == mat3A.getM20()); assertTrue(5 == mat3A.getM21()); assertTrue(8 == mat3A.getM22()); }
final Matrix3 mat3A = new Matrix3().fromFloatBuffer(fb); assertTrue(0 == mat3A.getM00()); assertTrue(1 == mat3A.getM01()); assertTrue(2 == mat3A.getM02()); assertTrue(3 == mat3A.getM10()); assertTrue(4 == mat3A.getM11()); assertTrue(5 == mat3A.getM12()); assertTrue(6 == mat3A.getM20()); assertTrue(7 == mat3A.getM21()); assertTrue(8 == mat3A.getM22()); mat3A.setIdentity(); mat3A.fromFloatBuffer(fb, false); assertTrue(0 == mat3A.getM00()); assertTrue(3 == mat3A.getM01()); assertTrue(6 == mat3A.getM02()); assertTrue(1 == mat3A.getM10()); assertTrue(4 == mat3A.getM11()); assertTrue(7 == mat3A.getM12()); assertTrue(2 == mat3A.getM20()); assertTrue(5 == mat3A.getM21()); assertTrue(8 == mat3A.getM22()); mat3A.setIdentity(); mat3A.fromDoubleBuffer(db); assertTrue(0 == mat3A.getM00()); assertTrue(1 == mat3A.getM01()); assertTrue(2 == mat3A.getM02()); assertTrue(3 == mat3A.getM10());
_matrix.applyPre(vector, vector); if (_uniformScale) { vector.divideLocal(_scale.getX()); final Matrix3 invertedMatrix = _matrix.invert(Matrix3.fetchTempInstance()); invertedMatrix.applyPost(vector, vector); Matrix3.releaseTempInstance(invertedMatrix);
final Matrix3 worldMatrix = Matrix3.fetchTempInstance().set(_worldTransform.getMatrix()); worldMatrix.applyPost(_look, _left); // coopt left for our own purposes. final ReadOnlyVector3 scale = _worldTransform.getScale(); _left.divideLocal(scale); _orient.setValue(0, 0, _left.getZ()); _orient.setValue(0, 1, 0); _orient.setValue(0, 2, _left.getX()); _orient.setValue(1, 0, 0); _orient.setValue(1, 1, 1); _orient.setValue(1, 2, 0); _orient.setValue(2, 0, -_left.getX()); _orient.setValue(2, 1, 0); _orient.setValue(2, 2, _left.getZ()); } else if (axis.getZ() == 1) { _left.setX(_left.getX() * invLength); _orient.setValue(0, 0, _left.getY()); _orient.setValue(0, 1, _left.getX()); _orient.setValue(0, 2, 0); _orient.setValue(1, 0, -_left.getY()); _orient.setValue(1, 1, _left.getX()); _orient.setValue(1, 2, 0); _orient.setValue(2, 0, 0); _orient.setValue(2, 1, 0); _orient.setValue(2, 2, 1); worldMatrix.multiplyLocal(_orient); _worldTransform.setRotation(worldMatrix);
result._rotationMatrix = true; final Matrix3 newRotation = result._matrix; newRotation.set(_matrix).multiplyLocal(transformBy.getMatrix()); _matrix.applyPost(newTranslation, newTranslation); ? _matrix.multiplyDiagonalPost(_scale, Matrix3.fetchTempInstance()) : _matrix; ? transformBy.getMatrix().multiplyDiagonalPost(transformBy.getScale(), Matrix3.fetchTempInstance()) : transformBy.getMatrix(); newMatrix.set(matrixA).multiplyLocal(matrixB); Matrix3.releaseTempInstance((Matrix3) matrixA); Matrix3.releaseTempInstance((Matrix3) matrixB);
@Test public void testValid() { final Matrix3 mat3 = new Matrix3(); assertTrue(Matrix3.isValid(mat3)); for (int i = 0; i < 9; i++) { mat3.setIdentity(); mat3.setValue(i / 3, i % 3, Double.NaN); assertFalse(Matrix3.isValid(mat3)); mat3.setIdentity(); mat3.setValue(i / 3, i % 3, Double.POSITIVE_INFINITY); assertFalse(Matrix3.isValid(mat3)); mat3.setIdentity(); assertTrue(Matrix3.isValid(mat3)); assertFalse(Matrix3.isValid(null)); assertTrue(mat3.strictEquals(mat3)); assertFalse(mat3.equals(null)); assertFalse(mat3.strictEquals(null)); assertFalse(mat3.equals(new Vector2())); assertFalse(mat3.strictEquals(new Vector2())); final Matrix3 matTemp = Matrix3.fetchTempInstance(); matTemp.set(mat3); assertEquals(mat3, matTemp); assertNotSame(mat3, matTemp); Matrix3.releaseTempInstance(matTemp); mat3.set(0, 1, 2, 3, 4, 5, 6, 7, 8);
@Override public boolean intersectsSphere(final BoundingSphere bs) { if (!Vector3.isValid(_center) || !Vector3.isValid(bs._center)) { return false; } _compVect1.set(bs.getCenter()).subtractLocal(_center); final Matrix3 tempMa = Matrix3.fetchTempInstance().fromAxes(_xAxis, _yAxis, _zAxis); tempMa.applyPost(_compVect1, _compVect1); boolean result = false; if (Math.abs(_compVect1.getX()) < bs.getRadius() + _extent.getX() && Math.abs(_compVect1.getY()) < bs.getRadius() + _extent.getY() && Math.abs(_compVect1.getZ()) < bs.getRadius() + _extent.getZ()) { result = true; } Matrix3.releaseTempInstance(tempMa); return result; }
final Matrix3 newMatrix = result._matrix.set(_matrix); if (_rotationMatrix) { if (_uniformScale) { final double sx = _scale.getX(); newMatrix.transposeLocal(); if (sx != 1.0) { newMatrix.multiplyLocal(1.0 / sx); newMatrix.multiplyDiagonalPost(_scale, newMatrix).invertLocal(); newMatrix.invertLocal(); result._matrix.applyPost(_translation, result._translation).negateLocal(); result.updateFlags(_rotationMatrix);
@Test public void testSetRotation() { final Matrix3 mat3A = new Matrix3(); // rotate identity 90 degrees around Y final double a = MathUtils.HALF_PI; final Quaternion quaternion = new Quaternion(); quaternion.fromAngleAxis(a, Vector3.UNIT_Y); mat3A.set(quaternion); assertEquals(new Matrix3( // Math.cos(a), 0, Math.sin(a), // 0, 1, 0, // -Math.sin(a), 0, Math.cos(a)), mat3A); }
final Vector3 workVect = Vector3.fetchTempInstance(); final Vector3 workVect2 = Vector3.fetchTempInstance(); final Matrix3 workMat = Matrix3.fetchTempInstance(); workVect.set(_swarmPoint).subtractLocal(particle.getPosition()).normalizeLocal(); workVect2.set(pVelocity).normalizeLocal(); workMat.fromAngleAxis(_turnSpeed * dt, axis); } else { workMat.fromAngleAxis(-_turnSpeed * dt, axis); workMat.applyPost(pVelocity, pVelocity); workMat.fromAngleAxis(_turnSpeed * dt, axis); } else { workMat.fromAngleAxis(-_turnSpeed * dt, axis); workMat.applyPost(pVelocity, pVelocity); Matrix3.releaseTempInstance(workMat);
public void stateChanged(final ChangeEvent e) { final Vector3 val = _rotationPanel.getValue().multiplyLocal(MathUtils.DEG_TO_RAD); final Matrix3 mat = Matrix3.fetchTempInstance().fromAngles(val.getX(), val.getY(), val.getZ()); getEdittedParticles().setRotation(mat); Matrix3.releaseTempInstance(mat); } });
/** * Constructs a new, mutable matrix using the values from the given matrix * * @param source */ public Matrix3(final ReadOnlyMatrix3 source) { set(source); }
/** * Forces rotation and translation of this node to be sync'd with the attached camera. (Assumes the node is in world * space.) */ public void updateFromCamera() { final ReadOnlyVector3 camLeft = _camera.getLeft(); final ReadOnlyVector3 camUp = _camera.getUp(); final ReadOnlyVector3 camDir = _camera.getDirection(); final ReadOnlyVector3 camLoc = _camera.getLocation(); final Matrix3 rotation = Matrix3.fetchTempInstance(); rotation.fromAxes(camLeft, camUp, camDir); setRotation(rotation); setTranslation(camLoc); Matrix3.releaseTempInstance(rotation); }