-
Notifications
You must be signed in to change notification settings - Fork 1
/
Camera.cpp
70 lines (56 loc) · 1.73 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
61
62
63
64
65
66
67
68
69
#include "Camera.h"
#include "config.h"
#include <glm/gtc/matrix_transform.hpp>
#include <stdio.h>
Camera::Camera(){
Camera(glm::vec3(0.0f,0.0f,0.0f), glm::vec3(0.0f,0.0f,0.0f), glm::vec3(0.0f,0.0f,0.0f));
}
Camera::Camera(glm::vec3 Pos, glm::vec3 Target, glm::vec3 Up){
mBasePos = mPos = Pos;
mTarget = Target;
mUp = Up;
}
glm::mat4 Camera::getView(){
return glm::lookAt(mPos,mPos+mTarget,mUp);
}
void Camera::setDomain(glm::vec3 p1, glm::vec3 p2){
mD1 = p1;
mD2 = p2;
}
void Camera::handleKeyboard(GLFWwindow* window){
if(glfwGetKey(window, GLFW_KEY_KP_8)==GLFW_PRESS)
mPos[2]-=cameraSpeed;
if(glfwGetKey(window, GLFW_KEY_KP_2)==GLFW_PRESS)
mPos[2]+=cameraSpeed;
if(glfwGetKey(window, GLFW_KEY_KP_4)==GLFW_PRESS)
mPos[0]-=cameraSpeed;
if(glfwGetKey(window, GLFW_KEY_KP_6)==GLFW_PRESS)
mPos[0]+=cameraSpeed;
if(glfwGetKey(window, GLFW_KEY_KP_0)==GLFW_PRESS)
mPos = mBasePos;
if(glfwGetKey(window, GLFW_KEY_KP_7)==GLFW_PRESS)
mPos[1]+=cameraSpeed;
if(glfwGetKey(window, GLFW_KEY_KP_9)==GLFW_PRESS)
mPos[1]-=cameraSpeed;
if(mD1[2]>mD2[2]){
if(mPos[2]>mD1[2])mPos[2]=mD1[2];
if(mPos[2]<mD2[2])mPos[2]=mD2[2];
}else{
if(mPos[2]<mD1[2])mPos[2]=mD1[2];
if(mPos[2]>mD2[2])mPos[2]=mD2[2];
}
if(mD1[1]>mD2[1]){
if(mPos[1]>mD1[1])mPos[1]=mD1[1];
if(mPos[1]<mD2[1])mPos[1]=mD2[1];
}else{
if(mPos[1]<mD1[1])mPos[1]=mD1[1];
if(mPos[1]>mD2[1])mPos[1]=mD2[1];
}
if(mD1[0]>mD2[0]){
if(mPos[0]>mD1[0])mPos[0]=mD1[0];
if(mPos[0]<mD2[0])mPos[0]=mD2[0];
}else{
if(mPos[0]<mD1[0])mPos[0]=mD1[0];
if(mPos[0]>mD2[0])mPos[0]=mD2[0];
}
}