/** * Sets the world transform. * * @param transform * the new world transform */ public void setWorldTransform(final ReadOnlyTransform transform) { _worldTransform.set(transform); }
public void applyTo(final Transform transform) { transform.setIdentity(); transform.setRotation(getRotation()); transform.setScale(getScale()); transform.setTranslation(getTranslation()); }
/** * @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(); } }
/** * Updates the worldTransform. * * @param recurse * usually false when updating the tree. Set to true when you just want to update the world transforms * for a branch without updating geometric state. */ public void updateWorldTransform(final boolean recurse) { if (_parent != null) { _parent._worldTransform.multiply(_localTransform, _worldTransform); } else { _worldTransform.set(_localTransform); } clearDirty(DirtyType.Transform); }
@Test public void testMultiply() { final Transform trans1 = new Transform(); final Transform trans2 = new Transform(); assertEquals(Transform.IDENTITY, trans1.multiply(trans2, null)); trans1.setTranslation(1, 2, 3); final Transform trans3 = trans1.multiply(trans2, null); assertEquals(trans1, trans3); trans2.setTranslation(-1, -2, -3); trans1.multiply(trans2, trans3); assertEquals(Transform.IDENTITY, trans3); assertTrue(trans3.isRotationMatrix()); assertTrue(trans3.isIdentity()); assertTrue(trans3.isUniformScale()); trans2.setScale(1, 2, 1); trans1.multiply(trans2, trans3); assertEquals(new Transform().setScale(1, 2, 1), trans3); assertTrue(trans3.isRotationMatrix()); assertFalse(trans3.isIdentity()); assertFalse(trans3.isUniformScale()); trans1.setScale(1, 2, 1); trans1.multiply(trans2, trans3); assertEquals(new Transform().setRotation(new Matrix3(1, 0, 0, 0, 4, 0, 0, 0, 1)).setTranslation(0, -2, 0), trans3); assertFalse(trans3.isRotationMatrix()); assertFalse(trans3.isIdentity()); assertFalse(trans3.isUniformScale()); }
@Override public void drawTo(final BufferedImage image, final ReadOnlyTransform localTransform, final int clipmapLevel) { // apply the two transforms together and then use result to scale/translate and rotate image final Transform trans = new Transform(); localTransform.multiply(getTransform(), trans); // grab a copy of the graphics so we don't bleed state to next image final Graphics2D g2d = (Graphics2D) image.getGraphics().create(); // apply hints for (final RenderingHints.Key key : hints.keySet()) { g2d.setRenderingHint(key, hints.get(key)); } // set transform g2d.translate(trans.getTranslation().getX(), trans.getTranslation().getY()); g2d.rotate(trans.getMatrix().toAngles(null)[2]); // rotation about z g2d.scale(trans.getScale().getX(), trans.getScale().getY()); // set composite if (_compositeOverride != null) { g2d.setComposite(_compositeOverride); } // draw the image g2d.drawImage(_image, 0, 0, null); } }
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; }
final Transform temp = Transform.fetchTempInstance(); _globalTransforms[parentIndex].multiply(_localTransforms[index], _globalTransforms[index]); } else { _globalTransforms[index].set(_localTransforms[index]); _globalTransforms[index].multiply(_skeleton.getJoints()[index].getInverseBindPose(), temp); temp.getHomogeneousMatrix(_matrixPalette[index]); Transform.releaseTempInstance(temp); firePoseUpdated();
@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); }
/** * * @param cam */ public void correctTransform(final Camera cam) { updateWorldTransform(false); if (_autoRotate) { // Billboard rotation _look.set(cam.getDirection()); _left.set(cam.getLeft()).negateLocal(); _rot.fromAxes(_left, _look, cam.getUp()); _worldTransform.setRotation(_rot); } _worldTransform.setScale(_localTransform.getScale()); }
@Override public ResultSample doTransformMultTest(final int count, final int maxCount, final long timeOutMS) { final ReadOnlyMatrix4 m1 = new Matrix4().fromAngleAxis(MathUtils.nextRandomDouble(), new Vector3(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble())); final ReadOnlyMatrix4 m2 = new Matrix4().fromAngleAxis(MathUtils.nextRandomDouble(), new Vector3(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble())); final Transform a = new Transform().fromHomogeneousMatrix(m1); final Transform b = new Transform(); final Transform by = new Transform().fromHomogeneousMatrix(m2); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { if (i % 2 == 0) { a.multiply(by, b); } else { b.multiply(by, a); } } } return populateResult(System.currentTimeMillis() - start, loopCount, a.getHomogeneousMatrix(null).toArray(null)); }
/** * Sets the world translation vector. * * @param translation * the new world translation */ public void setWorldTranslation(final ReadOnlyVector3 translation) { _worldTransform.setTranslation(translation); }
@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()); }
/** * Convert a vector (in) from this spatial's local coordinate space to world coordinate space. * * @param in * vector to read from * @param store * where to write the result (null to create a new vector, may be same as in) * @return the result (store) */ public Vector3 localToWorld(final ReadOnlyVector3 in, Vector3 store) { if (store == null) { store = new Vector3(); } return _worldTransform.applyForward(in, store); }
/** * Aligns this Billboard Node so that it points to the camera position. */ private void rotateCameraAligned() { final Camera camera = Camera.getCurrentCamera(); _look.set(camera.getLocation()).subtractLocal(_worldTransform.getTranslation()).normalizeLocal(); _left.set(camera.getUp()).crossLocal(_look); final Vector3 up = Vector3.fetchTempInstance(); up.set(_look).crossLocal(_left); _orient.fromAxes(_left, up, _look); if(_localRot != null) _orient.multiplyLocal(_localRot); _worldTransform.setRotation(_orient); Vector3.releaseTempInstance(up); }
/** * Draw a single Joint using the given world-space joint transform. * * @param jntTransform * our joint transform * @param scene * @param renderer * the Renderer to draw with. */ private static void drawJoint(final Transform jntTransform, final Spatial scene, final Renderer renderer) { final BoundingVolume vol = scene.getWorldBound(); double size = 1.0; if (vol != null) { SkeletalDebugger.measureSphere.setCenter(vol.getCenter()); SkeletalDebugger.measureSphere.setRadius(0); SkeletalDebugger.measureSphere.mergeLocal(vol); size = SkeletalDebugger.BONE_RATIO * SkeletalDebugger.measureSphere.getRadius(); } scene.getWorldTransform().multiply(jntTransform, SkeletalDebugger.spTransform); SkeletalDebugger.spTransform.getMatrix().scale(new Vector3(size, size, size), SkeletalDebugger.spMatrix); SkeletalDebugger.spTransform.setRotation(SkeletalDebugger.spMatrix); SkeletalDebugger.joint.setWorldTransform(SkeletalDebugger.spTransform); SkeletalDebugger.joint.draw(renderer); }
@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()); }
/** * Sets the rotation of this spatial. This marks the spatial as DirtyType.Transform. * * @param rotation * the new rotation of this spatial * @see Transform#setRotation(Matrix3) */ public void setRotation(final ReadOnlyMatrix3 rotation) { _localTransform.setRotation(rotation); markDirty(DirtyType.Transform); }