@Override public Vector2 setLength2 (float len2) { float oldLen2 = len2(); return (oldLen2 == 0 || oldLen2 == len2) ? this : scl((float)Math.sqrt(len2 / oldLen2)); }
@Override public Vector2 limit2 (float limit2) { float len2 = len2(); if (len2 > limit2) { return scl((float)Math.sqrt(limit2 / len2)); } return this; }
@Override public Vector2 setLength2 (float len2) { float oldLen2 = len2(); return (oldLen2 == 0 || oldLen2 == len2) ? this : scl((float)Math.sqrt(len2 / oldLen2)); }
@Override public Vector2 limit2 (float limit2) { float len2 = len2(); if (len2 > limit2) { return scl((float)Math.sqrt(limit2 / len2)); } return this; }
public void update (float deltaTime) { dist += dir.len() * deltaTime; if (dist > maxDist) { dir.scl(-1); dist = 0; } platform.setLinearVelocity(dir); } }
/** @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; }
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); } }
/** 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 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); } } }
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); } }
tmpV2.nor(); tmpV2.set(-tmpV2.y, tmpV2.x); tmpV2.scl((float)Math.sin(zt) * ZIGZAG_SCALE); tmpV.add(tmpV2);
float camX = camera.position.x; float camY = camera.position.y; Vector2 camMin = new Vector2(camera.viewportWidth, camera.viewportHeight); camMin.scl(camera.zoom/2); //bring to center and scale by the zoom level Vector2 camMax = new Vector2(borderWidth, borderHeight); camMax.sub(camMin); //bring to center //keep camera within borders camX = Math.min(camMax.x, Math.max(camX, camMin.x)); camY = Math.min(camMax.y, Math.max(camY, camMin.y)); camera.position.set(camX, camY, camera.position.z);
@Override public Vector2 setLength2 (float len2) { float oldLen2 = len2(); return (oldLen2 == 0 || oldLen2 == len2) ? this : scl((float)Math.sqrt(len2 / oldLen2)); }
@Override public Vector2 setLength2 (float len2) { float oldLen2 = len2(); return (oldLen2 == 0 || oldLen2 == len2) ? this : scl((float)Math.sqrt(len2 / oldLen2)); }