/** * @return An instance of Transform 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 Transform fetchTempInstance() { if (MathConstants.useMathPools) { return Transform.TRANS_POOL.fetch(); } else { return new Transform(); } }
/** * @return An instance of Transform 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 Transform fetchTempInstance() { if (MathConstants.useMathPools) { return Transform.TRANS_POOL.fetch(); } else { return new Transform(); } }
/** * Constructs a new Spatial. Initializes the transform fields. */ public Spatial() { _localTransform = Constants.useValidatingTransform ? new ValidatingTransform() : new Transform(); _worldTransform = Constants.useValidatingTransform ? new ValidatingTransform() : new Transform(); _sceneHints = new SceneHints(this); }
/** * Constructs a new Spatial. Initializes the transform fields. */ public Spatial() { _localTransform = Constants.useValidatingTransform ? new ValidatingTransform() : new Transform(); _worldTransform = Constants.useValidatingTransform ? new ValidatingTransform() : new Transform(); _sceneHints = new SceneHints(this); }
@Test(expected = NullPointerException.class) public void testApplyFail4() { final Transform trans = new Transform(); trans.applyInverseVector(null); }
@Test(expected = IllegalArgumentException.class) public void testFailScale1B() { final Transform trans = new Transform(); trans.setScale(Vector3.ZERO); }
@Test(expected = NullPointerException.class) public void testApplyFail3() { final Transform trans = new Transform(); trans.applyInverse(null); }
@Test(expected = IllegalArgumentException.class) public void testFailScale2B() { final Transform trans = new Transform(); trans.setScale(0, 0, 0); }
@Test(expected = NullPointerException.class) public void testApplyFail1() { final Transform trans = new Transform(); trans.applyForward(null); }
@Test(expected = NullPointerException.class) public void testApplyFail2() { final Transform trans = new Transform(); trans.applyForwardVector(null); }
@Test(expected = IllegalArgumentException.class) public void testFailScale3B() { final Transform trans = new Transform(); trans.setScale(0); }
@Test public void testSimpleHash() { // Just a simple sanity check. final Transform trans1 = new Transform().setTranslation(1, 2, 3); final Transform trans2 = new Transform().setTranslation(1, 2, 3); final Transform trans3 = new Transform().setTranslation(1, 2, 0); assertTrue(trans1.hashCode() == trans2.hashCode()); assertTrue(trans1.hashCode() != trans3.hashCode()); }
@Test(expected = InvalidTransformException.class) public void failConstructor() { final Transform bad = new Transform(); bad.translate(Double.NaN, 1, 2); new ValidatingTransform(Transform.IDENTITY); // good new ValidatingTransform(bad); // bad }
public ReadOnlyTransform getValue() { final Transform t = new Transform(); t.setTranslation(_translationX.getDoubleValue(), _translationY.getDoubleValue(), 0); final double val = _rotation.getDoubleValue() * MathUtils.DEG_TO_RAD; final Matrix3 mat = Matrix3.fetchTempInstance().fromAngles(0, 0, val); t.setRotation(mat); Matrix3.releaseTempInstance(mat); t.setScale(_scale.getDoubleValue()); return t; }
@Test(expected = InvalidTransformException.class) public void testSet() { final Transform bad = new Transform(); bad.translate(Double.NaN, 1, 2); final ValidatingTransform vt1 = new ValidatingTransform(); vt1.set(Transform.IDENTITY); // good vt1.set(bad); // bad }
public ReadOnlyTransform getValue() { final Transform t = new Transform(); t.setTranslation(_translation.getValue()); final Vector3 val = _rotation.getValue().multiplyLocal(MathUtils.DEG_TO_RAD); final Matrix3 mat = Matrix3.fetchTempInstance().fromAngles(val.getX(), val.getY(), val.getZ()); t.setRotation(mat); Matrix3.releaseTempInstance(mat); t.setScale(_scale.getValue()); return t; }
@Test(expected = TransformException.class) public void testFailScale1A() { final Transform trans = new Transform(new Matrix3(), new Vector3(), new Vector3(), false, false, false); trans.setScale(Vector3.ONE); }
@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 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 testTranslate() { final Transform trans = new Transform(); trans.translate(1, 3, 5); assertEquals(new Vector3(1, 3, 5), trans.getTranslation()); trans.translate(trans.getTranslation().negate(null)); assertEquals(Vector3.ZERO, trans.getTranslation()); trans.translate(new Vector3(1, 3, 5)); assertEquals(new Vector3(1, 3, 5), trans.getTranslation()); trans.translate(-1, -3, -5); assertEquals(Vector3.ZERO, trans.getTranslation()); }