Simple Question, I hope

Started by
4 comments, last by RyuuKurai 22 years, 4 months ago
I started learning OGL a while ago, then gave up, and now am starting again. Well, I decided to make a simple little screensaver using the VB conversion of NeHe''s basecode. The problem is, it''s so simple that it runs way too fast. I was just wondering if anyone knew how I could implement a frame rate limiter. Any help would be appreciated. And also, I would like to express my condolences to Jeff and his family. Losing a family member is never easy, and he is a very strong man for being able to still keep the site updated. My most heartfelt condolences to him.
Advertisement
You don''t need to limit your frame rate.
What you need to do is measure the time between two frames (there is a timer somewhere on the site) and use that as your timestep (i.e. instead of doing pos += velocity, you do sth like pos += timestep * velocity ).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
I thought about doing that, but the way the program runs it wouldn;t work right. The program is a double-helix that grows and shrinks, as well as rotates around the x and y axis. I add one step (or remove one, depending on whether it is currently growing or shrinking) every frame. Maybe I could just have it add a step everytime the timer reaches a certain value? Would you happen to know what/where I could find the VB syntax for the timer? (the timer control doesn''t work, unfortunately)
hmm.. ok, then try this : measure the time rendering a frame takes, and then sleep() for the ''remaining'' amount of time that will bring your framerate down to the desired value.

Or have your update function just return without doing anything if the right amount of time hasn''t elapsed yet.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
When you do something like this:

pos += velcocity * deltaTime;

You can interpret it as move the object''s position x units per second. So in other words, velocity should equal the distance you want the object to move per second. If you think about the math for a second or two, you''ll realize this works.
Thanks Fruny! I can''t believe I didn''t think of that. He he.

And Floppy, I know how it works. But it''s not just moving, the object itself is increasing in steps, so it can''t increase by a fractional value.

This topic is closed to new replies.

Advertisement