-
Notifications
You must be signed in to change notification settings - Fork 8
/
fixedcamera.h
56 lines (48 loc) · 1.4 KB
/
fixedcamera.h
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
#pragma once
#include <glad\glad.h>
#include <glm\glm.hpp>
#include <glm\gtc\matrix_transform.hpp>
#include <vector>
const float ZOOM = 45.0f;
class FixedCamera
{
public:
//Camera Attributes
glm::vec3 Position;
glm::vec3 TargetPos;
glm::vec3 WorldUp;
glm::mat4 ViewMatrix;
glm::vec3 Direction;//Actually the opposite Direction in which camera is looking
glm::vec3 Up;
glm::vec3 Right;
float Zoom;
FixedCamera(glm::vec3 pos = glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3 targetPos = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f))
{
Position = pos;
WorldUp = up;
TargetPos = targetPos;
ViewMatrix = glm::lookAt(Position, TargetPos, WorldUp);
Direction = glm::normalize(Position - TargetPos);
Right = glm::normalize(glm::cross(Direction, WorldUp));
Up = glm::normalize(glm::cross(Right, Direction));
Zoom = ZOOM;
}
glm::mat4 GetViewMatrix()
{
ViewMatrix = glm::lookAt(Position, TargetPos, WorldUp);
Direction = glm::normalize(Position - TargetPos);
Right = glm::normalize(glm::cross(Direction, WorldUp));
Up = glm::normalize(glm::cross(Right, Direction));
return ViewMatrix;
}
//Processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis
void ProcessMouseScroll(float yoffset)
{
if (Zoom >= 1.0f && Zoom <= 45.0f)
Zoom -= yoffset;
if (Zoom <= 1.0f)
Zoom = 1.0f;
if (Zoom >= 45.0f)
Zoom = 45.0f;
}
};