-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.cpp
49 lines (37 loc) · 1.33 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
#include "Camera.h"
Camera::Camera(XMFLOAT3 position, XMFLOAT3 at, XMFLOAT3 up, FLOAT windowWidth, FLOAT windowHeight, FLOAT nearDepth, FLOAT farDepth)
: _eye(position), _at(at), _up(up), _windowWidth(windowWidth), _windowHeight(windowHeight), _nearDepth(nearDepth), _farDepth(farDepth)
{
Update();
}
Camera::~Camera()
{
}
void Camera::Update()
{
// Initialize the view matrix
XMFLOAT4 eye = XMFLOAT4(_eye.x, _eye.y, _eye.z, 1.0f);
XMFLOAT4 at = XMFLOAT4(_at.x, _at.y, _at.z, 1.0f);
XMFLOAT4 up = XMFLOAT4(_up.x, _up.y, _up.z, 0.0f);
XMVECTOR EyeVector = XMLoadFloat4(&eye);
XMVECTOR AtVector = XMLoadFloat4(&at);
XMVECTOR UpVector = XMLoadFloat4(&up);
XMStoreFloat4x4(&_view, XMMatrixLookAtLH(EyeVector, AtVector, UpVector));
// Initialize the projection matrix
XMStoreFloat4x4(&_projection, XMMatrixPerspectiveFovLH(0.25f * XM_PI, _windowWidth / _windowHeight, _nearDepth, _farDepth));
}
void Camera::Reshape(FLOAT windowWidth, FLOAT windowHeight, FLOAT nearDepth, FLOAT farDepth)
{
_windowWidth = windowWidth;
_windowHeight = windowHeight;
_nearDepth = nearDepth;
_farDepth = farDepth;
}
XMFLOAT4X4 Camera::GetViewProjection() const
{
XMMATRIX view = XMLoadFloat4x4(&_view);
XMMATRIX projection = XMLoadFloat4x4(&_projection);
XMFLOAT4X4 viewProj;
XMStoreFloat4x4(&viewProj, view * projection);
return viewProj;
}