-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.cpp
60 lines (44 loc) · 1.16 KB
/
camera.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <glad/glad.h>
#include <glfw3.h>
#include <glm.hpp>
#include <gtc/matrix_transform.hpp>
#include <gtc/type_ptr.hpp>
#include <iostream>
//other libs
#include <string>
#include <vector>
#include <stack>
#include <cmath>
void keyboardMouseIO()
{
double currentTime = glfwGetTime();
float deltaTime = float(currentTime - lastTime);
glm::vec3 pos = glm::vec3(0 , 0, 0, 5);
float horizontal = 3.14f;
float vertical = 0.0f;
float initFov = 45.0f;
float speed = 3.0f;
float mouseSpeed = 0.005f;
int xPos;
int yPos;
glfwGetMousePos(&xPos, &yPos);
glfwSetMousePos(1024/2, 768/2);
horizontal += mouseSpeed * deltaTime * float(1024/2 - xPos);
vertical += mouseSpeed * deltaTime * float(768/2 - yPos);
glm::vec3 direction(
cos(vertical) * sin(horizontal),
sin(vertical),
cos(vertical) * cos(horizontal)
);
glm::vec3 right(
sin(horizontal - 3.14f/2.0f),
0,
cos(horizontal - 3.14f/2.0f)
);
glm::vec3 up = glm::cross(right, direction);
//Move:
if (glfwGetKey(GLFW_KEY_UP) == GLFW_PRESS)
{
pos += direction * deltaTime * speed;
}
}