Hi everyone,
I am new to OpenGL and I am just working on my first little project, where I want to create a nice wave like motion of a series of ellipses (stack on one another), to try to simulate a sea weed. And here’s the code for that:
void display()
{
glPushMatrix();
glRotatef(0,0,0,1);
drawEllipse();
glTranslatef(0,0.6,0);
glRotatef(angle1,0,0,1);
drawEllipse();
glTranslatef(0,0.6,0);
glRotatef(angle1,0,0,1);
drawEllipse();
glTranslatef(0,0.6,0);
glRotatef(angle2,0,0,1);
drawEllipse();
glTranslatef(0,0.6,0);
glRotatef(angle2,0,0,1);
drawEllipse();
glTranslatef(0,0.6,0);
glRotatef(angle1,0,0,1);
drawEllipse();
glTranslatef(0,0.6,0);
glRotatef(angle3,0,0,1);
drawEllipse();
glTranslatef(0,0.6,0);
glRotatef(angle3,0,0,1);
drawEllipse();
glTranslatef(0,0.6,0);
glRotatef(0,0,0,1);
drawEllipse();
glPopMatrix();
}
void idleCB(void)
{
if( g_animate == 1 )
{
if( g_recording == 0 )
g_time = g_timer.GetElapsedTime() ;
else
g_time += 0.033 ; // save at 30 frames per second.
cout << "current time: " << g_time << endl;
angle = 5*sin(g_time);
angle1 = 5*sin(g_time);
angle2 = 10*sin(g_time*1.5);
angle3 = 15*sin(g_time*2);
glutPostRedisplay() ;
}
}
Here, g_time is a time step. Every time the display function gets called, the glRotatef() takes in small increments of a function of g_time which is defined inside the idleCB function as a form of a sine function.
This kind of gives me the feel I want to see but still does not compeltely replicate the sinusoidal motion. Can anyone give me better ideas?
I have been working on this for hours at a stretch and my brain has literally stopped functioning. No matter which way I try, it won’t work. Please some body with a smarter idea, HELP ME!!!
Thanks much!