Jump to content
  • Advertisement
Sign in to follow this  
baraka

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

This topic is 4934 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!