-
Notifications
You must be signed in to change notification settings - Fork 8
/
Trackball.h
44 lines (36 loc) · 1.05 KB
/
Trackball.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include <iostream>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtc/matrix_inverse.hpp>
#include <math.h>
#include <algorithm>
#include<glm/gtc/quaternion.hpp>
#include<glm/common.hpp>
class Trackball
{
private:
int windowWidth;
int windowHeight;
int mouseEvent;
GLfloat rollSpeed;
GLfloat angle;
glm::vec3 prevPos;
glm::vec3 currPos;
glm::vec3 camAxis;
glm::quat _quat;
bool flag;
public:
bool track;
Trackball(int window_width, int window_height, GLfloat roll_speed = 1.0f);
glm::vec3 toScreenCoord(double x, double y);
void mouseButtonCallback(bool _track, double x, double y);
void cursorCallback(GLFWwindow *window, double x, double y);
glm::quat createViewRotationQuat(float deltaTime);
glm::quat createWorldRotationQuat(glm::mat4 view_matrix, float deltaTime, bool& f);
glm::quat createModelRotationQuat(glm::mat4 view_matrix, glm::mat4 model_matrix, float deltaTime);
};