/** Creates a circle map object * * @param x X coordinate * @param y Y coordinate * @param radius Radius of the circle object. */ public CircleMapObject (float x, float y, float radius) { super(); circle = new Circle(x, y, radius); } }
@Override public Actor hit (float x, float y, boolean touchable) { if (touchable && this.getTouchable() != Touchable.enabled) return null; if (!isVisible()) return null; return touchBounds.contains(x, y) ? this : null; }
public static boolean overlaps (Circle c1, Circle c2) { return c1.overlaps(c2); }
@Test public void testCircle () { Circle c1 = new Circle(0, 0, 1); Circle c2 = new Circle(0, 0, 1); Circle c3 = new Circle(2, 0, 1); Circle c4 = new Circle(0, 0, 2); assertTrue(c1.overlaps(c1)); assertTrue(c1.overlaps(c2)); assertFalse(c1.overlaps(c3)); assertTrue(c1.overlaps(c4)); assertTrue(c4.overlaps(c1)); assertTrue(c1.contains(0, 1)); assertFalse(c1.contains(0, 2)); assertTrue(c1.contains(c1)); assertFalse(c1.contains(c4)); assertTrue(c4.contains(c1)); }
@Override public void layout () { // Recalc pad and deadzone bounds float halfWidth = getWidth() / 2; float halfHeight = getHeight() / 2; float radius = Math.min(halfWidth, halfHeight); touchBounds.set(halfWidth, halfHeight, radius); if (style.knob != null) radius -= Math.max(style.knob.getMinWidth(), style.knob.getMinHeight()) / 2; knobBounds.set(halfWidth, halfHeight, radius); deadzoneBounds.set(halfWidth, halfHeight, deadzoneRadius); // Recalc pad values and knob position knobPosition.set(halfWidth, halfHeight); knobPercent.set(0, 0); }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((circle == null) ? 0 : circle.hashCode()); return result; }
@Override public void scale(float scale) { circle.setRadius(circle.radius * scale); setDirty(); }
@Override public void layout () { // Recalc pad and deadzone bounds float halfWidth = getWidth() / 2; float halfHeight = getHeight() / 2; float radius = Math.min(halfWidth, halfHeight); touchBounds.set(halfWidth, halfHeight, radius); if (style.knob != null) radius -= Math.max(style.knob.getMinWidth(), style.knob.getMinHeight()) / 2; knobBounds.set(halfWidth, halfHeight, radius); deadzoneBounds.set(halfWidth, halfHeight, deadzoneRadius); // Recalc pad values and knob position knobPosition.set(halfWidth, halfHeight); knobPercent.set(0, 0); }
/** Creates a circle map object * * @param x X coordinate * @param y Y coordinate * @param radius Radius of the circle object. */ public CircleMapObject (float x, float y, float radius) { super(); circle = new Circle(x, y, radius); } }
@Override public Actor hit (float x, float y, boolean touchable) { if (touchable && this.getTouchable() != Touchable.enabled) return null; if (!isVisible()) return null; return touchBounds.contains(x, y) ? this : null; }
public static boolean overlaps (Circle c1, Circle c2) { return c1.overlaps(c2); }
@Override public void layout () { // Recalc pad and deadzone bounds float halfWidth = getWidth() / 2; float halfHeight = getHeight() / 2; float radius = Math.min(halfWidth, halfHeight); touchBounds.set(halfWidth, halfHeight, radius); if (style.knob != null) radius -= Math.max(style.knob.getMinWidth(), style.knob.getMinHeight()) / 2; knobBounds.set(halfWidth, halfHeight, radius); deadzoneBounds.set(halfWidth, halfHeight, deadzoneRadius); // Recalc pad values and knob position knobPosition.set(halfWidth, halfHeight); knobPercent.set(0, 0); }
/** * Constructs a {@link Circle} as a copy of another * @param circle The {@link Circle} to copy */ public Circle(Circle circle) { this.circle = new com.badlogic.gdx.math.Circle(circle.circle); }
void calculatePositionAndValue (float x, float y, boolean isTouchUp) { float oldPositionX = knobPosition.x; float oldPositionY = knobPosition.y; float oldPercentX = knobPercent.x; float oldPercentY = knobPercent.y; float centerX = knobBounds.x; float centerY = knobBounds.y; knobPosition.set(centerX, centerY); knobPercent.set(0f, 0f); if (!isTouchUp) { if (!deadzoneBounds.contains(x, y)) { knobPercent.set((x - centerX) / knobBounds.radius, (y - centerY) / knobBounds.radius); float length = knobPercent.len(); if (length > 1) knobPercent.scl(1 / length); if (knobBounds.contains(x, y)) { knobPosition.set(x, y); } else { knobPosition.set(knobPercent).nor().scl(knobBounds.radius).add(knobBounds.x, knobBounds.y); } } } if (oldPercentX != knobPercent.x || oldPercentY != knobPercent.y) { ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class); if (fire(changeEvent)) { knobPercent.set(oldPercentX, oldPercentY); knobPosition.set(oldPositionX, oldPositionY); } Pools.free(changeEvent); } }
public static boolean overlaps (Circle c1, Circle c2) { return c1.overlaps(c2); }
/** Creates a circle map object * * @param x X coordinate * @param y Y coordinate * @param radius Radius of the circle object. */ public CircleMapObject (float x, float y, float radius) { super(); circle = new Circle(x, y, radius); } }
void calculatePositionAndValue (float x, float y, boolean isTouchUp) { float oldPositionX = knobPosition.x; float oldPositionY = knobPosition.y; float oldPercentX = knobPercent.x; float oldPercentY = knobPercent.y; float centerX = knobBounds.x; float centerY = knobBounds.y; knobPosition.set(centerX, centerY); knobPercent.set(0f, 0f); if (!isTouchUp) { if (!deadzoneBounds.contains(x, y)) { knobPercent.set((x - centerX) / knobBounds.radius, (y - centerY) / knobBounds.radius); float length = knobPercent.len(); if (length > 1) knobPercent.scl(1 / length); if (knobBounds.contains(x, y)) { knobPosition.set(x, y); } else { knobPosition.set(knobPercent).nor().scl(knobBounds.radius).add(knobBounds.x, knobBounds.y); } } } if (oldPercentX != knobPercent.x || oldPercentY != knobPercent.y) { ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class); if (fire(changeEvent)) { knobPercent.set(oldPercentX, oldPercentY); knobPosition.set(oldPositionX, oldPositionY); } Pools.free(changeEvent); } }
/** * Constructs a {@link Circle} with a center and radius * @param centerX The center x coordinate * @param centerY The center y coordinate * @param radius The radius */ public Circle(float centerX, float centerY, float radius) { this.circle = new com.badlogic.gdx.math.Circle(centerX, centerY, radius); }
/** * Returns if another {@link Circle} is contained within this one * @param circle The {@link Circle} to check * @return True if the other {@link Circle} is contained within this one */ public boolean contains(Circle circle) { return this.circle.contains(circle.circle); }
public Circle getCurrentCircle(float elapsedTime) { float x = originX + magnitude * MathUtils.cos(angle) * MathUtils.sin(MathUtils.PI2 * elapsedTime / period); float y = originY + magnitude * MathUtils.sin(angle) * MathUtils.sin(MathUtils.PI2 * elapsedTime / period); return new Circle(x, y, radius); } }