-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
52 lines (43 loc) · 1.46 KB
/
Camera.cpp
File metadata and controls
52 lines (43 loc) · 1.46 KB
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
#include "Camera.h"
#include "glm/gtc/matrix_transform.hpp"
#include <iostream>
#include <math.h>
Camera::Camera(GLFWwindow* window)
: eye_x(0.0f), eye_y(0.0f), eye_z(0.8f), angle_y(0.0f), cameraSpeed(0.003f), window(window) {}
glm::mat4 Camera::update(float deltaTime, glm::mat4 pMatrix) {
float deltaSpeed = cameraSpeed * deltaTime;
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) {
// angle_y += 0.3f * deltaSpeed;
}
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) {
// angle_y -= 0.3f * deltaSpeed;
}
float lookPosX = sin(angle_y), lookPosZ = -cos(angle_y);
// if(glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
//{
// eye_x += lookPosX * deltaSpeed;
// eye_z += lookPosZ * deltaSpeed;
//}
//
// if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
//{
// eye_x -= lookPosX * deltaSpeed;
// eye_z -= lookPosZ * deltaSpeed;
//}
//
// if(glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS)
//{
// eye_y += 0.3f * deltaSpeed;
//}
//
// if(glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)
//{
// eye_y -= 0.3f * deltaSpeed;
//}
glm::mat4 vMatrix = glm::lookAt(glm::vec3(eye_x, eye_y, eye_z),
glm::vec3(eye_x + lookPosX, eye_y, eye_z + lookPosZ), glm::vec3(0.0f, 1.0f, 0.0f));
// gluLookAt(eye_x, eye_y, eye_z,
// eye_x + lookPosX, eye_y, eye_z+lookPosZ,
// 0.0f, 1.0f, 0.0f);
return pMatrix * vMatrix;
}