Trying to implement camera movement by using the mouse movement callback when left click is pressed, but every time nothing happens right when clicking and once i start dragging everything pauses until I release the mouse button. Pertinent code below.
[code]class Camera {
private:
//Vectors
glm::vec3 position;
glm::vec3 facing;
glm::vec3 right;
glm::vec3 up;
glm::mat4 view;
//Viewing angles
float horizontalAngle;
float verticalAngle;
//Movement speeds
float moveSpeed;
float rotateSpeed;
float mouseSpeed;
//Status
bool pressA, pressS, pressD, pressQ, pressW, pressE;
double moveByMouseX, moveByMouseY;
bool rMousePressed;
public:
Camera(void);
void update(double t);
glm::mat4 render(void);
//Forward callback
void keyEvent(GLFWwindow* window, int key, int scancode, int action, int mods);
void mouseEvent(GLFWwindow* window, double xpos, double ypos);
void buttonEvent(GLFWwindow* window, int button, int action, int mods);
};
void Camera::mouseEvent(GLFWwindow* window, double xpos, double ypos) {
if (rMousePressed) {
int x, y;
glfwGetWindowSize(window, &x, &y);
moveByMouseX += (x / 2) - xpos;
moveByMouseY += (y / 2) - ypos;
glfwSetCursorPos(window, x / 2, y / 2);
}
}
void Camera::buttonEvent(GLFWwindow* window, int button, int action, int mods) {
if (button == GLFW_MOUSE_BUTTON_LEFT) {
rMousePressed = (bool)action;
}
}
void Camera::update(double t) {
horizontalAngle += moveByMouseX * mouseSpeed * t;
verticalAngle += moveByMouseY * mouseSpeed * t;
moveByMouseX = 0.0f;
moveByMouseY = 0.0f;
if (verticalAngle > 45.0f)
verticalAngle = 45.05f;
if (verticalAngle < -45.0f)
verticalAngle = -45.0f;
facing = glm::vec3(cos(verticalAngle) * sin(horizontalAngle), sin(verticalAngle), cos(verticalAngle)*cos(horizontalAngle));
right = glm::vec3(sin(horizontalAngle - 3.14f / 2.0f), 0, cos(horizontalAngle - 3.14f / 2.0f));
up = glm::cross(right, facing);
view = glm::lookAt(position, position + facing, up);
}
[/code]