c program using opengl for oscillating pendulum

need a program for an oscillating pendulum - a sphere suspended to the end of the thread that can oscillate about the fixed point at the other end of the thread. need the code. im creating the sphere by recursive subdivision of a tetrahedron. need help with attaching the string and making it oscillate. thank you.

"need the code." Homework task? How exactely is it Windows(R) specific?

How detailed does the simulation have to be? Is the thread supposed to be flexible or rigid?

For the rigid case, I remember having solved the underlying differential equation in school some time. The result can be found here

Regarding the code: If you understand the problem and your programming language (neither is hard), it is fairly easy to write the simulation code yourself (from the post I assume you already have the drawing code).

Yes, its a homework task. I've just started working on the drawing code. I don't know much about OpenGL, just a beginner. If not the code for the entire program, I'd at least like an idea on how to go about with it. Like i said, i was able to create a sphere by recursive subdivision of a tetrahedron and the thread I created using GL_LINES from the centre of the sphere to a point outside. I need to get it to rotate about its axis now.

You could aproach the rotation picewise: Write down a translation matrix that moves the tip of the line to the origin (and the rest of the pendulum accordingly), a rotation matrix that rotates the pendulum around one of the major axes, a translation matrix that moves it back to it is supposed to be at. Multiply those matrices and you end up with a single matrix that depends on the angle of rotation.

Somewhere, you need a variable to store time passed since the beginning of the program. At the end of every frame, update that variable. At the beginning of the frame, this variable can be used to determine the angle from the formula on the Wikipedia page (or the solution of your differential equation). Once you have the angle, you can determine the value of the matrix and send it to the shader.

Well, I understand the multiplication of the 3 matrices to achieve the rotation but I dont understand how to construct a matrix for translation/rotation. Could you please help me with it?

Homogeneous coordinates
You don't use 3x3 matrices and 3 component vectors, you use 4x4 matrices 4 component vectors. If the last component "happens to be" 1.0, it will result in the last row of the matrix being added to the vector.

I tried lot of alternatives.
A for loop in the idlefunc oscillate() to rotate till +90 and then back to -90:
void oscillate()
{
int i;
for(i=0;i<=90;i+=30)
theta+=30;
for(i=0;i<180;i+=30)
theta-=30;
glutPostRedisplay();
}

I tried to use a mouse callback function through which I incremented theta on a right click and decremented it on a left click. I used a global variable as a flag:
float global;
void oscillate()
{
if(global==0.0)
{
theta-=theta;
glutPostRedisplay();
}
else if(global==1.0)
{
theta+=theta;
glutPostRedisplay();
}
}

I don't know what you thought of when writing those functions, but none of them have any relationship to movements of a pendulum. What was that strange for loop supposed to do that only adds constant values without anything being drawn at all? If you subtract theta from itself, the result is 0!!

If you go to that wikipedia article I posted earlier, you would know that the movement of a pendulum is a cosine of some constant multiplied with the current time.

Knowledge of oscillation and a little bit of common sense should actually lead you to something like this:

theta = theta_0 * cos(w*t)

The article mentions how the angular frequency is caclulted. Simply use a global or static variable to accumulate time every frame and calculate theta from that.

Im sorry, thats theta+=10.0 and theta-=10.0. I just need to show that the pendulum (or the object that I've created) rotates to a particular angle, say 0 to +90 degrees and back to -90 degrees in a single plane. I just want to show that simple movement visually. I'm still a beginner, i just started studying opengl a month ago. This is a very very basic project. I didn't mean the exact movement of a pendulum scientifically, its just a simple project to show 2D movements, it doesnt need to be accurate physics-wise. As for all the alternatives I tried, they were just ideas I was trying to make work, obviously they were bad ones but I was just trying things out to get a solution.