Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

paulcoz

Time-bound Rotations...help needed

This topic is 6786 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

I am trying to make the rotations in my program time-bound (x degrees per second) rather than frame-bound (x degrees per frame). Can anybody see what is wrong with this because it doesn't work: DWORD keydown; DWORD elapsed; int timeprop; // proportion of time yaw; // yaw value for rotation matrix (degrees) I am polling for DirectInput every 30ms (perhaps this needs to be changed?), and checking input like this: if (z key JUST pressed down) { keydown = GetTickCount(); } if (z key down) { elapsed = GetTickCount() - keydown ; timeprop = int ( (elapsed / 5000) * 180); yaw += timeprop; } The 5000 in the timeprop assignment means I want it to take 5 seconds (5000ms) to rotate, and the 180 is the full rotation angle in degrees. Is this the right way of going about this? Paulcoz. Edited by - paulcoz on 3/16/00 6:13:59 PM

Share this post


Link to post
Share on other sites
Advertisement
Hi paulcoz,

I''ve mucked around with this sort of thing quite a bit before (though not using DirectInput, but anyway...), and I''ve found that the easiest approach is to have a rotation angle variable (this is what ''yaw'' is in your program, yes?) that is incremented/decremented by whatever step if the appropriate key is down upon an input poll.

What I mean is, if you want it to rotate 180 degrees in 5 seconds (5000ms), and input is polled every 30ms, then your ''step angle'' will be found by this method:

rotation rate per ms = 180/5000
therefore, rotation rate per input poll (step angle) = 30 * 180/5000

i.e. this is the number of degrees to add/subtract to/from (depending on which direction you want to rotate) ''yaw'' if the Z key is down upon input poll.

You then rotate your object by ''yaw'' degrees (from a fresh modelview matrix) before drawing each frame.

Is this making sense, or am I spouting complete shit?

Hope that was helpful in some small way. I''ve got to get back to work before I get sprung by the boss



-------------
squirrels are a remarkable source of protein...

Share this post


Link to post
Share on other sites
Hi Bad Monkey,

Thanks for the suggestion. I have tried doing it that way (eg. 180/5000 * 30 = 1.08) but I find that the animation as I turn the camera around is still too jerky.

My dodgy fps calculator (using GetTickCount) tells me I am jumping between 35, 75, 14, and 200 fps however when I rotate the camera it looks like the objects in the world are taking huge jumps across the screen as if they are either: (1) rotating too far in too short a space of time, or (2) repeating the same frame multiple times for each rotation step, I can't tell which.

"You then rotate your object by 'yaw' degrees (from a fresh modelview matrix) before drawing each frame."

I think that's the old way I was doing it (frame-bound).

Paulcoz.

Edited by - paulcoz on 3/16/00 9:33:06 PM

Share this post


Link to post
Share on other sites
If you want more presicion from your timer you could try with QueryPerformanceCounter() and QueryPerformaceFrequency(). Just remember that these might not work with older computers.

Share this post


Link to post
Share on other sites
I have no idea why it would appear jumpy, but one random thought that comes to mind is... you''re not (accidentally or otherwise) casting floats or doubles to ints anywhere? This kind of thing would end up rounding off some of the extra precision given you by a floating point variable.

Just a thought.

Share this post


Link to post
Share on other sites

Good day again paulcoz,

Don''t know if you''re still checking this for responses, but if you are, I have a wee suggestion.

If you poll more frequently for input, movement will appear smoother, as you are updating the angle more frequently and rotating by a smaller angle at each update. This will mean that your state will be more accurate at any given time during movement (the perfect scenario is polling it infinitely, but that''s not really practical, is it ).

Polling every 15ms will make your updates twice as smooth, every 10ms - three times as smooth, etc...

If it is smoothness you are after, I might suggest even-driven input. This is as close to infinitely polling as you could want, and it has the bonus of only being called when needed (i.e. the mouse is moved, etc). Same calculation method, but you just need to find the time since the last update:

angle = 180/5000 * timeSinceLastUpdate

I don''t know if DirectInput makes provision for event-driven input, so sorry if this is no help to you.

Take care people



-------------
squirrels are a remarkable source of protein...

Share this post


Link to post
Share on other sites
Thank you all for your help. I finally got it to work on the weekend.

Bad Monkey is right - it is to do with the polling time. I was polling every 30ms and using a yaw += 1.08 or whatever to update the yaw, so even though my frame rate was totally off the scales (I can now smoothly rotate 360 degrees in a second!) the rotation amount was only being applied every 30ms meaning there were duplicate frames for each rotation step.

I have put the yaw changing code inside the rendering loop for the moment with increments of 1.08. I will try and make it time-bound later on & also use one of those higher precision timers.

Thanks again.
Paulcoz.

Edited by - paulcoz on 3/20/00 1:07:49 AM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!