This repository was archived by the owner on Jun 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToCam.cpp
More file actions
59 lines (47 loc) · 1.4 KB
/
ToCam.cpp
File metadata and controls
59 lines (47 loc) · 1.4 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
#include "ToCam.h"
ToCam::ToCam(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;
//initialize the view matrix default
UpdateView();
//initialize the projection matrix
Reshape(_windowWidth, _windowHeight, _nearDepth, _farDepth);
}
void ToCam::UpdateView()
{
XMVECTOR posVec = XMVectorSet(_eye.x, _eye.y, _eye.z, 0.0f);
XMVECTOR atVec = XMVectorSet(_at.x, _at.y, _at.z, 0.0f);
XMVECTOR upVec = XMVectorSet(_up.x, _up.y, _up.z, 0.0f);
XMStoreFloat4x4(&_view, XMMatrixLookToLH(posVec, atVec, upVec));
}
void ToCam::Update(Input* nextInput, float deltaT)
{
const float movementSpeed = 5.0f;
_distance = 0.0f;
_strafe = 0.0f;
//zoom
if (nextInput->KeyWDown()) {
_distance = deltaT * movementSpeed;
}
if (nextInput->KeySDown()) {
_distance = -(deltaT * movementSpeed);
}
//rotate
if (nextInput->KeyADown()) {
_strafe = -(deltaT * movementSpeed);
}
if (nextInput->KeyDDown()) {
_strafe = deltaT * movementSpeed;
}
XMVECTOR posVec = XMVectorSet(_eye.x, _eye.y, _eye.z, 0.0f);
XMVECTOR atVec = XMVectorSet(_at.x, _at.y, _at.z, 0.0f);
posVec += XMVector4Normalize(atVec) * _distance;
posVec += XMVectorSet(_strafe, 0.0f, 0.0f, 0.0f);
XMStoreFloat3(&_eye, posVec);
UpdateView();
}