• Advertisement
Sign in to follow this  

making a point rebound to and fro along the same path..HELP

This topic is 4759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement