## Archive Pages Design\$type=blogging

Learn How to draw a Moving Bézier curves in OpenGL C/C++ in this opengl projects tutorial.

In our many tutorial, we have explained about how to create various objects, diagrams, things in OpenGL.  In our earlier tutorial we have explained about how to draw Bézier curves in opengl C/C++ with source code. In this post we will use the same source code and bring motion to our Bézier curves. You will see OpenGL Moving Bézier curves Program in C/C++ explained in this post.

Before going to the tutorial we are going to see the output of our program. Below gif will demo the out put and show Moving Bézier curve.

A curve is collection of set of points which are not in a straight line. They exist in 2d as well as 3d space. Bézier curves are parametric curves which can be generate with some set of points called as control points. Bézier curves are of different degree - linear curves, quadratic curve, cubic curve and high order curve. Following image will show the mathematical representation of Bézier curves -

In our example we will use simple Bézier curves, and give motion to them using two control points.

First we define the global variables which we can use in more than one set of function or methods. We have four set of control points, one each at end of curve and two in the middle. Using the middle control points we will give the curve a movement to change their position in 2d plane.
```int bzco[4][2]={{0,0},{99,201},{204,49},{320,300}},c[4],n=3;
```
You can experiments with the bzco and choose the specific points for motion.

Next is to draw bezier curve, for which we need to define the curve center points. Firs of all we will define a function that will compute the points of the curve. This functions is very important for drawing bezier curves in opengl.

```void bezierCoefficients(int n,int *c)
{
int k,i;
for(k=0;k<=n;k++)
{
c[k]=1;
for(i=n;i>=k+1;i--)
c[k]*=i;
for(i=n-k;i>=2;i--)
c[k]/=i;

}
}
```
In display function we will call the above function and use the GL_LINE_STRIP in loop to develop the curve. The array of x, y coefficients will help in containing value for control and end points. Size of points is also defined using the glPointSize and gluOrtho2D to certain x, y values which define the curve path. You can see code in source code download below.

We have finished drawing Bézier curve but this post is about Moving Bézier curves Program. Hence we need to define a function called motion(), which will give movement to the curve. Simple logic we use to determine the extent of movement is the x, y coefficient point of 2d plane. We will set the value to which curve can move and then came down from there. For this we will use the array which we have declared as global variable.
```void motion(void)
{
bzco[1][0]+=s1x;
bzco[1][1]+=s1y;
bzco[2][0]+=s2x;
bzco[2][1]+=s2y;
if(bzco[1][0]<0 bzco="">320)
{
s1x=-s1x;
}
if(bzco[1][1]<0 bzco="">300)
{
s1y=-s1y;
}
if(bzco[2][0]<0 bzco="">320)
{
s2x=-s2x;
}
if(bzco[2][1]<0 bzco="">300)
{
s2y=-s2y;
}
glutPostRedisplay();
}
```
In the above code you can see that first we add the number(distance) to the array and then negate it. So, logic is to first add the value to coefficient to go up and bring them down. You can see we have chosen 300, 320 two different control points. You all can experiment with these points as well and see the the magic yourselves. The glutPostRedisplay(); repeat drawing of objects on screen with call back to main function, hence will repeat the same.

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm Bézier curves Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero Doll DSAV Escapa Fighter Jet First Come First Serve Flag Flag Hoisting Fluids Font Demo Games Gear Motion GlutDino Glutplane Graphics Editor iOS iPhone Java Java OpenGL Graphics Programming Light Torus Linked List Ludo Board Game Mancala board games Memory blocks game Memory Game Menu Mickey Mouse Minesweeper Miniature Steam Engine moth Motion Blur MoveLight moving car Moving Ship Multiplex Networking Based Project Nuclear Power Plant Olympic opengl c++ examples OpenGL ES OpenGL Programming OpenGL Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Queuqe Random Flowing lines Ray Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Space Invaders Sphere Spot Light Swing Stack Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation Trippy Tutorial water ripple effects Whirlpool
false
ltr
item
OpenGL Projects: OpenGL Moving Bézier curves Program in C/C++
OpenGL Moving Bézier curves Program in C/C++
Learn How to draw a Moving Bézier curves in OpenGL C/C++ in this opengl projects tutorial.
https://3.bp.blogspot.com/-e7U0cmm6uUE/WHqauG3-WwI/AAAAAAAAIOU/nZG44kAx6AgNhNT2hJhVR0J0RtufisN7ACLcB/s400/moving%2Bbezier%2Bcurve%2Bopengl%2Bc%2Bc%252B%252B%2Bprogram.gif
https://3.bp.blogspot.com/-e7U0cmm6uUE/WHqauG3-WwI/AAAAAAAAIOU/nZG44kAx6AgNhNT2hJhVR0J0RtufisN7ACLcB/s72-c/moving%2Bbezier%2Bcurve%2Bopengl%2Bc%2Bc%252B%252B%2Bprogram.gif
OpenGL Projects
http://www.openglprojects.in/2017/01/opengl-moving-bezier-curves-program-in-c-and-c-plus-plus.html
http://www.openglprojects.in/
http://www.openglprojects.in/
http://www.openglprojects.in/2017/01/opengl-moving-bezier-curves-program-in-c-and-c-plus-plus.html
true
2020194800836807725
UTF-8