/** Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up. * @param radians the angle in radians * @param reference center Vector2 */ public Vector2 rotateAroundRad (Vector2 reference, float radians) { return this.sub(reference).rotateRad(radians).add(reference); }
/** Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up. * @param degrees the angle in degrees * @param reference center Vector2 */ public Vector2 rotateAround (Vector2 reference, float degrees) { return this.sub(reference).rotate(degrees).add(reference); }
/** Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up. * @param degrees the angle in degrees * @param reference center Vector2 */ public Vector2 rotateAround (Vector2 reference, float degrees) { return this.sub(reference).rotate(degrees).add(reference); }
/** Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up. * @param radians the angle in radians * @param reference center Vector2 */ public Vector2 rotateAroundRad (Vector2 reference, float radians) { return this.sub(reference).rotateRad(radians).add(reference); }
/** @return the {@link #position} with the {@link #selectedInterpolation interpolation} applied */ Vector2 getPosition (float time) { position.set(targetPosition); position.sub(startPosition); position.scl(getInterpolation(selectedInterpolation).apply(time / duration)); position.add(startPosition); return position; }
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); } } }
protected void renderBody (Body body) { Transform transform = body.getTransform(); for (Fixture fixture : body.getFixtureList()) { if (drawBodies) { drawShape(fixture, transform, getColorByBody(body)); if (drawVelocities) { Vector2 position = body.getPosition(); drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR); } } if (drawAABBs) { drawAABB(fixture, transform); } } }
/** Does not set the normal member! */ protected VertexInfo getVertexAt (final VertexInfo out, int x, int y) { final float dx = (float)x / (float)(width - 1); final float dy = (float)y / (float)(height - 1); final float a = data[y * width + x]; out.position.set(corner00).lerp(corner10, dx).lerp(tmpV1.set(corner01).lerp(corner11, dx), dy); out.position.add(tmpV1.set(magnitude).scl(a)); out.color.set(color00).lerp(color10, dx).lerp(tmpC.set(color01).lerp(color11, dx), dy); out.uv.set(dx, dy).scl(uvScale).add(uvOffset); return out; }
public void draw (Batch batch, float parentAlpha) { // Use Stage#toScreenCoordinates, which we know is correct. toScreenCoordinates.set(testX, testY).sub(getOriginX(), getOriginY()).scl(getScaleX(), getScaleY()).rotate(getRotation()) .add(getOriginX(), getOriginY()).add(getX(), getY()); getStage().toScreenCoordinates(toScreenCoordinates, batch.getTransformMatrix()); // Do the same as toScreenCoordinates via Actor#localToParentCoordinates. localToAscendantCoordinates(null, localToParentCoordinates.set(testX, testY)); getStage().stageToScreenCoordinates(localToParentCoordinates); // System.out.println(name + " " + toScreenCoordinates + " " + localToParentCoordinates); batch.setColor(getColor()); batch.draw(region, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation()); super.draw(batch, parentAlpha); } }
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); } }
tmpV2.set(-tmpV2.y, tmpV2.x); tmpV2.scl((float)Math.sin(zt) * ZIGZAG_SCALE); tmpV.add(tmpV2);
/** Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up. * @param radians the angle in radians * @param reference center Vector2 */ public Vector2 rotateAroundRad (Vector2 reference, float radians) { return this.sub(reference).rotateRad(radians).add(reference); }
/** Rotates the Vector2 by the given angle around reference vector, counter-clockwise assuming the y-axis points up. * @param degrees the angle in degrees * @param reference center Vector2 */ public Vector2 rotateAround (Vector2 reference, float degrees) { return this.sub(reference).rotate(degrees).add(reference); }
private Vector2 origin; private Vector2 distance; void ctor(){ origin = new Vector2(); distance = new Vector2(0, 100); } public void update(float Delta){ origin.set(200, 200); distance.rotate(40 * Delta); Vector2 newPos = origin.add(distance); sprite.setPosition(newPos.x - sprite.width/2, newPos.y - sprite.height/2); }
Shard(final Vector2 pos, final float size) { final float xRange = Gdx.graphics.getWidth() * EXPLOSION_X_RANGE; final float yRange = Gdx.graphics.getHeight() * EXPLOSION_Y_RANGE; vel = new Vector2(MathUtils.random(-xRange, +xRange), MathUtils.random(-yRange * 0.2f, +yRange)); acc = new Vector2(0f, Gdx.graphics.getHeight() * GRAVITY_PERCENTAGE); this.size = size * MathUtils.random(0.40f, 0.60f); this.pos = pos.cpy().add(this.size * 0.5f, this.size * 0.5f); }
@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); }