/** Checks whether the line segment and the circle intersect and returns by how much and in what direction the line has to move * away from the circle to not intersect. * * @param start The line segment starting point * @param end The line segment end point * @param point The center of the circle * @param radius The radius of the circle * @param displacement The displacement vector set by the method having unit length * @return The displacement or Float.POSITIVE_INFINITY if no intersection is present */ public static float intersectSegmentCircleDisplace (Vector2 start, Vector2 end, Vector2 point, float radius, Vector2 displacement) { float u = (point.x - start.x) * (end.x - start.x) + (point.y - start.y) * (end.y - start.y); float d = start.dst(end); u /= d * d; if (u < 0 || u > 1) return Float.POSITIVE_INFINITY; tmp.set(end.x, end.y, 0).sub(start.x, start.y, 0); tmp2.set(start.x, start.y, 0).add(tmp.scl(u)); d = tmp2.dst(point.x, point.y, 0); if (d < radius) { displacement.set(point).sub(tmp2.x, tmp2.y).nor(); return d; } else return Float.POSITIVE_INFINITY; }
/** Checks whether the line segment and the circle intersect and returns by how much and in what direction the line has to move * away from the circle to not intersect. * * @param start The line segment starting point * @param end The line segment end point * @param point The center of the circle * @param radius The radius of the circle * @param displacement The displacement vector set by the method having unit length * @return The displacement or Float.POSITIVE_INFINITY if no intersection is present */ public static float intersectSegmentCircleDisplace (Vector2 start, Vector2 end, Vector2 point, float radius, Vector2 displacement) { float u = (point.x - start.x) * (end.x - start.x) + (point.y - start.y) * (end.y - start.y); float d = start.dst(end); u /= d * d; if (u < 0 || u > 1) return Float.POSITIVE_INFINITY; tmp.set(end.x, end.y, 0).sub(start.x, start.y, 0); tmp2.set(start.x, start.y, 0).add(tmp.scl(u)); d = tmp2.dst(point.x, point.y, 0); if (d < radius) { displacement.set(point).sub(tmp2.x, tmp2.y).nor(); return d; } else return Float.POSITIVE_INFINITY; }
public void solveFakeIK (Vector3 target) { float gravity = Gdx.graphics.getDeltaTime() * GRAVITY; endPoint.set(target); bones[0].position.set(endPoint); for (int i = 0; i < bones.length - 1; i++) { Bone bone = bones[i]; endPoint.set(bone.position); diff.set(endPoint.x, endPoint.y).sub(bones[i + 1].position.x, bones[i + 1].position.y); diff.add(0, gravity); diff.add(bones[i + 1].inertia.x, bones[i + 1].inertia.y); diff.nor().scl(bones[i + 1].len); float x = endPoint.x - diff.x; float y = endPoint.y - diff.y; float delta = Gdx.graphics.getDeltaTime(); bones[i + 1].inertia.add((bones[i + 1].position.x - x) * delta, (bones[i + 1].position.y - y) * delta, 0).scl(0.99f); bones[i + 1].position.set(x, y, 0); } } }
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); } }
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); } }
axis.nor(); pjd.initialize(ground, body, new Vector2(0, 0), axis);
tmpV2.nor(); tmpV2.set(-tmpV2.y, tmpV2.x); tmpV2.scl((float)Math.sin(zt) * ZIGZAG_SCALE);
check(ShapeType.Line, ShapeType.Filled, 8); float colorBits = color.toFloatBits(); Vector2 t = tmp.set(y2 - y1, x1 - x2).nor(); width *= 0.5f; float tx = t.x * width;
check(ShapeType.Line, ShapeType.Filled, 8); float colorBits = color.toFloatBits(); Vector2 t = tmp.set(y2 - y1, x1 - x2).nor(); width *= 0.5f; float tx = t.x * width;
float col1Bits = c1.toFloatBits(); float col2Bits = c2.toFloatBits(); Vector2 t = tmp.set(y2 - y1, x1 - x2).nor(); width *= 0.5f; float tx = t.x * width;
float col1Bits = c1.toFloatBits(); float col2Bits = c2.toFloatBits(); Vector2 t = tmp.set(y2 - y1, x1 - x2).nor(); width *= 0.5f; float tx = t.x * width;
Vector2 target = new Vector2(GameWorld.getBall().getX(), GameWorld.getBall().getY()); target.sub(getX(), getY()); target.nor().scl(BULLET_HOMING); velocity.add(target.scl(delta)); velocity.nor().scl(BULLET_SPEED); Vector2 v = velocity.cpy().scl(delta); translate(v.x, v.y); setOriginCenter(); setRotation(velocity.angle());
@Override public void moveTowards(float x, float y, float speed) { TMP_SOURCE_VECTOR.set(getX(), getY()); TMP_TARGET_VECTOR.set(x, y); Vector2 direction = TMP_TARGET_VECTOR.sub(TMP_SOURCE_VECTOR).nor(); float xComponent = speed * MathUtils.cosDeg(direction.angle()); float yComponent = speed * MathUtils.sinDeg(direction.angle()); TMP_SOURCE_VECTOR.add(xComponent, yComponent); set(TMP_SOURCE_VECTOR.x, TMP_SOURCE_VECTOR.y); }
@Override public void moveTowards(float x, float y, float speed) { TMP_SOURCE_VECTOR.set(getX(), getY()); TMP_TARGET_VECTOR.set(x, y); Vector2 direction = TMP_TARGET_VECTOR.sub(TMP_SOURCE_VECTOR).nor(); float xComponent = speed * MathUtils.cosDeg(direction.angle()); float yComponent = speed * MathUtils.sinDeg(direction.angle()); TMP_SOURCE_VECTOR.add(xComponent, yComponent); set(TMP_SOURCE_VECTOR.x, TMP_SOURCE_VECTOR.y); }
public void moveTowards(float x, float y, float speed) { TMP_SOURCE_VECTOR.set(getX(), getY()); TMP_TARGET_VECTOR.set(x, y); Vector2 direction = TMP_TARGET_VECTOR.sub(TMP_SOURCE_VECTOR).nor(); float xComponent = speed * MathUtils.cosDeg(direction.angle()); float yComponent = speed * MathUtils.sinDeg(direction.angle()); TMP_SOURCE_VECTOR.add(xComponent, yComponent); set(TMP_SOURCE_VECTOR.x, TMP_SOURCE_VECTOR.y); }
@Override public void moveTowards(float x, float y, float speed) { TMP_SOURCE_VECTOR.set(getX(), getY()); TMP_TARGET_VECTOR.set(x, y); Vector2 direction = TMP_TARGET_VECTOR.sub(TMP_SOURCE_VECTOR).nor(); float xComponent = speed * MathUtils.cosDeg(direction.angle()); float yComponent = speed * MathUtils.sinDeg(direction.angle()); TMP_SOURCE_VECTOR.add(xComponent, yComponent); set(TMP_SOURCE_VECTOR.x, TMP_SOURCE_VECTOR.y); }
public void moveTowards(float x, float y, float speed) { TMP_SOURCE_VECTOR.set(getX(), getY()); TMP_TARGET_VECTOR.set(x, y); Vector2 direction = TMP_TARGET_VECTOR.sub(TMP_SOURCE_VECTOR).nor(); float xComponent = speed * MathUtils.cosDeg(direction.angle()); float yComponent = speed * MathUtils.sinDeg(direction.angle()); TMP_SOURCE_VECTOR.add(xComponent, yComponent); set(TMP_SOURCE_VECTOR.x, TMP_SOURCE_VECTOR.y); }
@Override public void moveTowards(float x, float y, float speed) { TMP_SOURCE_VECTOR.set(getX(), getY()); TMP_TARGET_VECTOR.set(x, y); Vector2 direction = TMP_TARGET_VECTOR.sub(TMP_SOURCE_VECTOR).nor(); float xComponent = speed * MathUtils.cosDeg(direction.angle()); float yComponent = speed * MathUtils.sinDeg(direction.angle()); TMP_SOURCE_VECTOR.add(xComponent, yComponent); set(TMP_SOURCE_VECTOR.x, TMP_SOURCE_VECTOR.y); }
@Override public void moveTowards(float x, float y, float speed) { TMP_SOURCE_VECTOR.set(getX(), getY()); TMP_TARGET_VECTOR.set(x, y); Vector2 direction = TMP_TARGET_VECTOR.sub(TMP_SOURCE_VECTOR).nor(); float xComponent = speed * MathUtils.cosDeg(direction.angle()); float yComponent = speed * MathUtils.sinDeg(direction.angle()); TMP_SOURCE_VECTOR.add(xComponent, yComponent); set(TMP_SOURCE_VECTOR.x, TMP_SOURCE_VECTOR.y); }