Skip to content

Commit

Permalink
Fix mouse movement in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKsr committed Jul 9, 2020
1 parent 8ff64ef commit a84630b
Showing 1 changed file with 35 additions and 38 deletions.
73 changes: 35 additions & 38 deletions source/core/vs_fpcameracontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,54 +51,51 @@ void VSFPCameraController::updateCamera(bool handleMouseEvents)
}

// Handle rotation
if (handleMouseEvents)
float xPos = inputHandler->getMouseX();
float yPos = inputHandler->getMouseY();
if (inputHandler->isLeftMouseClicked() && handleMouseEvents)
{
float xPos = inputHandler->getMouseX();
float yPos = inputHandler->getMouseY();
if (inputHandler->isLeftMouseClicked())
if (firstMouse)
{
if (firstMouse)
{
lastX = xPos;
lastY = yPos;
firstMouse = false;
}
else
{
float xoffset = xPos - lastX;
float yoffset = lastY - yPos; // reversed since y-coordinates go from bottom to top
lastX = xPos;
lastY = yPos;
firstMouse = false;
}
else
{
float xoffset = xPos - lastX;
float yoffset = lastY - yPos; // reversed since y-coordinates go from bottom to top

lastX = xPos;
lastY = yPos;
lastX = xPos;
lastY = yPos;

xoffset *= mouseSensitivity;
yoffset *= mouseSensitivity;
xoffset *= mouseSensitivity;
yoffset *= mouseSensitivity;

float yaw = cam->getYaw();
float pitch = cam->getPitch();
yaw += xoffset;
pitch += yoffset;
float yaw = cam->getYaw();
float pitch = cam->getPitch();
yaw += xoffset;
pitch += yoffset;

// Make sure that when pitch is out of bounds, screen doesn't get flipped
if (/*constrainPitch == */ GL_TRUE)
// Make sure that when pitch is out of bounds, screen doesn't get flipped
if (/*constrainPitch == */ GL_TRUE)
{
if (pitch > 89.0F)
{
pitch = 89.0F;
}
if (pitch < -89.0F)
{
if (pitch > 89.0F)
{
pitch = 89.0F;
}
if (pitch < -89.0F)
{
pitch = -89.0F;
}
pitch = -89.0F;
}
cam->setPitchYaw(pitch, yaw);
}
cam->setPitchYaw(pitch, yaw);
}
else
{
lastX = xPos;
lastY = yPos;
}
}
else
{
lastX = xPos;
lastY = yPos;
}

// Handle keyboard movement
Expand Down

0 comments on commit a84630b

Please sign in to comment.