Advertisement

ship rotation and timers

Started by February 02, 2001 01:56 AM
0 comments, last by xSuiCidEx 23 years, 11 months ago
heres the current code i use to increment/deincrement the shipframe of my ship, each ship has 36 frames for 10 degree increments of rotation...im using QueryPerformanceCounter() to keep everything in time, and i have it setup and working for moving the ship forwards and backwards in the same amount of time(so you can''t move faster on a faster computer), i was wondering if anyone knows a good way of doing for this situation, ive fiddled around a little but with no results =\ btw..i have a variable called "deltatime" that has the time it took to render and compute everything in milliseconds and thats what i used to get the timed movement backwards and forwards to work // process ship controls if(m_DI.GetKeyboardKeyState(KEY_LEFTARROW) == KEYSTATE_REPEAT){ m_ShipFrame -= 1; if(m_ShipFrame < 0) m_ShipFrame = 35; } if(m_DI.GetKeyboardKeyState(KEY_RIGHTARROW) == KEYSTATE_REPEAT){ m_ShipFrame += 1; if(m_ShipFrame > 35) m_ShipFrame = 0; }
---===xxxx===---
----THE END----
---===xxxx===---
Hi xSuiCidEx,

I'm working on something similar and solved this problem by storing the ships direction as a double, along with a 'turn rate' which is the amount the direction changes per millisecond when the player turns. If a left/right turn keypress is detected, subtract/add turn_rate*delta_time to the current direction, ensuring that you keep the value within your 0-35 range.

I've attempted to adapt my code to your example. I hope it makes sense:

    // Ship direction and turn rate defined elsewheredouble m_fShipDirection;double m_fShipTurnRate; (this will be something like 0.05)// ...// ...// process ship controlsif(m_DI.GetKeyboardKeyState(KEY_LEFTARROW) == KEYSTATE_REPEAT){  m_fShipDirection -= m_fShipTurnRate * deltatime;  if (m_fShipDirection < 0)  {    m_fShipDirection += 36;  }}if(m_DI.GetKeyboardKeyState(KEY_RIGHTARROW) == KEYSTATE_REPEAT){  m_fShipDirection += m_fShipTurnRate * deltatime;  if (m_fShipDirection >= 36)  {    m_fShipDirection -= 36;  }}// Cast the double to an int to get your 0-35 frame numberm_ShipFrame = (int)m_fShipDirection;    


I've only been programming C++/DirectX stuff for the last 5 months, so this may not be the best way of doing it. Other people may have better or quicker methods, maybe using fixed point instead of doubles and somehow avoiding the double->int cast, but this method works for me.

Hope it helps.

Moot



Edited by - Moot on February 2, 2001 10:55:56 AM

This topic is closed to new replies.

Advertisement