Question about Advanced Graphics Programming Using OpenGL

1 Answer

I need open gl source code to make a point move along the circumference of the circle.

Posted by on

1 Answer

  • Level 1:

    An expert who has achieved level 1.

  • Contributor
  • 3 Answers

 I'm studying Physics, not CS, but I've had a few brushes with OpenGL.
 I'll use a Basic-like pseudocode syntax since I don't know what language you're using, and basic is very easy to read:

'Constants - Radius is radius of the circle
Const PI = 3.14159, Radius = 10

'Current angle, and angular velocity (dTheta / dt)
Dim Shared Theta as Single, Omega as Single

'Frame is called when you want to draw a new frame
Sub Frame(dt as Single)
  'dt is number of seconds passed since last frame (typically less than one, since you want several frames per second)

 'Initialize the frame (clear buffers, set up projection, etc)

 'Increase angle
 Theta = Theta + (Omega * dt)

 'Calculate co-ordinates of point
 X = Radius * Cos(Theta)
 Y = Radius * Sin(Theta)


  'Set the colour of the point
  glColor(<r>, <g>, <b>, <a>)

  'Draw the point
  glVertex2f(X, Y)


 'Display the frame

End Sub

Posted on Sep 05, 2009

  • Battlesnake Sep 05, 2009

    You would probably want to set up an orthographic projection for this, in InitFrame. I think the function for that is glOrtho - remember to select the right matrix before setting it up though!


1 Suggested Answer

  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%


Complete. Click "Add" to insert your video. Add



Related Questions:

1 Answer

How do I design a 6 foot diameter circle for my garden?

drive a peg in the ground where you want the center of the circle to be
get a piece of string and make a loop at one enf big enough to fall over the peg
measure out 3 ft from that loop and tie a stake at that point
now pull the string until it is tight and where the peg hits the ground make a mark
move about a foot an make another mark keeping the string tight all the whole
repeat the process until you have done a complete circle
the marks will be the circumference of a 6 foot diameter circle

Oct 12, 2014 | Esschert Design USA Esschert Design...

1 Answer

What is the diameter of a circle with a 120 ft. circumference?

Check out this page from Open High School. It explains the process:
LESSON Circumference of Circles READ Find the Diameter or Radius of...

Aug 14, 2014 | Home Fencing

2 Answers

15" circle what is outside measurement

If you would like to know the circumference of a 15" diameter circle this is the formula:
circumference = radius x 2 x pi
circumference = diameter x pi

in our case:
circumference = 15" x 3,14
circumference = 47 ,1" (that's 119,634 cm)

May 06, 2014 | Cars & Trucks

1 Answer

Help finding the circumferance of a circle

The circumference of a circle is given by the expression
Circumference= 2* PI* Radius of circle
The area is given by
Area of a disk with radius R = Pi* R*R or PI*R^2
Area= PI*R^2

Mar 11, 2014 | SoftMath Algebrator - Algebra Homework...

1 Answer

Trying to determine if a tangent is present when a triangle overlaps a circle

In which language? This is really more a mathematical problem than a programming/compilation one. Try walking the circumference of the circle, testing for a point along each of the triangle's segments. If only one such point can be found, or a series of consecutive points (since software "circles" are never true circles, they're made up of short straight segments), then you have a tangent.

You can save a lot of time and math by making coarse estimates first - for example, don't bother testing for tangentiality for any circumferential segment that's fully above, to the left or right of, or below, all three points of the triangle - you CANNOT have a tangent in those areas.

An alternate approach is... walk the triangle instead of walking the circle. Test for a single circle crossing point. Again, you can save time by checking each segment first, and walking only segments that actually cross the circle's circumference. If no part of the circle can be found mathematically between any pair of vertices, then discard that segment outright.

Mar 10, 2014 | Computers & Internet

1 Answer

What is circumference of 4 foot radius circle

The circumference of any circle is pi (lowercase Greek letter pi) multiplied by the diameter. For a four-foot diameter circle the circumference is about 12 feet 7 inches.

Feb 24, 2014 | Mathsoft Computers & Internet

1 Answer

Circle equation

If you know the center, measure the distance between the center and one point on the circumference. Measure with the opening of a compass and report on a ruler, or use a ruler.
Take the measure of the radius and multiply by 2. Any other indirect way of getting the radius does not constitute a measure but a calculation.
The diameter of a circle enters in two formulas.
Length of Circumference: C=Pi*D (D diameter) ====>D=C/Pi
Area of the disk A=Pi *D^2/4 =====>D=SQRT(4*A/Pi), SQRT is the square root operation.

Dec 31, 2013 | Office Equipment & Supplies

2 Answers

What is the radius of a 30'' pipe

30" diameter? Radius is 15" (half of diameter).

30" circumference (distance around) is a little more complicated...

The number pi.gif is the ratio of the circumference of a circle to the diameter. The value of pi.gif is approximately 3.14159265358979323846...The diameter of a circle is twice the radius. Given the diameter or radius of a circle, we can find the circumference. We can also find the diameter (and radius) of a circle given the circumference. The formulas for diameter and circumference of a circle are listed below. We round pi.gif to 3.14 in order to simplify our calculations. diam_formula.gif circum_formula.gif

Nov 17, 2009 | Gateway FPD1975W 19" LCD Monitor

2 Answers

Example of program in c++ and there code

Hello my friend, I am Jonas I work as a programmer in some various programming languages. Here try this code:
This program is design to output the Diameter, circumference, and area given a radius of a circle. #include <iostream.h> int main() { int radius, diameter, circumference, area, pi; cout << " Enter the radius of a circle\n"; cin >> radius; pi = 3.14159; diameter = 2 * radius; circumference = 2 * pi * radius; area = pi * (radius)^2; cout << "Diameter formula executing.....(2 x r)\n"; cout << "Diameter is " << diameter << endl; cout << "circumference formula executing.....(2 x pi x r)\n"; cout << "circumference is " << circumference << endl; cout << "area formula executing......(pi x [r x r])\n"; cout << "area is " << area << endl; return 0; }
Also if you need tutorial you can visit this site Learning C++ .Hope this solution will able to help your problem solved. If you need more assistance just reply to this post or send me a mail at geo_jonas@yahoo.comThank you and Godbless.

Jul 09, 2009 | Computers & Internet

1 Answer

How you use a stanley center square #46-101

No need for a manual. Just hold it so that the two edges of the "vee" line up with the circumference of the circle and scribe a line along the steel rule. Then turn approx. 90 degrees and scribe another line along the rule that intersects the first. The point of intersection is exactly the center of the circle. This tools only function is to find the center of circles.

Mar 05, 2009 | Measuring Tools & Sensors

Not finding what you are looking for?

Open Questions:

0 Answers

my code in opengl does not work can any one help me #include <string.h> #include <GL/glut.h> #include "math.h" float rotate =0.0; float start = 0.0; float z_dep = 0.0; int poi_size = 0; int poi_arr[100][2]; float rad_arr[50]; int m_x = 0; int m_y = 0; int rubber_band_on = 0; int down_flag = 0; #define MENU1 10 #define MENU2 11 #define MENU3 12 #define MENU4 13 #define MENU5 14 GLfloat r,g,b; GLint t=0 ; void sel(int item) { switch(item) { case MENU1: {r=1 , g=0 , b=0;} break; case MENU2: {r=0 , g=0 , b=1;} break; case MENU3: {r=0 , g=1 , b=0;} break; case MENU4: {t=1;} break; case MENU5: {t=2;} break; } glutPostRedisplay(); } void menu(void) { int MainMenu, SubMenu1,SubMenu2; SubMenu1=glutCreateMenu(sel); glutAddMenuEntry("red", MENU1); glutAddMenuEntry("bule", MENU2); glutAddMenuEntry("green", MENU3); SubMenu2=glutCreateMenu(sel); glutAddMenuEntry("line", MENU4); glutAddMenuEntry("circle", MENU5); MainMenu=glutCreateMenu(sel); glutAddSubMenu("Color", SubMenu1); glutAddSubMenu("Shap", SubMenu2); glutAttachMenu(GLUT_RIGHT_BUTTON); }void drawCircle(float radius, float x1, float y1) { float angle = 0; float x2,y2,cx,cy,fx,fy; int cache = 0; glBegin(GL_LINES); for (angle = 0; angle < 360; angle+=1.0) { float rad_angle = angle * 3.14 / 180; x2 = x1+radius * sin((double)rad_angle); y2 = y1+radius * cos((double)rad_angle); if (cache) { glVertex2f(cx,cy); glVertex2f(x2,y2); } else { fx = x2; fy = y2; } cache = 1; cx = x2; cy = y2; } glVertex2f(x2,y2); glVertex2f(fx,fy); glEnd(); } void tick(void) { glutPostRedisplay(); } void display1(void) { glClear(GL_COLOR_BUFFER_BIT); // Draw the lines created by user glBegin(GL_LINES); for(int i=0; i<poi_size; i++) { glVertex2f(poi_arr[i][0],poi_arr[i][1]); } if (rubber_band_on && (poi_size%2==1)) { glVertex2f(m_x,m_y); } glEnd(); glutSwapBuffers(); } void handleKeypress(unsigned char key, int x, int y) { switch (key) { case 27: //Escape key exit(0); } } void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, w, h, 0); glMatrixMode(GL_MODELVIEW); } void mouse_move1(int x, int y) { m_x = x; m_y = y; display1(); } void mouse1(int button, int state, int x, int y) { m_x = x; m_y = y; switch (button) { case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN) { // glutIdleFunc(spinDisplay); } if (state == GLUT_UP) { if (poi_size>0) { poi_size-=2; } rubber_band_on = 0; glutIdleFunc(NULL); } break; case GLUT_LEFT_BUTTON: rubber_band_on = 1; if (state == GLUT_DOWN) { down_flag = 1; } if (state == GLUT_UP) { if(down_flag) { poi_arr[poi_size][0]=x; poi_arr[poi_size][1]=y; poi_size++; down_flag = 0; } glutIdleFunc(NULL); } break; default: break; } display1(); } float calculate_radius(int x1,int y1) { int x_diff = m_x - x1; int y_diff = m_y - y1; if(x_diff<0) { x_diff *= -1; } if(y_diff<0) { y_diff *= -1; } float mag = x_diff*x_diff + y_diff*y_diff; float rad = sqrt(mag); return rad; } void display2(void) { glClear(GL_COLOR_BUFFER_BIT); for(int i=0; i<poi_size; i+=2) { int rad_index = (int)(i/2); float rad = rad_arr[rad_index]; if (rad>1) { drawCircle(rad,poi_arr[i][0],poi_arr[i][1]); } } glutSwapBuffers(); } void mouse_move2(int x, int y) { m_x = x; m_y = y; if (rubber_band_on) { float rd = calculate_radius(poi_arr[poi_size-1][0],poi_arr[poi_size-1][1]); rad_arr[poi_size/2] = rd; } display2(); } void mouse2(int button, int state, int x, int y) { m_x = x; m_y = y; switch (button) { case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN) { // glutIdleFunc(spinDisplay); } if (state == GLUT_UP) { glutIdleFunc(NULL); } break; case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) { down_flag = 1; } if (state == GLUT_UP) { if(down_flag) { poi_arr[poi_size][0]=x; poi_arr[poi_size][1]=y; poi_size++; down_flag = 0; rubber_band_on = !rubber_band_on; } glutIdleFunc(NULL); } break; default: break; } if (rubber_band_on && poi_size>0) { float rd = calculate_radius(poi_arr[poi_size-1][0],poi_arr[poi_size-1][1]); rad_arr[poi_size/2] = rd; } display2(); } int main(int argc, char **argv) { glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(1000, 800); glutCreateWindow("OPENGL LINE DRAWING"); glClearColor(0.0, 0.0, 0.0, 1.0); menu(); if (t=1) { glutDisplayFunc(display1); glutReshapeFunc(reshape); glutIdleFunc(tick); glutKeyboardFunc(handleKeypress); glutMouseFunc(mouse1); glutMotionFunc(mouse_move1); glutPassiveMotionFunc(mouse_move1); glutMainLoop(); } if (t=2) { glutDisplayFunc(display2); glutReshapeFunc(reshape); glutIdleFunc(tick); glutKeyboardFunc(handleKeypress); glutMouseFunc(mouse2); glutMotionFunc(mouse_move2); glutPassiveMotionFunc(mouse_move2); glutMainLoop(); } return 0; /* ANSI C requires main to return int. */ }

Jun 22, 2013 | Advanced Graphics Programming Using OpenGL...

See all Advanced Graphics Programming Using OpenGL Questions

Advanced Graphics Programming Using OpenGL  Logo

430 people viewed this question

Ask a Question

Usually answered in minutes!

Top Advanced Graphics Computers & Internet Experts

Doctor PC
Doctor PC

Level 3 Expert

7733 Answers


Level 3 Expert

102366 Answers

David Payne
David Payne

Level 3 Expert

14161 Answers

Are you an Advanced Graphics Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides