/** Creates an affine transform from the supplied scale, rotation and translation. */ public AffineTransform (float scaleX, float scaleY, float angle, float tx, float ty) { float sina = FloatMath.sin(angle), cosa = FloatMath.cos(angle); this.m00 = cosa * scaleX; this.m01 = sina * scaleY; this.m10 = -sina * scaleX; this.m11 = cosa * scaleY; this.tx = tx; this.ty = ty; }
@Override // from IQuaternion public float getRotationZ () { return FloatMath.atan2(2f*(x*y + z*w), 1f - 2f*(y*y + z*z)); }
@Override public Canvas drawArc(float cx, float cy, float r, float startAngle, float arcAngle) { int top = (int) (cx - r); int left = (int) (cy - r); int diam = (int) (2*r); currentState().prepareStroke(g2d); g2d.drawArc(top, left, diam, diam, FloatMath.round(FloatMath.toDegrees(startAngle)), FloatMath.round(FloatMath.toDegrees(arcAngle))); isDirty = true; return this; }
/** * Sets the location, size, angular extents, and closure type of this arc based on the * specified values. */ public void setArcByTangent (XY p1, XY p2, XY p3, float radius) { // use simple geometric calculations of arc center, radius and angles by tangents float a1 = -FloatMath.atan2(p1.y() - p2.y(), p1.x() - p2.x()); float a2 = -FloatMath.atan2(p3.y() - p2.y(), p3.x() - p2.x()); float am = (a1 + a2) / 2f; float ah = a1 - am; float d = radius / Math.abs(FloatMath.sin(ah)); float x = p2.x() + d * FloatMath.cos(am); float y = p2.y() - d * FloatMath.sin(am); ah = ah >= 0f ? FloatMath.PI * 1.5f - ah : FloatMath.PI * 0.5f - ah; a1 = normAngle(FloatMath.toDegrees(am - ah)); a2 = normAngle(FloatMath.toDegrees(am + ah)); float delta = a2 - a1; if (delta <= 0f) { delta += 360f; } setArcByCenter(x, y, radius, a1, delta, type); }
@Override public void update(int delta) { elapsed += delta/1000f; i1.setRotation(elapsed * FloatMath.PI/2); s1.setRotation(elapsed * FloatMath.PI/2); g2.setWidth(Math.round(Math.abs(100 * FloatMath.sin(elapsed)))); inner.setOrigin(FloatMath.sin(elapsed * 2f) * 50, FloatMath.cos(elapsed * 2f) * 50); float cycle = elapsed / (FloatMath.PI * 2); if (FloatMath.ifloor(cycle) % 2 == 0) { // go in a circle without going out of bounds g5Inner.setTranslation(-25 + 50 * FloatMath.cos(elapsed), -25 + 50 * FloatMath.sin(elapsed)); } else { // go out of bounds on right and left g5Inner.setTranslation(25 + 250 * FloatMath.cos(elapsed + FloatMath.PI/2), -25); } } }
/** * Sets the starting angle and angular extent of this arc using two sets of coordinates. The * first set of coordinates is used to determine the angle of the starting point relative to * the arc's center. The second set of coordinates is used to determine the angle of the end * point relative to the arc's center. The arc will always be non-empty and extend * counterclockwise from the first point around to the second point. */ public void setAngles (float x1, float y1, float x2, float y2) { float cx = centerX(); float cy = centerY(); float a1 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y1 - cy, x1 - cx))); float a2 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y2 - cy, x2 - cx))); a2 -= a1; if (a2 <= 0f) { a2 += 360f; } setAngleStart(a1); setAngleExtent(a2); }
/** * 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 public void update(int delta) { elapsed += delta; if (osci != null) { // round the width so that it sometimes goes to zero; just to be sure zero doesn't choke float width = Math.round(Math.abs(FloatMath.sin(elapsed/1000f)) * osci.parent().width()); osci.setBounds(0, 0, width, osci.parent().height()); } }
@Override // from IQuaternion public Vector3 toAngles (Vector3 result) { float sy = 2f*(y*w - x*z); if (sy < 1f - MathUtil.EPSILON) { if (sy > -1 + MathUtil.EPSILON) { return result.set(FloatMath.atan2(y*z + x*w, 0.5f - (x*x + y*y)), FloatMath.asin(sy), FloatMath.atan2(x*y + z*w, 0.5f - (y*y + z*z))); } else { // not a unique solution; x + z = atan2(-m21, m11) return result.set(0f, -MathUtil.HALF_PI, FloatMath.atan2(x*w - y*z, 0.5f - (x*x + z*z))); } } else { // not a unique solution; x - z = atan2(-m21, m11) return result.set(0f, MathUtil.HALF_PI, -FloatMath.atan2(x*w - y*z, 0.5f - (x*x + z*z))); } }
@Override public Canvas drawArc(float cx, float cy, float r, float startAngle, float arcAngle) { float left = cx - r; float top = cy - r; float right = cx + r; float bottom = cy + r; rectf.set(left, top, right, bottom); canvas.drawArc(rectf, -FloatMath.toDegrees(startAngle), -FloatMath.toDegrees(arcAngle), false, currentState().prepareStroke()); isDirty = true; return this; }
/** * Sets the location, size, angular extents, and closure type of this arc based on the * specified values. */ public void setArcByTangent (XY p1, XY p2, XY p3, float radius) { // use simple geometric calculations of arc center, radius and angles by tangents float a1 = -FloatMath.atan2(p1.y() - p2.y(), p1.x() - p2.x()); float a2 = -FloatMath.atan2(p3.y() - p2.y(), p3.x() - p2.x()); float am = (a1 + a2) / 2f; float ah = a1 - am; float d = radius / Math.abs(FloatMath.sin(ah)); float x = p2.x() + d * FloatMath.cos(am); float y = p2.y() - d * FloatMath.sin(am); ah = ah >= 0f ? FloatMath.PI * 1.5f - ah : FloatMath.PI * 0.5f - ah; a1 = normAngle(FloatMath.toDegrees(am - ah)); a2 = normAngle(FloatMath.toDegrees(am + ah)); float delta = a2 - a1; if (delta <= 0f) { delta += 360f; } setArcByCenter(x, y, radius, a1, delta, type); }
i1.setRotation(elapsed * FloatMath.PI/2); s1.setRotation(elapsed * FloatMath.PI/2); g2.setWidth(Math.round(Math.abs(100 * FloatMath.sin(elapsed)))); inner.setOrigin(FloatMath.sin(elapsed * 2f) * 50, FloatMath.cos(elapsed * 2f) * 50); float cycle = elapsed / (FloatMath.PI * 2); if (FloatMath.ifloor(cycle) % 2 == 0) { g5Inner.setTranslation(-25 + 50 * FloatMath.cos(elapsed), -25 + 50 * FloatMath.sin(elapsed)); } else { g5Inner.setTranslation(25 + 250 * FloatMath.cos(elapsed + FloatMath.PI/2), -25);
/** * Sets the starting angle and angular extent of this arc using two sets of coordinates. The * first set of coordinates is used to determine the angle of the starting point relative to * the arc's center. The second set of coordinates is used to determine the angle of the end * point relative to the arc's center. The arc will always be non-empty and extend * counterclockwise from the first point around to the second point. */ public void setAngles (float x1, float y1, float x2, float y2) { float cx = centerX(); float cy = centerY(); float a1 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y1 - cy, x1 - cx))); float a2 = normAngle(-FloatMath.toDegrees(FloatMath.atan2(y2 - cy, x2 - cx))); a2 -= a1; if (a2 <= 0f) { a2 += 360f; } setAngleStart(a1); setAngleExtent(a2); }
/** * 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 public void paint(float alpha) { super.paint(alpha); float now = elapsed + alpha*UPDATE_RATE; float scale = Math.abs(FloatMath.sin(now/1000)); player1.setScale(scale); player2.setScale(scale); slayer1.setScale(scale); slayer2.setScale(scale); } }