View Full Version : moving the ball

01-09-2011, 07:24 PM
In lesson 26 (nehe) , i want to move the ball to cross 4 points in the floor, but i dont know. please help me. thank you very much!

01-10-2011, 08:02 AM
If you posted a link to the tutorial you are having trouble with, it would be easier to help you.

01-11-2011, 12:13 AM
here is code :
i want to move the ball to another points ( as clip), i need sb help me.
ex: When i press key 'z', the ball moving.
from (1) position -> (2) ->(3) -> (4) (repeat)
My code :

void Drawball()
void processkeyboard(){
int k;
a = a[k];
b = b[k];
c = c[k];
But the ball only move to (2) position. and it's not like moving the ball. Please help me

Rosario Leonardi
01-11-2011, 05:14 PM
If you want to create an animation you have to draw the sphere in different position in each frame.
If you want to move an object from A to B in 10 seconds at frame 0 the object will be in the point A, in the frame 1 will be in the point A + deltaT/10 * (B-A)
where deltaT is the time between a frame and another.
So you will have a code like this

time = 0;
A = StartPosition
B = EndPosition

time += deltaT;
if(time < endAnimation)
actualPosition = A + (time/endAnimation)*(B-A)
actualPosition = B;

To have a smooth animation you have to call the draw function at least 30 times for seconds.

01-12-2011, 12:10 AM
Thank you. But i understand a little your code.
What's endAnimation ? "A = StartPosition" is : Gldouble A[3] = {a1,a2,a3 ) , isn't it?
And I want the ball from A (start position) run to B, then run to C, then run to C..., not only from A to B.
I'm a newbie, so i need heper of...

Rosario Leonardi
01-12-2011, 03:37 PM
If you have point A, B, C, D;
at init time set
start = A
end = B
then then the animation is finished reset the timer and set
start = B
end = C
and so on.

I usually write meta code when the implementation is not important. When I write
start = A
is only a conceptual starting point A
I don't care if this is a 3d point or 2d, or if it's a GLfloat or GLdouble or is you have a class representing points.
"If you have point A, B, C, D;"
I don't care is you have four variable or a vector, this is up to you.