Jump to content
  • Advertisement
jsquare89

First Person Camera SDL2 problem SDL_WarpMouseInWindow

Recommended Posts

I am somewhat new to game development and trying to create a basic 3d engine. I have managed to set up a first person camera and it seems to be working fine for the most part. While I am able to look up, down, left and right just fine the camera is constrained to the mouse movement in the window (i.e when the mouse reaches edges of the window it discontinues camera rotation and mouse is out of window bounds. I tried to use SDL_WarpMouseInWindow(window, center.x,center.y) but when I do this then it messes up the camera and the camera is stuck, even though there is some slight movement of the camera, it keeps going back to the center.

void Camera::UpdateViewByMouse(SDL_Window &window, glm::vec2 mousePosition)
{
float xDistanceFromWindowCenter = mousePosition.x - ((float)1024 / 2) ;
float yDistanceFromWindowCenter = ((float)720 / 2) - mousePosition.y;
yaw = xDistanceFromWindowCenter * cameraRotationSpeed;
pitch = yDistanceFromWindowCenter * cameraRotationSpeed;

SDL_WarpMouseInWindow(&window, 1024 / 2, 768 / 2); 

}

i’ve been stuck on this for far too long. any help would be much appreciated

i have also tried relative mouse movement,  and .xrel and .yrel to avail. polling mouse state with sdl_event. I do also know that SDL_WarpMouseInWindow makes change to event and have tried also ignore and reenabling to no avail

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!