-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.cpp
55 lines (37 loc) · 1.1 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
/* START OF 'camera.cpp' FILE */
#include "camera.h"
CAMERA::CAMERA (void) :
viewDirection(0.0f, 0.0f, -1.0f), up(0.0f, 1.0f, 0.0f), position(0.0f, 0.0f, -10.0f)
{
}
CAMERA::CAMERA (const CAMERA & newCamera) :
viewDirection(newCamera.viewDirection),
position(newCamera.position),
up(newCamera.up)
{
}
CAMERA::~CAMERA (void)
{
}
CAMERA & CAMERA::operator= (const CAMERA & newCamera)
{
viewDirection = newCamera.viewDirection;
position = newCamera.position;
up = newCamera.up;
return *this;
}
void CAMERA::MouseUpdate (const POINT & mouseDelta, const float rotationSpeed)
{
float angleX = mouseDelta.x * rotationSpeed;
float angleY = mouseDelta.y * rotationSpeed;
// Horizontal rotation
viewDirection = glm::mat3(glm::rotate(angleX, up)) * viewDirection;
// Vertical rotation
glm::vec3 rotateAround = glm::cross(viewDirection, up);
viewDirection = glm::mat3(glm::rotate(angleY, rotateAround)) * viewDirection;
}
glm::mat4 CAMERA::GetWorldToViewMatrix (void) const
{
return glm::lookAt(position, position + viewDirection, up);
}
/* END OF 'camera.cpp' FILE */