My animation shows an unsmooth motion

82 views
Skip to first unread message

Jose Luis Da

unread,
Dec 10, 2014, 9:58:14 AM12/10/14
to pyglet...@googlegroups.com
Hi all, 

I have been working with pyglet in order to create a series of OpenGL figures and animate them given some parameters.
I have obtained what I want, but the movements of these figures is not smooth all the time, the movement is sometimes glitchy.

What are the most common sources of this kind of errors? Could you tell me if there is something I am doing wrong in the code?

You can find the code here: https://github.com/thisisjl/NuEyePlaid


Thank you,
jl

Leif Theden

unread,
Dec 23, 2014, 4:24:52 PM12/23/14
to pyglet...@googlegroups.com
The unsmooth movement is due to how you are using the clock.  By default the clock will limit the framerate and it isn't accurate.  You need to reorganize your app so that the movement math isn't limited by the framerate.

Da, Jose Luis

unread,
Feb 3, 2015, 9:45:24 AM2/3/15
to pyglet...@googlegroups.com
Hi Leif, 

Thank you for your answer and sorry for my late reply.

Could you explain me what do you mean with the "movement math"? And how it is limited by the framerate in my code?

Thank you

--
You received this message because you are subscribed to a topic in the Google Groups "pyglet-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyglet-users/JgEtp7YL8SQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyglet-users...@googlegroups.com.
To post to this group, send email to pyglet...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Leif Theden

unread,
Feb 3, 2015, 2:03:41 PM2/3/15
to pyglet...@googlegroups.com
Please post a link to your source code so I can show you exactly.  You can join me in #pyglet on IRC if you want to chat about it.  My nickname is bitcraft.
Message has been deleted
Message has been deleted

Leif Theden

unread,
Feb 11, 2015, 10:34:15 AM2/11/15
to pyglet...@googlegroups.com
Thanks for sharing that.  I've looked over it, and my initial comment still stands.  In the github repo, around lines 180 - 225, you are doing all of your updating and drawing in the same block of code, all of which is at the mercy of the pyglet clock.

The pyglet clock, and all software timers are inaccurate, no matter if it is python, or C, and you need to decouple your updates from your drawing.  My recommendation is to move all the drawing functions to a callback from window.on_draw.  For your updating code, you can build a function with that and schedule it using the clock.  

After that you should use pyglet.app.run().  The pyglet app has some platform-dependent code that may help smooth out your framerate by allowing the program to sleep, too.  Please see the following code from the pyglet docs to see how to get code called from window.on_draw:


This type of event oriented programming is a common way to get smooth framerates.  Hope that helps.

Da, Jose Luis

unread,
Feb 25, 2015, 5:03:49 AM2/25/15
to pyglet...@googlegroups.com
Hi again Leif, 

Thank you for your answer. 

I avoided using "window.on_draw" because I did not understand it completely and I wanted to maintain the "window" instance as a local variable inside the "main()" function.

Can I maintain the "window" instance being a local variable in main() and use the "on_draw" function?

Thanks

--
Reply all
Reply to author
Forward
0 new messages