Changing a flow field at runtime
in
Programming Questions
•
3 years ago
Hi!
Using Daniel Shiffman's flow field as a base, I'm trying to alter the flow field at runtime, using the mouse as a sort of brush that alters the direction of the field (and possibly nearby ones). I thought I'd start off by trying to get all fields point toward the mouse pointer, and this is what I've come up with so far (
field being a two-dimensional array of PVectors):
public void face(float x, float y) {
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
PVector direction = new PVector(x, y);
direction.normalize();
field[i][j] = direction;
}
}
}
To be honest I'm quite at a loss as to how to get all fields to point toward the mouse, but the above code at least changes their direction, though they appear to be using the upper left corner of the window as the origin and the mouse coordinates as the target vector, causing this to happen:
Instead, each one of those "waves" should converge on the mouse coordinates.
Any help would be appreciated!
1