-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera_PBR.cpp
More file actions
105 lines (91 loc) · 2.96 KB
/
Copy pathCamera_PBR.cpp
File metadata and controls
105 lines (91 loc) · 2.96 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
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
103
104
105
#include "Camera_PBR.h"
Camera::Camera(glm::vec3 position, glm::vec3 target, glm::vec3 worldup)
{
Position = position;
WorldUp = worldup;
Forward = glm::normalize(target - position);
Right = glm::normalize(glm::cross(Forward, WorldUp));
Up = glm::normalize(glm::cross(Right, Forward));
}
Camera::Camera(glm::vec3 position, float pitch, float yaw, glm::vec3 worldup)
{
Position = position;
WorldUp = worldup;
Pitch = pitch;
Yaw = yaw;
Forward.x = glm::cos(Pitch) * glm::cos(Yaw);
Forward.y = glm::sin(Pitch);
Forward.z = glm::cos(Pitch) * glm::sin(Yaw);
Right = glm::normalize(glm::cross(Forward, WorldUp));
Up = glm::normalize(glm::cross(Right, Forward));
}
glm::mat4 Camera::GetViewMatrix()
{
return glm::lookAt(Position, Position + Forward, WorldUp);
}
// the following three functions are about process input from mouse
void Camera::ProcessMouseMovement(float Delta_x, float Delta_y)
{
Pitch += -Delta_y * SenseY;
Yaw += Delta_x * SenseX;
UpdateCameraVector();
}
void Camera::UpdateCameraVector()
{
Forward.x = glm::cos(Pitch) * glm::cos(Yaw);
Forward.y = glm::sin(Pitch);
Forward.z = glm::cos(Pitch) * glm::sin(Yaw);
Right = glm::normalize(glm::cross(Forward, WorldUp));
Up = glm::normalize(glm::cross(Right, Forward));
}
void Camera::UpdateCameraPos()
{
Position += Forward * SpeedZ * SenseSpeedZ + Right * SpeedX * SenseSpeedX + Up * SpeedY * SenseSpeedY;
}
void Camera::UpdateCameraPos_ThirdPersonView(glm::vec3 displacement)
{
Position += displacement;
}
void Camera::ProcessMouseMovement_ThirdPersonView(float Delta_x, float Delta_y)
{
glm::vec3 temp_pos = Position + Delta_y * Up * 0.1f;
if (temp_pos.y >= 0.9 * fov)
{
Position.y = 0.9 * fov;
}
else if (temp_pos.y <= 1.0f)
{
Position.y = 1.0f;
}
else
Position += Delta_y * Up * 0.1f;
Position += -Delta_x * Right * 0.1f;
}
//// the rest are different camera mode
//void Camera::ThirdPersonView_LookAtCharacter(Character character)
//{
// //Position = character.position + glm::vec3(0.0f, 6.0f, 12.0f);
// Forward = glm::normalize((character.position + glm::vec3(0.0f, 2.0f, 0.0f)) - Position);
// UpdateCameraVector_ThirdPersonView(character);
//}
//
//void Camera::UpdateCameraVector_ThirdPersonView(Character character)
//{
// Right = glm::normalize(glm::cross(Forward, WorldUp));
// Up = glm::normalize(glm::cross(Right, Forward));
// Position = (character.position + glm::vec3(0.0f, 2.0f, 0.0f)) - fov * Forward;
//}
//
//
//void Camera::TopDownView_LookAtCharacter(Character character)
//{
// Forward = glm::normalize((character.position + glm::vec3(0.0f, 2.0f, 0.0f)) - Position);
// UpdateCameraVector_TopDownView(character);
//}
//
//void Camera::UpdateCameraVector_TopDownView(Character character)
//{
// Right = glm::normalize(glm::cross(Forward, WorldUp));
// Up = glm::normalize(glm::cross(Right, Forward));
// Position = (character.position + glm::vec3(0.0f, 2.0f, 0.0f)) - 30.0f * Forward;
//}