-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewCamera.cpp
102 lines (70 loc) · 2.61 KB
/
newCamera.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "newCamera.h"
#include "glm/glm.hpp"
#include "glm/gtc/type_ptr.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "windows.h"
#include "Shader.hh"
#include "newCube.h"
newCamera::newCamera() { //construtor
}
void newCamera::cam(float lastX, float lastY, double ypos, double xpos, float yaw, float pitch) { //Angulo do rato
float xoffset = xpos - lastX;
float yoffset = lastY - ypos;
lastX = xpos;
lastY = ypos;
float sensitivity = 0.05;
xoffset *= sensitivity;
yoffset *= sensitivity;
yaw += xoffset;
pitch += yoffset;
if (pitch > 89.0f)
pitch = 89.0f;
if (pitch < -89.0f)
pitch = -89.0f;
glm::vec3 direction;
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
direction.y = sin(glm::radians(pitch));
direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
cameraFront = glm::normalize(direction);
}
void newCamera::zoom(GLFWwindow *window) { //Zoom do teclado e moviemnto da cobra
const float cameraSpeed = 0.1f; // e a velocidade dos moveimentos
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
cameraPos += cameraSpeed * cameraFront;
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
cameraPos -= cameraSpeed * cameraFront;
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
cameraPos -= glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
cameraPos += glm::normalize(glm::cross(cameraFront, cameraUp)) * cameraSpeed;
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) { // move a cobra para baixo
if (x > -19.20) {
moveSnake = glm::vec3(x -= 0.10, y, z);
moveSnake2 = glm::vec3(x2 = x + 1.0, y, z2 = z);
moveSnake3 = glm::vec3(x3 = x + 2.0, y, z3 = z);
}
}
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS) { // move a cobra para direita
if (z < 16.0) {
moveSnake = glm::vec3(x, y, z += 0.10);
moveSnake2 = glm::vec3(x2 = x, y, z2 = z - 0.9);
moveSnake3 = glm::vec3(x3 = x, y, z3 = z - 1.8);
}
}
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS) { // move a cobra para cima
if (x < -0.899971) {
moveSnake = glm::vec3(x += 0.10, y, z);
moveSnake2 = glm::vec3(x2 = x - 1.0, y, z2 = z);
moveSnake3 = glm::vec3(x3 = x - 2.0, y, z3 = z);
}
}
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) { // move a cobra para a esquerda
if (z > 0.8 ) {
moveSnake = glm::vec3(x, y, z -= 0.10);
moveSnake2 = glm::vec3(x2 = x, y, z2 = z + 0.9);
moveSnake3 = glm::vec3(x3 = x, y, z3 = z + 1.8);
}
}
}