Jump to content
  • Advertisement
Sign in to follow this  
blue-ice2002

rotate camera speed

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

hello, i want to rotate my camera around Y axis 90 degrees so that i want to turn to north,east,south,west at every key press.But in a very milisecond of time it turns many times rather then one,so how can i limit that loop with key pressing down.It can stil turn,but at a constant visible speed.?d3d of course,please help me.

Share this post


Link to post
Share on other sites
Advertisement
Firstly, it sounds like you want to reduce your rotation speed [wink]

Secondly, you may want to look into Time Based Movement. It is a common approach used in games to allow your objects to move at a uniform speed, regardless of the frame rate. This is achieved using the delta time between frames.

For an example of a camera with time based movement, check out codesampler [smile]

Regards,
ViLiO

Share this post


Link to post
Share on other sites
You'll likley want to store the orientation in a static/global variable and modify it per frame in a time-independent matter:

void DoMovement() {
static float Orientation = 0.0f; // North
static long LastTickCount = GetTickCount();
const float TurnSpeed = math_pi; // Tweak this if necessary

float ElapsedSeconds = (float) (GetTickCount() - LastTickCount) / 1000.0f;
LastTickCount = GetTickCount();

if (Keys[DIK_LEFT]) {
// Rotate anticlockwise
Orientation += ElapsedSeconds * TurnSpeed;
Orientation = fmodf(Orientation, 2 * math_pi);
} else if (Keys[DIK_RIGHT]) {
// Rotate Clockwise
Orientation -= ElapsedSeconds * TurnSpeed;
Orientation = fmodf(Orientation, 2 * math_pi);
}

Camera.SetOrientation(ORIENT_NORTH);
Camera.Rotate(AXIS_Y, Orientation); // Rotates anticlockwise
}



There's a bit of pseudocode in there, but I'm sure you can guess what the undocumenteds are. The important thing to remember is that you need to reset the camera's orientation before rotating by 'Orientation', else the camera will go wild.

Regards
Admiral

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!