refactoring

This commit is contained in:
Eikthyrnir 2023-11-24 04:09:19 +01:00
parent 0267879884
commit ff22bce6ba

View File

@ -39,7 +39,7 @@ float deltaTime = 0.f;
glm::vec3 lightColor = glm::vec3(0.9, 0.7, 0.8);
bool moveCamWithMouse = false;
glm::vec2 posMousePressed;
glm::vec2 lastMousePos;
glm::vec2 posMouseReleased;
glm::mat4 createCameraMatrix()
@ -171,23 +171,10 @@ void cursor_position_callback(GLFWwindow* window, double xpos, double ypos)
if (moveCamWithMouse) {
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, spaceshipUp));
//int winWidth, winHeight;
//glfwGetWindowSize(window, &winWidth, &winHeight);
//glm::vec2 currMouseWorldPos = glm::vec2(2 * xpos / winWidth - 1, -(2 * ypos / winHeight - 1));
//glm::vec2 lastMouseWorldPos = glm::vec2(2 * posMousePressed.x / winWidth - 1, -(2 * posMousePressed.y / winHeight - 1));
//glm::vec3 lastPosOnClickPlane = spaceshipPos + 1.5f * spaceshipDir
// + lastMouseWorldPos.x * spaceshipSide
// + lastMouseWorldPos.y * spaceshipUp;
//glm::vec3 currPosOnClickPlane = spaceshipPos + 1.5f * spaceshipDir
// + currMouseWorldPos.x * spaceshipSide
// + currMouseWorldPos.y * spaceshipUp;
//spaceshipDir = glm::normalize(spaceshipDir - (currPosOnClickPlane - lastPosOnClickPlane) / 10.f);
glm::vec3 diff = spaceshipSide * (xpos - posMousePressed.x) - spaceshipUp * (ypos - posMousePressed.y);
glm::vec3 diff = spaceshipSide * (xpos - lastMousePos.x) - spaceshipUp * (ypos - lastMousePos.y);
spaceshipDir = glm::normalize(spaceshipDir - diff / 1000.f);
posMousePressed = glm::vec2(xpos, ypos);
lastMousePos = glm::vec2(xpos, ypos);
}
}
@ -195,7 +182,7 @@ void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
{
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
posMousePressed = glm::vec2(xpos, ypos);
lastMousePos = glm::vec2(xpos, ypos);
if (button == GLFW_MOUSE_BUTTON_1 && action == GLFW_PRESS) {
moveCamWithMouse = true;