-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
60 lines (42 loc) · 1.21 KB
/
Copy pathPlayer.cpp
File metadata and controls
60 lines (42 loc) · 1.21 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
53
54
55
56
57
58
59
60
#include "Player.h"
#include "glm/trigonometric.hpp"
Player::Player(glm::vec3 posistion, float speed) {
this->speed = speed;
this->position = posistion;
}
Player::Player(float x, float y, float z, float speed) {
this->speed = speed;
this->position = glm::vec3(x, y, z);
}
void Player::setSpeed(float speed) {
this->speed = speed;
}
void Player::move(const Keyboard& key) {
if (key.keyPressed(Keyboard::KEY_W))
position += speed * front;
if (key.keyPressed(Keyboard::KEY_S))
position -= speed * front;
if (key.keyPressed(Keyboard::KEY_A))
position -= glm::normalize(glm::cross(front, up)) * speed;
if (key.keyPressed(Keyboard::KEY_D))
position += glm::normalize(glm::cross(front, up)) * speed;
}
void Player::look(const Mouse& mouse) {
double xof, yof, x, y;
x = mouse.getX();
y = mouse.getY();
xof = x - lx;
yof = ly - y;
lx = x;
ly = y;
xof *= mouse.getSensitivity();
yof *= mouse.getSensitivity();
yaw += xof;
pitch += yof;
if (pitch > 89.0f) pitch = 89.0f;
if (pitch < -89.0f) pitch = -89.0f;
front.x = cos(glm::radians(pitch)) * cos(glm::radians(yaw));
front.y = sin(glm::radians(pitch));
front.z = cos(glm::radians(pitch)) * sin(glm::radians(yaw));
front = glm::normalize(front);
}