首页 > 解决方案 > LWJGL FPS Camera rotation is limited to pixels

问题描述

I'm currently working on a small fps project for testing, although I am familiar with OpenGl (LWJGL). My problem here is that the rotation of the camera is not very smooth. It "jumps" from pixel to pixel, which is actually very obvious. How can I smoothen it out? [Link to footage:] https://www.youtube.com/watch?v=6Hgt1hXCKKA&feature=youtu.be

Summary of my code: I'm storing the current mouse position in a Vector2f;

I'm increasing yaw and pitch by the relative movement of the camera (new position - old position);

I'm moving the mouse to the center of the window

I'm storing the currennt position (center of the window) in the old position Vector2f

标签: javaopengllwjgl

解决方案


One possible way is to treat the (delta) input of your input device (mouse, keyboard, whatever) not as absolute values for your new camera position or rotation angles, but to treat them as impulse or force to move/rotate in a certain direction. You would then simply use integration over some time differentials dt to update the camera position/rotation with some damping/friction factor to reduce the translational or angular momentum of the camera for it to quickly come to a stop. This would be a somewhat physical simulation. Another possible approach is via parametric interpolation: Whenever you receive a (delta) input of your input device, you calculate a new "desired target position or rotation angle" from that and then interpolate between the current and target state over time to reach that target.


推荐阅读