/** Creates a new {@link Circle} in terms of its center and a point on its edge. * * @param center The center of the new circle * @param edge Any point on the edge of the given circle */ public Circle (Vector2 center, Vector2 edge) { this.x = center.x; this.y = center.y; this.radius = Vector2.len(center.x - edge.x, center.y - edge.y); }
/** Creates a new {@link Circle} in terms of its center and a point on its edge. * * @param center The center of the new circle * @param edge Any point on the edge of the given circle */ public Circle (Vector2 center, Vector2 edge) { this.x = center.x; this.y = center.y; this.radius = Vector2.len(center.x - edge.x, center.y - edge.y); }
/** Sets this {@link Circle}'s values in terms of its center and a point on its edge. * * @param center The new center of the circle * @param edge Any point on the edge of the given circle */ public void set (Vector2 center, Vector2 edge) { this.x = center.x; this.y = center.y; this.radius = Vector2.len(center.x - edge.x, center.y - edge.y); }
/** Sets this {@link Circle}'s values in terms of its center and a point on its edge. * * @param center The new center of the circle * @param edge Any point on the edge of the given circle */ public void set (Vector2 center, Vector2 edge) { this.x = center.x; this.y = center.y; this.radius = Vector2.len(center.x - edge.x, center.y - edge.y); }
@Override public Vector2 nor () { float len = len(); if (len != 0) { x /= len; y /= len; } return this; }
@Override public Vector2 nor () { float len = len(); if (len != 0) { x /= len; y /= len; } return this; }
/** The distance from drag start to the current drag position. */ public float getDragDistance () { return Vector2.len(dragX - dragStartX, dragY - dragStartY); }
/** The distance from drag start to the current drag position. */ public float getDragDistance () { return Vector2.len(dragX - dragStartX, dragY - dragStartY); }
/** Sets the angle of the vector in radians relative to the x-axis, towards the positive y-axis (typically counter-clockwise). * @param radians The angle in radians to set. */ public Vector2 setAngleRad (float radians) { this.set(len(), 0f); this.rotateRad(radians); return this; }
/** Sets the angle of the vector in radians relative to the x-axis, towards the positive y-axis (typically counter-clockwise). * @param radians The angle in radians to set. */ public Vector2 setAngleRad (float radians) { this.set(len(), 0f); this.rotateRad(radians); return this; }
public void update (float deltaTime) { dist += dir.len() * deltaTime; if (dist > maxDist) { dir.scl(-1); dist = 0; } platform.setLinearVelocity(dir); } }
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); } }
t2 += avg_speed * Gdx.graphics.getDeltaTime() / tmpV3.len();
@Override public Vector2 nor () { float len = len(); if (len != 0) { x /= len; y /= len; } return this; }
/** Creates a new {@link Circle} in terms of its center and a point on its edge. * * @param center The center of the new circle * @param edge Any point on the edge of the given circle */ public Circle (Vector2 center, Vector2 edge) { this.x = center.x; this.y = center.y; this.radius = Vector2.len(center.x - edge.x, center.y - edge.y); }
/** Sets this {@link Circle}'s values in terms of its center and a point on its edge. * * @param center The new center of the circle * @param edge Any point on the edge of the given circle */ public void set (Vector2 center, Vector2 edge) { this.x = center.x; this.y = center.y; this.radius = Vector2.len(center.x - edge.x, center.y - edge.y); }
int samples = 100; //the higher the more accurate, however slower float derivativeAverage = 0; Vector2 out = new Vector2(); for (float i=0;i<1;i+=1f/samples) { catmull.derivativeAt(out, i); derivativeAverage += out.len(); } derivativeAverage /= samples;
/** Sets the angle of the vector in radians relative to the x-axis, towards the positive y-axis (typically counter-clockwise). * @param radians The angle in radians to set. */ public Vector2 setAngleRad (float radians) { this.set(len(), 0f); this.rotateRad(radians); return this; }
@Override public void onSubstepCompleted () { carState.update(carDesc); driftState.update(carSim.lateralForceFront.y, carSim.lateralForceRear.y, carDesc.velocity_wc.len()); if (Config.Debug.ApplyCarFrictionFromMap) { updateCarFriction(); handleFriction(); } }