making a point rebound to and fro along the same path..HELP
elo again guys. Well, my problem is that nite I got stuck with - which am sure is - a simple problem. Initially I wanted to simulate the Brownian motion in a cube. But then, I decide to try a simpler one using OpenGL. I want to make a point rebound to and fro along the same path.
So, I guess I have to declare the function to do it as being a IdleFunc();
I declared a variable,
GLfloat mol_x = -1.0; //this is the x-position of the point.
then in the function, I wrote a contional statement as follows:
if(mol_x >= -1.0 && mol_x < 1.0)
mol_x += 1.0;
else if(......)
But I'm stuck with the else if part. I'm wonderingand I'm having doubts if this should be done in the IdelFunc or whether a recursive function should be used. Please help. Thanx.
you need a velocity variable, or direction
mol_dx = 0.001f;mol_x = -1.0f;if (mol_x < -1.0f && mol_dx < 0.0f) { mol_x = -1.0f; mol_dx = -mol_dx;}else if (mol_x > 1.0f && mol_dx > 0.0f) { mol_x = 1.0f; mol_dx = -mol_dx;}else { mol_x += mol_dx;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement