Sign in to follow this  

rotate camera speed

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

This topic is 4107 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this