@Override // from Transform public Transform lerp (Transform other, float t) { if (generality() < other.generality()) { return other.lerp(this, -t); // TODO: is this correct? } AffineTransform ot = (other instanceof AffineTransform) ? (AffineTransform)other : new AffineTransform(other); return new AffineTransform( m00 + t*(ot.m00 - m00), m01 + t*(ot.m01 - m01), m10 + t*(ot.m10 - m10), m11 + t*(ot.m11 - m11), tx + t*(ot.tx - tx ), ty + t*(ot.ty - ty )); }
@Override // from Transform public AffineTransform uniformScale (float scale) { return scale(scale, scale); }
/** Sets this affine transform matrix to {@code other}. * @return this instance, for chaining. */ public AffineTransform set (AffineTransform other) { return setTransform(other.m00, other.m01, other.m10, other.m11, other.tx, other.ty); }
@Override // from Transform public AffineTransform invert () { // compute the determinant, storing the subdeterminants for later use float det = m00*m11 - m10*m01; if (Math.abs(det) == 0f) { // determinant is zero; matrix is not invertible throw new NoninvertibleTransformException(this.toString()); } float rdet = 1f / det; return new AffineTransform( +m11 * rdet, -m10 * rdet, -m01 * rdet, +m00 * rdet, (m10*ty - m11*tx) * rdet, (m01*tx - m00*ty) * rdet); }
final AffineTransform af = new AffineTransform(). scale(game.graphics.scale().factor, game.graphics.scale().factor). translate(160, (ygap + 150));
/** * Fills a line between the specified coordinates, of the specified display unit width. */ public Surface drawLine (float x0, float y0, float x1, float y1, float width) { // swap the line end points if x1 is less than x0 if (x1 < x0) { float temp = x0; x0 = x1; x1 = temp; temp = y0; y0 = y1; y1 = temp; } float dx = x1 - x0, dy = y1 - y0; float length = FloatMath.sqrt(dx * dx + dy * dy); float wx = dx * (width / 2) / length; float wy = dy * (width / 2) / length; AffineTransform xf = new AffineTransform(); xf.setRotation(FloatMath.atan2(dy, dx)); xf.setTranslation(x0 + wy, y0 - wx); Transforms.multiply(tx(), xf, xf); if (patternTex != null) { batch.addQuad(patternTex, tint, xf, 0, 0, length, width); } else { batch.addQuad(colorTex, Tint.combine(fillColor, tint), xf, 0, 0, length, width); } return this; }
@Override // from Transform public AffineTransform copy () { return new AffineTransform(m00, m01, m10, m11, tx, ty); }
/** Translates the current transformation matrix by the given amount. */ public Surface translate (float x, float y) { tx().translate(x, y); return this; }
@Override // from Transform public void transform (IPoint[] src, int srcOff, Point[] dst, int dstOff, int count) { for (int ii = 0; ii < count; ii++) { transform(src[srcOff++], dst[dstOff++]); } }
/** * Returns the layer's current transformation matrix. If any changes have been made to the * layer's scale, rotation or translation, they will be applied to the transform matrix before it * is returned. * * <p><em>Note:</em> any direct modifications to this matrix <em>except</em> modifications to its * translation, will be overwritten if a call is subsequently made to {@link #setScale(float)}, * {@link #setScale(float,float)}, {@link #setScaleX}, {@link #setScaleY} or {@link #setRotation}. * If you intend to manipulate a layer's transform matrix directly, <em>do not</em> call those * other methods. Also do not expect {@link #scaleX}, {@link #scaleY}, or {@link #rotation} to * reflect the direct changes you've made to the transform matrix. They will not. </p> */ public AffineTransform transform() { if (isSet(Flag.XFDIRTY)) { float sina = FloatMath.sin(rotation), cosa = FloatMath.cos(rotation); float m00 = cosa * scaleX, m01 = sina * scaleX; float m10 = -sina * scaleY, m11 = cosa * scaleY; float tx = transform.tx(), ty = transform.ty(); transform.setTransform(m00, m01, m10, m11, tx, ty); setFlag(Flag.XFDIRTY, false); } return transform; }
@Override public String toString () { if (m00 != 1 || m01 != 0 || m10 != 0 || m11 != 1) return "affine [" + MathUtil.toString(m00) + " " + MathUtil.toString(m01) + " " + MathUtil.toString(m10) + " " + MathUtil.toString(m11) + " " + translation() + "]"; else if (tx != 0 || ty != 0) return "trans " + translation(); else return "ident"; }
@Override public void willInit (int count) { // concatenate the transform of all layers above our target layer xform.setTransform(1, 0, 0, 1, 0, 0); Layer xlayer = layer; while (xlayer != null) { Transforms.multiply(xlayer.transform(), xform, xform); xlayer = xlayer.parent(); } xform.get(_matrix); } @Override public void init (int index, float[] data, int start) {
/** * Sets the x and y translation of this layer. * * <p><em>Note:</em> all transform changes are deferred until {@link #transform} is called * (which happens during rendering, if not before) at which point the current scale, rotation and * translation are composed into an affine transform matrix. This means that, for example, * setting rotation and then setting scale will not flip the rotation like it would were these * applied to the transform matrix one operation at a time. </p> * * @return a reference to this layer for call chaining. */ public Layer setTranslation(float x, float y) { transform.setTranslation(x, y); return this; }
/** * Fills a line between the specified coordinates, of the specified display unit width. */ public Surface drawLine (float x0, float y0, float x1, float y1, float width) { // swap the line end points if x1 is less than x0 if (x1 < x0) { float temp = x0; x0 = x1; x1 = temp; temp = y0; y0 = y1; y1 = temp; } float dx = x1 - x0, dy = y1 - y0; float length = FloatMath.sqrt(dx * dx + dy * dy); float wx = dx * (width / 2) / length; float wy = dy * (width / 2) / length; AffineTransform xf = new AffineTransform(); xf.setRotation(FloatMath.atan2(dy, dx)); xf.setTranslation(x0 + wy, y0 - wx); Transforms.multiply(tx(), xf, xf); if (patternTex != null) { batch.addQuad(patternTex, tint, xf, 0, 0, length, width); } else { batch.addQuad(colorTex, Tint.combine(fillColor, tint), xf, 0, 0, length, width); } return this; }
@Override // from Transform public AffineTransform copy () { return new AffineTransform(m00, m01, m10, m11, tx, ty); }
/** Translates the current transformation matrix by the given amount. */ public Surface translate (float x, float y) { tx().translate(x, y); return this; }
@Override // from Transform public AffineTransform invert () { // compute the determinant, storing the subdeterminants for later use float det = m00*m11 - m10*m01; if (Math.abs(det) == 0f) { // determinant is zero; matrix is not invertible throw new NoninvertibleTransformException(this.toString()); } float rdet = 1f / det; return new AffineTransform( +m11 * rdet, -m10 * rdet, -m01 * rdet, +m00 * rdet, (m10*ty - m11*tx) * rdet, (m01*tx - m00*ty) * rdet); }
@Override // from Transform public void transform (IPoint[] src, int srcOff, Point[] dst, int dstOff, int count) { for (int ii = 0; ii < count; ii++) { transform(src[srcOff++], dst[dstOff++]); } }
protected void doStart(float x, float y) { _lstart = layer.transform().translation(); _pstart = new Vector(x, y); } protected void doMove(float x, float y) {
@Override // from Transform public Transform lerp (Transform other, float t) { if (generality() < other.generality()) { return other.lerp(this, -t); // TODO: is this correct? } AffineTransform ot = (other instanceof AffineTransform) ? (AffineTransform)other : new AffineTransform(other); return new AffineTransform( m00 + t*(ot.m00 - m00), m01 + t*(ot.m01 - m01), m10 + t*(ot.m10 - m10), m11 + t*(ot.m11 - m11), tx + t*(ot.tx - tx ), ty + t*(ot.ty - ty )); }