Can't get smooth movement i Z axis with glTranslatef

Hi!

I have been testing different OpenGL stuff on my Android Mobile phone, supporting OpenGL ES 1.1.

I have created a 3D plane and I’m trying to zoom out the object using glTranslatef.

This is the call I’m doing:

glTranslatef(0.0f, 0.0f, fOldZ);

fOldZ will be added or subtracted with 0.4f to make it zoom in or out.

The problem I’m seeing is that the object does not move smoothly. It has more of a choppy movement.

Could someone maybe explain what may be wrong?
Can I do something to make it zoom in/out more smoothly?

First I thought it could have been something to do with fixed point values but the function does take float values so it can’t be that.

Please help.

Maybe you should measure the amount of time between frames and move based on that.

Thanks!

Do you have any example of how this is done?

I’ll leave that as an exercise for you ::slight_smile:

Let’s say I have the time it takes for 1 frame to render.

Do you mean that I should only make sure to move the plane when it renders 1 frame.?

I assume you use Android GL and not JOGL 2, don’t you?

That is correct. I’m using Android GL and not JOGL.

I wrote in this forum because I couldn’t find any good form related to just GL.

Think about it this way:
You draw one frame, which takes 5ms and it moves the plane by .4
Then you draw another frame which takes 7ms but still only moves the plane by .4
In the extreme a frame could take 30ms to draw

Essentially, the amount of time between frames is not guaranteed to be constant so moving the plane by a constant amount results in uneven perceived velocity. To solve the problem, you can use the physics equation distance = velocity * time.

Each frame, if ms is the milliseconds since last frame and vel is your chosen velocity, then you’d do:


fOldZ = fOldZ + ms * vel;
glTranslatef(0f, 0f, fOldZ);

Hachoso,

Several OpenGL forums: http://www.opengl.org/discussion_boards/ubbthreads.php.

Thank you,
Robert