# 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.

## 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
frob
16
3. 3
4. 4
5. 5

• 20
• 13
• 14
• 76
• 22
• ### Forum Statistics

• Total Topics
632139
• Total Posts
3004369

×