Jump to content
  • Advertisement
Sign in to follow this  

Making a Bezier curve oscillate

This topic is 2565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How might one go about making a Bezier curve oscillate? I've been trying to do this all day today by changing the control points back and forth on each pass through the drawScene function but to no avail. Here is the relevant code I've written:

//The control points
GLfloat ctrlPoints[4][3] = {{-4.0, 0.0f, 0.0f}, {-6.0f, 4.0f, 0.0f},
{6.0f, -4.0f, 0.0f}, {4.0f, 0.0f, 0.0f}};

//The flag for oscillating the points
int flag = 0;

//Your standard resize function, make note of the call to gluOrtho2D
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
gluOrtho2D(-10.0f, 10.0f, -10.0f, 10.0f);


void drawScene()
//Clear the screen and load the identity matrix

//Lets get this party started by setting up the Bezier
glMap1f(GL_MAP1_VERTEX_3, 0.0f, 100.0f, 3, 4, &ctrlPoints[0][0]);

//Enable the evaluator

//Make the curve red
glColor3f(1.0f, 0.0f, 0.0f);

//Begin drawing the curve with a line strip connecting the points

//Loop through the u range and produce the points
for(int i = 0;i <= 100; i++)
glEvalCoord1f((GLfloat) i);

//End the drawing

//And disable the evaluator

//Now swap buffers

//If the flag is 0 and the second control y-point is greater than the y-point
//at which it bottoms out then keep decrementing the second y-point and keep
//incrementing the third y-point
if(flag == 0 && ctrlPoints[1][1] >= -4.0f)
ctrlPoints[1][1] = ctrlPoints[1][1] - (GLfloat)0.1f;
ctrlPoints[2][1] = ctrlPoints[2][1] + (GLfloat)0.1f;
else if(flag == 0 && ctrlPoints[1][1] < -4.0f)//Otherwise flip the flag
flag = 1;

//If flag is 1 and the second y-point is less than its top y-point
//then do the opposite as when the flag was 0
if(flag == 1 && ctrlPoints[1][1] <= 4.0f)
ctrlPoints[1][1] = ctrlPoints[1][1] + (GLfloat)0.1f;
ctrlPoints[2][1] = ctrlPoints[2][1] - (GLfloat)0.1f;
else if(flag == 1 && ctrlPoints[1][1] > 4.0f)
flag = 0;

Any help would be appreciated.

Share this post

Link to post
Share on other sites
How does you curve change? Bezier curve is sensitive to the change of each control point. In another word, if you change one of control points, your whole Bezier curve would change. Try use B-spline curve. The control point of b-spline curve can affect the curve more precisely, the change of one of control points will only cause the change of part of the curve around that control point.

don't know if I get your point, just about what I think.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!