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

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

## 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 on other sites
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;}

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633296
• Total Posts
3011245
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!