/** * Transforms a vector as specified, storing the result in the vector provided. * @return a reference to the result vector, for chaining. */ public static Vector transform (float x, float y, float sx, float sy, float sina, float cosa, Vector result) { return result.set((x*cosa - y*sina) * sx, (x*sina + y*cosa) * sy); }
@Override // from interface IVector public Vector clone () { return new Vector(this); }
/** * Sets this vector's magnitude, preserving its angle. */ public Vector setLength (float length) { return normalizeLocal().scaleLocal(length); }
protected void onMove(float x, float y) { Vector delta = new Vector(x, y).subtractLocal(_pstart); layer.setTranslation(_lstart.x + delta.x, _lstart.y + delta.y); }
@Override // from IRay2 public boolean getIntersection (IVector center, float radius, Vector result) { // see if we start inside the circle if (origin.distanceSq(center) <= radius*radius) { result.set(origin); return true; } // then if we intersect the circle float ax = origin.x - center.x(), ay = origin.y - center.y(); float b = 2f*(direction.x*ax + direction.y*ay); float c = ax*ax + ay*ay - radius*radius; float radicand = b*b - 4f*c; if (radicand < 0f) { return false; } float t = (-b - FloatMath.sqrt(radicand)) * 0.5f; boolean isect = (t >= 0f); if (isect) { origin.addScaled(direction, t, result); } return isect; }
@Override protected void update (Clock clock, Entities entities) { Point p = _pos; Vector v = _vel; int delta = clock.dt; for (int ii = 0, ll = entities.size(); ii < ll; ii++) { int eid = entities.get(ii); pos.get(eid, p); // get our current pos p.x = wrapx(p.x); // wrap it around the screen if necessary p.y = wrapy(p.y); opos.set(eid, p); // copy wrapped pos to opos vel.get(eid, v).scaleLocal(delta); // turn velocity into delta pos pos.set(eid, p.x + v.x, p.y + v.y); // add velocity (but don't wrap) } }
/** Adds a scaled vector in-place to this one. * @return a reference to this vector, for chaining. */ public Vector addScaledLocal (IVector other, float v) { return addScaled(other, v, this); }
/** Adds a vector in-place to this one. * @return a reference to this vector, for chaining. */ public Vector addLocal (IVector other) { return add(other, this); }
protected void doMove(float x, float y) { Vector delta = new Vector(x, y).subtractLocal(_pstart); layer.setTranslation(_lstart.x + delta.x, _lstart.y + delta.y); }
@Override // from IRay2 public boolean getIntersection (IVector center, float radius, Vector result) { // see if we start inside the circle if (origin.distanceSq(center) <= radius*radius) { result.set(origin); return true; } // then if we intersect the circle float ax = origin.x - center.x(), ay = origin.y - center.y(); float b = 2f*(direction.x*ax + direction.y*ay); float c = ax*ax + ay*ay - radius*radius; float radicand = b*b - 4f*c; if (radicand < 0f) { return false; } float t = (-b - FloatMath.sqrt(radicand)) * 0.5f; boolean isect = (t >= 0f); if (isect) { origin.addScaled(direction, t, result); } return isect; }
/** Adds a scaled vector in-place to this one. * @return a reference to this vector, for chaining. */ public Vector addScaledLocal (IVector other, float v) { return addScaled(other, v, this); }
/** Adds a vector in-place to this one. * @return a reference to this vector, for chaining. */ public Vector addLocal (float x, float y) { return add(x, y, this); }
/** Transforms a vector as specified (as a point, accounting for translation), storing the * result in the vector provided. * @return a reference to the result vector, for chaining. */ public static Vector transform (float x, float y, float sx, float sy, float sina, float cosa, float tx, float ty, Vector result) { return result.set((x*cosa - y*sina) * sx + tx, (x*sina + y*cosa) * sy + ty); }
@Override // from interface IVector public Vector negate () { return negate(new Vector()); }
@Override public void onMouseDrag(MotionEvent event) { Vector delta = new Vector(event.x(), event.y()).subtractLocal(_pstart); label.setTranslation(_lstart.x + delta.x, _lstart.y + delta.y); modify(event); motionLabel.set("mouse drag", describe(event, "")); } @Override
/** * Sets this vector's magnitude, preserving its angle. */ public Vector setLength (float length) { return normalizeLocal().scaleLocal(length); }