Repository navigation
Expand file tree
/
Copy pathCamera.cpp
More file actions
78 lines (65 loc) · 1.96 KB
/
Copy pathCamera.cpp
File metadata and controls
78 lines (65 loc) · 1.96 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
#include "Camera.h"
Camera::Camera()
{
eye = XMVectorSet(0, 0, -1, 1);
up = XMVectorSet(0, 1, 0, 0);
at = XMVectorSet(0, 0, 1, 1);
XMStoreFloat4x4(&move, XMMatrixIdentity());
XMStoreFloat4x4(&rotate, XMMatrixIdentity());
XMStoreFloat4x4(&view, XMMatrixLookAtLH(eye, at, up));
}
void Camera::Pitch(float x)
{
XMMATRIX temp = XMMatrixMultiply(XMLoadFloat4x4(&rotate), XMMatrixRotationX(x));
XMStoreFloat4x4(&rotate, temp);
}
void Camera::Yaw(float y)
{
XMMATRIX temp = XMMatrixMultiply(XMLoadFloat4x4(&rotate), XMMatrixRotationY(y));
XMStoreFloat4x4(&rotate, temp);
}
void Camera::Roll(float z)
{
XMMATRIX temp = XMMatrixMultiply(XMLoadFloat4x4(&rotate), XMMatrixRotationZ(z));
XMStoreFloat4x4(&rotate, temp);
}
void Camera::MoveForwardBy(float z)
{
XMMATRIX temp = XMMatrixMultiply(XMLoadFloat4x4(&move), XMMatrixTranslation(0, 0, z));
XMStoreFloat4x4(&move, temp);
}
void Camera::MoveRightBy(float x)
{
XMMATRIX temp = XMMatrixMultiply(XMLoadFloat4x4(&move), XMMatrixTranslation(x, 0, 0));
XMStoreFloat4x4(&move, temp);
}
void Camera::MoveUpBy(float y)
{
XMMATRIX temp = XMMatrixMultiply(XMLoadFloat4x4(&move), XMMatrixTranslation(0, y, 0));
XMStoreFloat4x4(&move, temp);
}
void Camera::Frame()
{
XMMATRIX temp = XMLoadFloat4x4(&move)*XMLoadFloat4x4(&rotate);
eye = XMVector4Transform(eye, temp);
up = XMVector4Transform(up, XMLoadFloat4x4(&rotate));
at = eye + XMVector4Transform(XMVectorSet(0, 0, 1, 0), XMLoadFloat4x4(&rotate));
temp = XMMatrixLookAtLH(eye, at, up);
XMStoreFloat4x4(&view, temp);
XMStoreFloat4x4(&move, XMMatrixIdentity());
XMStoreFloat4x4(&rotate, XMMatrixIdentity());
}
void Camera::SetEye(XMVECTOR& e)
{
e.m128_f32[3] = 1.0f;
eye = e;
at = eye + XMVector4Transform(XMVectorSet(0, 0, 1, 0), XMLoadFloat4x4(&rotate));
}
const XMMATRIX Camera::GetViewMatrix()
{
return XMLoadFloat4x4(&view);
}
XMVECTOR Camera::GetEyePosition()
{
return eye;
}