Sign in to follow this  

Can't get smooth movement i Z axis with glTranslatef

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this