Can't get smooth movement i Z axis with glTranslatef

Started by
4 comments, last by karwosts 14 years, 1 month ago
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.
Well I just want to join so I can get som help.
Advertisement
Have you tried using finer granuality, as in doing something like 0.1 increments or even 0.001, usually when it comes down to doing something with camera movement smaller=smoother.
Thanks for the fast reply.

I have tried to use 0.1f values. but that didn't seem to help.
The thing is that I don't want the movement to be way to slow either.

Any other suggestion?
Well I just want to join so I can get som help.
Can you explain more clearly what you mean by "its choppy"? I don't understand what you are doing really. When you zoom out are you just moving out by 0.4 everytime someone pushes a button? Or does it move 0.4 per frame and it doesn't appear to move smoothly over multiple frames?

Typically when moving things you want to multiply the movement speed by the amount of time since your last update. If you just use a fixed translate then it will appear to change speed based on your framerate, which is not natural.

If your first 5 frames at 10ms each and the next 5 frames at 5ms each, it will appear to move twice as fast for the second set of frames, which is unnatural.

Multiply the translation speed by the time per frame and it will not appear to change translation speed. I'm not sure if this is your issue though.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Everytime I touch the screen on my mobile phone, I make sure to catch that event and do this fOldZ -= 0.4f;
When I release my finger from the touch screen I do this fOldZ += 0.4f;

The actual adding and subtracting I'm doing in the "draw" method. Where I call the Opengl functions.

What I actually do is to set a flag in the onTouchEvent method if the screen is being touched or not.

When screen touched:
bPressed = true;

then in the draw method I do:

if(bPressed == true){
fOldZ -= 0.4f;
}
gl.glTranslatef(0.0f, 0.0f, fOldZ);


Thats basically what I'm doing.

Is this not the way to go?

Well I just want to join so I can get som help.
You probably want to smooth out that translation over several frames. Right now you're doing your whole movement in one frame, so it appears instantaneous. Try to break up the animation over several frames so you get an actual effect of movement instead of an instant change from one position to another.


Instead of this:
if(bPressed == true){  fOldZ -= 0.4f;}gl.glTranslatef(0.0f, 0.0f, fOldZ);


Consider something like this:
if(bPressed == true){   if(zoom < 0.4){     zoom += 0.01   }   fOldZ -= zoom  }gl.glTranslatef(0.0f, 0.0f, fOldZ);


While zoom is persistent from one frame to the next. I'm assuming that fOldZ is reinitialized every frame so that you're not accumulating zoom while the button is held in a pressed position.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

This topic is closed to new replies.

Advertisement