-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponentCamera.h
More file actions
103 lines (77 loc) · 2.11 KB
/
ComponentCamera.h
File metadata and controls
103 lines (77 loc) · 2.11 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
#ifndef __ComponentCamera_H__
#define __ComponentCamera_H__
#include "Globals.h"
#include "Component.h"
#include "MathGeoLib/Geometry/Frustum.h"
#include "MathGeoLib/Math/float4x4.h"
const int AABB_OUT = 0;
const int AABB_IN = 1;
const int AABB_INTERSECT = 2;
const bool FRONT = true;
const bool BEHIND = false;
class ComponentCamera : public Component
{
public:
ComponentCamera(GameObject* go);
ComponentCamera(GameObject* go, ComponentCamera* comp);
~ComponentCamera();
void Update();
bool CleanUp();
//Methods
void SetFOV();
void SetAspectRatio(int newHeight, int newWidth);
void Rotate(const float dx, const float dy);
void Move(const float3 &direction);
void TranslateCameraToPoint(const float3 &newPos);
void SetNearPlaneDistance(const float nearDist);
void SetFarPlaneDistance(const float farDist);
void LookAt(const float3 &target);
void ComputeViewMatrix();
void ComputeProjMatrix();
void DrawInspector();
//Frutum intersection
int AABBWithinFrustum(const AABB &aabb) const;
bool SideOfPlane(const float3 &point, const Plane &plane) const;
//Saving and loading
void OnSave(SceneLoader & loader);
void OnLoad(SceneLoader & loader);
//Drawing
void DrawFrustum();
//Variables
float aspect = 1.0f;
Frustum* frustum;
//Matrices
float4x4 proj = float4x4::zero;
float4x4 view = float4x4::zero;
float movementSpeed = 0.2f;
float rotationSpeed = 0.015f;
float zoomSpeed = 0.5f;
float motionOffset = 2.5f;
unsigned int frustumVAO = 0;
float3 oldPosition;
float Hnear;
float Wnear;
//Then we do the same for the far plane
float Hfar;
float Wfar;
//Now we get the center of the planes
float3 centerNear;
float3 centerFar;
//And now we get our points
float3 NearTopLeft;
float3 NearTopRight;
float3 NearBottomLeft;
float3 NearBottomRight;
float3 FarTopLeft;
float3 FarTopRight;
float3 FarBottomLeft;
float3 FarBottomRight;
bool isMainCamera = false;
private:
bool isPerspective = true;
const char* perspectives[2] = { "Perspective", "Orthogonal"};
int currentPerspective = 0;
const char* usedPerspective = perspectives[0];
void ChangeFrustumType();
};
#endif __ComponentCamera_H__