/** * 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; }
/** * 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; }