I'm currently working on something that allows the user to "fire" points around the canvas, with each point connecting to all other points, creating cool geometric shapes. Although I'm having some difficulties with the aiming system. This is the current code I am using:
void mousePressed() {
vecXStart = mouseX;
vecYStart = mouseY;
aimDraw = true;
}
void mouseReleased() {
float vecX = vecXStart - mouseX;
float vecY = vecYStart - mouseY;
point[pointCount] = new linePoint(mouseX, mouseY, vecX, vecY, random(255), random(255), random(255)); // locationx, locationy, speedx, speedy, R, G, B
pointCount++;
aimDraw = false;
}
This works fine, but the only problem is the velocity. I want to make it so if the user draws a long line, the point doesn't go shooting off at a crazy speed.
I tried dividing the vectors by 10, but this caused the points to fire off slightly to the left/right. I'm guessing I'd have to use some king of trigonometry here?
Here is the full code, if it's hard to understand what's going on above: