PVector pos = friendlies.get(i); // direction vector PVector dir = new PVector(mouseX - pos.x, mouseY - pos.y); // now it becomes unit-vector (with length 1) dir.normalize(); pos.x = pos.x + dir.x * factor; pos.y = pos.y + dir.y * factor;
/** * Sets the magnitude of this vector, storing the result in another vector. * @param target Set to null to create a new vector * @param len the new length for the new vector * @return a new vector (if target was null), or target */ public PVector setMag(PVector target, float len) { target = normalize(target); target.mult(len); return target; }
/** * Sets the magnitude of this vector, storing the result in another vector. * @param target Set to null to create a new vector * @param len the new length for the new vector * @return a new vector (if target was null), or target */ public PVector setMag(PVector target, float len) { target = normalize(target); target.mult(len); return target; }
/** * ( begin auto-generated from PVector_setMag.xml ) * * Set the magnitude of this vector to the value used for the <b>len</b> parameter. * * ( end auto-generated ) * * @webref pvector:method * @usage web_application * @param len the new length for this vector * @brief Set the magnitude of the vector */ public void setMag(float len) { normalize(); mult(len); }
/** * ( begin auto-generated from PVector_setMag.xml ) * * Set the magnitude of this vector to the value used for the <b>len</b> parameter. * * ( end auto-generated ) * * @webref pvector:method * @usage web_application * @param len the new length for this vector * @brief Set the magnitude of the vector */ public PVector setMag(float len) { normalize(); mult(len); return this; }
for (int i = 0; i < movers.length; i++) { float c = 0.01; PVector friction = movers[i].velocity.get(); friction.mult(-1); friction.normalize(); friction.mult(c); movers[i].applyForce(friction); movers[i].applyForce(wind); movers[i].applyForce(gravity); movers[i].update(); movers[i].display(); movers[i].checkEdges(); }
/** * ( begin auto-generated from PVector_limit.xml ) * * Limit the magnitude of this vector to the value used for the <b>max</b> parameter. * * ( end auto-generated ) * * @webref pvector:method * @usage web_application * @param max the maximum magnitude for the vector * @brief Limit the magnitude of the vector */ public void limit(float max) { if (magSq() > max*max) { normalize(); mult(max); } }
/** * ( begin auto-generated from PVector_limit.xml ) * * Limit the magnitude of this vector to the value used for the <b>max</b> parameter. * * ( end auto-generated ) * * @webref pvector:method * @usage web_application * @param max the maximum magnitude for the vector * @brief Limit the magnitude of the vector */ public PVector limit(float max) { if (magSq() > max*max) { normalize(); mult(max); } return this; }
protected float computeRotation(Touch touch0, Touch touch1) { PVector currentDirection = PVector.sub(touch0.pposition, touch1.pposition); PVector previousDirection = PVector.sub(touch0.position, touch1.position); currentDirection.normalize(); previousDirection.normalize(); float cos = currentDirection.dot(previousDirection); float angle = acos(cos); PVector sin = currentDirection.cross(previousDirection); if (sin.z < 0) { angle = -angle; } return angle; }
dir.normalize(); // Normalize dir.mult(4); // Scale acceleration = dir;