-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraComponent.h
More file actions
68 lines (51 loc) · 1.82 KB
/
CameraComponent.h
File metadata and controls
68 lines (51 loc) · 1.82 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
#ifndef CAMERA_COMPONENT_H
#define CAMERA_COMPONENT_H
#include "Component.h"
#include "EntitySystem.h"
#include <DirectXMath.h>
using namespace DirectX;
class PositionComponent;
class CameraComponent : public Component
{
public:
struct Frustum
{
XMFLOAT3 nearTopLeft;
XMFLOAT3 nearTopRight;
XMFLOAT3 nearBottomLeft;
XMFLOAT3 nearBottomRight;
XMFLOAT3 farTopLeft;
XMFLOAT3 farTopRight;
XMFLOAT3 farBottomLeft;
XMFLOAT3 farBottomRight;
};
public:
CameraComponent(float verticalFOV, float aspectRatio, float nearDistance, float farDistance, PositionComponent *positionComponent, const XMFLOAT3 &relativePosition, const XMFLOAT3 &relativeOrientationEulerAngles);
void Init() override { EntitySystem::GetInstance().SetCamera(GetOwner()); }
void SetLens(float verticalFOV, float aspectRatio, float nearDistance, float farDistance);
void SetActive(bool active) { mIsActive = active; }
bool IsActive() const { return mIsActive; }
Frustum const GetFrustum(float maxDistance) const;
const XMFLOAT3 GetPosition() const;
const XMFLOAT4X4 GetViewMatrix() const;
const XMFLOAT4X4 GetInverseViewMatrix() const;
const XMFLOAT4X4 &GetProjectionMatrix() const { return mProjectionMatrix; }
float GetNearDistance() const { return mNearDistance; }
float GetFarDistance() const { return mFarDistance; }
private:
// associated entity's position component
PositionComponent *mPositionComponent;
bool mIsActive = false;
// camera pose relative to associated entity (in entity's coordinate system)
XMFLOAT3 mRelativePosition;
XMFLOAT3 mRelativeOrientationEulerAngles;
XMFLOAT4X4 mOffsetMatrix;
XMFLOAT4X4 mViewMatrix;
// perspective projection parameters
float mNearDistance;
float mFarDistance;
float mVerticalFOV;
float mAspectRatio;
XMFLOAT4X4 mProjectionMatrix;
};
#endif // CAMERA_COMPONENT_H