We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi
I am tying to make a pivot like game. I have tried with everything bezierVertex(), curveVertex() ,curvepoint() or beizerPoint() but none of them helping me.
Problems:
For small curve I could make the ellipse move using curvePoint or bezierPoint but I am not able to think about the logic to make it work for the infinite 2D curve.
ArrayList<Float> xmotion = new ArrayList();
ArrayList<Float> ymotion = new ArrayList();
void setup() {
size(400, 300);
curvegenerate();
}
float t=0;
void draw() {
background(-1);
float x = bezierPoint(xmotion.get(0), xmotion.get(1), xmotion.get(2), xmotion.get(3), t);
float y = bezierPoint(ymotion.get(0), ymotion.get(1), ymotion.get(2), ymotion.get(3), t);
fill(0);
ellipse(width/2, height/2, 10, 10);
pushMatrix();
translate(width/2-x, height/2-y);
noFill();
bezier(xmotion.get(0), ymotion.get(0), xmotion.get(1), ymotion.get(1), xmotion.get(2), ymotion.get(2), xmotion.get(3), ymotion.get(3));
popMatrix();
t+=1/100.0;
}
void curvegenerate() {
for (int i=0; i<4; i++) {
float x = noise(i)*random(-width/2, width/2);
float y = noise(i)*random(-800, 800);
if (i==0)xmotion.add(-width/2.0*2);
else if (i==3)xmotion.add(width/2.0*2);
else xmotion.add(noise(i)*random(-width/2, width/2));
ymotion.add(y);
}
}
void mousePressed() {
xmotion.clear();
ymotion.clear();
curvegenerate();
t=0;
}
Answers
Good idea to give this link, because you got the name of the game wrong...
Note that you don't necessarily need an infinite curve, as curves can be created on the fly, and just forgotten when going out of the screen. You just need the capability to connect curves together. With Bézier curves, that's relatively easy, if you align the control points.
Sorry about the name :( my bad ! it is Pivvot :P
PhiLho ! what would you suggest to use a bezier curve or spline for this? Also would you suggest me how deal with the connecting curve ?
Hi,
I have got this far. Still it doesn't look like pivvot but now it is generating infinte curve. May be someone in the forum can fix it for you :)
If I would have any luck I'll let you know
for bezier curves to be c2 continuous the control points at the join have to be co-linear AND the same length.
in the following the two control points joining to the middle point are equal and opposite so the curve is always smooth at the join.
Thanks everyone ! I would try to use bezier in blyk's code. @Koogs thanks for providing the code for connected bezier :)
Also when I was playing with the blyk's code it seems something I am missing something. What I was trying to do is to create another curve before t --> 1 so that it wouldn't have to wait for another curve to be generate. The problem occurs when curve generate before t-->1 it jumps to another curve (generated curve) and even sometimes return "array out of the box error" :(