We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › wierd behaivor with path following and rotation
Page Index Toggle Pages: 1
wierd behaivor with path following and rotation (Read 347 times)
wierd behaivor with path following and rotation
Jul 15th, 2009, 6:09am
 

hi, im tryint to make a program where some graphical objects can follow a bezier line and rotate according the curves tangent , ive made this example  it works but im getting two  wierd behaivors. The first one is that my sphere appears in  front of the curve line and then it sometimes goes to the back.

my second wierd behaivor is that in the begining of the curve it seems to works well but when the ellipse is at the end of the line it stills rotating not following the curve.

Why are these problems comming? Do im doing anything bad?
and my last question, why does it begins to move slow and the it become faster?

there is my code

thanks in advance


Code:



import processing.opengl.*;



float aumenta = 0;

float x1;
float y1;
float cx1;
float cy1;
float cx2;
float cy2;
float x2;
float y2;



void setup() {
size(600, 300, OPENGL);

x1 = 0;
y1 = random(200);
cx1 = random(200);
cy1 = random(200);
cx2 = random(200);
cy2 = random(200);
x2 = random(200);
y2 = random(200);

}



void draw(){
background(250, 250 , 0);
noFill();


bezier(0, y1, cx1, cy1, cx2, cy2, 600, y2);
fill(255);

aumenta = aumenta + 0.003;

float x = bezierPoint(0, cx1, cx2, 600, aumenta);
float y = bezierPoint(y1, cy1, cy2, y2, aumenta);

float tx = bezierTangent(0, cx1, cx2, 600, aumenta);
float ty = bezierTangent(y1, cy1, cy2, y2, aumenta);

float a = atan2(ty, tx);
//a -= HALF_PI;

rotateX(a);
ellipse(x, y, 10, 25);
}





Page Index Toggle Pages: 1