   Rotate Spaceship Strafing Left and Right.
  I have a space ship in the middle of the screen rendering in OpenGL and I want to rotate left and right a little when mouse or keyboard is making the ship strafe. Then when it has stopped strafing have it tilt back the 0. How can I do this using a mouse and keyboard? So it rotates when no keys are press and or the mouse has stopped moving?Any pseudo code or C++ example someone can give? I know how to use OpenGL functions with rotation. I'm just wondering what someone would do. I just want to be sure I'm using a good method or working hard then smart.   
Quote:I have a space ship in the middle of the screen rendering in OpenGL and I want to rotate left and right a little when mouse or keyboard is making the ship strafe. Then when it has stopped strafing have it tilt back the 0. How can I do this using a mouse and keyboard? So it rotates when no keys are press and or the mouse has stopped moving?Any pseudo code or C++ example someone can give? I know how to use OpenGL functions with rotation. I'm just wondering what someone would do. I just want to be sure I'm using a good method or working hard then smart.Can you provide a few more details? Is this a top-down game with 3-d rendering? What's the control scheme (i.e. how are the mouse and keyboard used to control the ship)? And by rotate left and right, do you mean roll by some amount in the direction of lateral movement?   ;  Its in 3D, but in a 2D kinda work dimension. The control scheme is mouse and keyboard moving the ship only left and right on the screen. And yes, roll is what I mean.All C++ Win32 and OpenGL code is being used. Just encase if your wondering what APIs I was using.   ;Quote:Its in 3D, but in a 2D kinda work dimension. The control scheme is mouse and keyboard moving the ship only left and right on the screen. And yes, roll is what I mean.All C++ Win32 and OpenGL code is being used. Just encase if your wondering what APIs I was using.Assuming I understand correctly the type of motion the ship will be undergoing, I wouldn't bother with SLERP or anything like that. Instead, I'd just store a 'roll angle' for the ship, and update it based on whether the ship is strafing left, strafing right, or not strafing. The logic might look something like this:if (strafing_left) {    roll_angle -= roll_speed * time_step;    roll_angle = max(roll_angle, -max_roll_angle);} else if (strafing_right) {    roll_angle += roll_speed * time_step;    roll_angle = min(roll_angle, max_roll_angle);} else if (roll_angle < 0) {    roll_angle += roll_speed * time_step;    roll_angle = min(roll_angle, 0);} else if (roll_angle > 0) {    roll_angle -= roll_speed * time_step;    roll_angle = max(roll_angle, 0);}Depending on the game this might be perfectly sufficient, but it also might look better if the effect were smoothed out a bit. For a smoother effect, the first thing I'd probably try would be to use the above logic as is, but applied to an interpolation parameter rather than to the roll directly, and then use a non-linear mapping (an exponential mapping, for example) to map the interpolation parameter to the actual roll value.   ;  It works well! Just need to work on the keyboard, because it seems like the mouse is resetting the roll bools. So if I used the arrow keys it wouldn't roll.Thanks, Ajm.   