Skip to main content
gamedev.net
🔒 Locked

Problem with rotation

Started by boolean010 Mar 13, 2007 at 9:46 PM 1 replies 400+ views
Original Post
boolean010
boolean010
I'm trying to get an object to rotate by itself without having to press a key on the keyboard. Here is the code if (m_bKey['J']) m_pObjects[0].vR.z -= 1.0f * m_fTimeElapsed; if (m_bKey['L']) m_pObjects[0].vR.z += 1.0f * m_fTimeElapsed; if (m_bKey['I']) m_pObjects[0].vR.y -= 1.0f * m_fTimeElapsed; if (m_bKey['K']) m_pObjects[0].vR.y += 1.0f * m_fTimeElapsed; if (m_bKey['V']) m_pObjects[0].vR.x -= 1.0f * m_fTimeElapsed; if (m_bKey['B']) m_pObjects[0].vR.x += 1.0f * m_fTimeElapsed; I tried commenting out if (m_bKey['J']) and using m_pObjects[0].vR.z -= 1.0f * m_fTimeElapsed; The object is rotated once and that is it. I figured if I'm able to use the keyboard to rotate the object I should be able to rotate it by itself, but that's not the case.
** boolean010 **
boolean010
boolean010
I think I figured it out. It appears that m_fTimeElapsed is constant for each frame. So it will rotate the object once and that's it. I tried two other things and got different results.

The first thing I tried was this.
m_pObjects[0].vR.z -= 1.0f * m_fTime;

With the code above it rotates really fast. It looks like the propeller of an airplane, I don't like the way this looks.

Then I tried
m_pObjects[0].vR.z = 1.0f * m_fTime;

It rotates it a little bit at a time.

I think the thing with the keyboard works because the keyboard kinda changes the frame rate.
** boolean010 **
perkbrian
perkbrian
im guessing you're using the framework timer thing? elapsed time is time between frames for that timer...

you may want to keep track of the total time somewhere else... or every frame add to a variable the m_fTimeElapsed and using that instead...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.