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? This is my code uptil now that just creates a stationary pendulum:
void normalize(GLfloat *p)
void triangle(GLfloat *a,GLfloat *b,GLfloat *c)
void divide_triangle(GLfloat *a,GLfloat *b,GLfloat *c,int n)
void tetrahedron(int n)
void myReshape(int w,int h)
void main(int argc,char** argv)
Originally Posted by andre_arjun
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 suggest reading a tutorial related to the subject.