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 pathAtCam.cpp
More file actions
63 lines (50 loc) · 1.54 KB
/
AtCam.cpp
File metadata and controls
63 lines (50 loc) · 1.54 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
#include "AtCam.h"
AtCam::AtCam(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);
//default
_distance = 5.0f;
_currentAngle = 0.0f;
}
void AtCam::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, XMMatrixLookAtLH(posVec, atVec, upVec));
}
void AtCam::Update(Input* nextInput, float deltaT)
{
const float movementSpeed = 5.0f;
const float rotateSpeed = 3.0f;
//zoom
if (nextInput->KeyWDown()) {
_distance -= deltaT * movementSpeed;
}
if (nextInput->KeySDown()) {
_distance += deltaT * movementSpeed;
}
//rotate
if (nextInput->KeyADown()) {
_currentAngle -= deltaT * rotateSpeed;
}
if (nextInput->KeyDDown()) {
_currentAngle += deltaT * rotateSpeed;
}
//boundaries
if (_distance < 1.0f) _distance = 1.0f;
//calculate next positions based on circle algorithm.
//research reference link: https://funprogramming.org/68-Circular-motion-reviewed.html
_eye.x = _at.x + cosf(_currentAngle) * _distance; //uses angle to tell location of orbit
_eye.z = _at.z + sinf(_currentAngle) * _distance;
UpdateView();
}