convert to a PVector class?
Hi
I have been trying this for two days...
How to convert this "example code of make a cuve" into a PVector class and get the new location or velocity from the other PVector class, I think someone ask a bout two objects question, I don't know if it the same.
- float beginX = 20.0; // Initial x-coordinate
float beginY = 10.0; // Initial y-coordinate
float endX = 570.0; // Final x-coordinate
float endY = 320.0; // Final y-coordinate
float distX; // X-axis distance to move
float distY; // Y-axis distance to move
float exponent = 4; // Determines the curve
float x = 0.0; // Current x-coordinate
float y = 0.0; // Current y-coordinate
float step = 0.01; // Size of each step along the path
float pct = 0.0; // Percentage traveled (0.0 to 1.0) - void setup()
{
size(640, 360);
noStroke();
smooth();
distX = endX - beginX;
distY = endY - beginY;
} - void draw()
{
fill(0, 2);
rect(0, 0, width, height);
pct += step;
if (pct < 1.0) {
x = beginX + (pct * distX);
y = beginY + (pow(pct, exponent) * distY);
}
fill(255);
ellipse(x, y, 20, 20);
} - void mousePressed() {
pct = 0.0;
beginX = x;
beginY = y;
endX = mouseX;
endY = mouseY;
distX = endX - beginX;
distY = endY - beginY;
}
I don't know what should be in constructor, and why? like this:
Ball(PVector P) {
velocity = new PVector();
location =new PVector();
PVector acceleration=PVector.sub(location,velocity) ;
}
or
Ball(float _x,float _y) {
x = _x;
y=_y;
}