-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFollowCamera.cpp
More file actions
163 lines (126 loc) · 3.44 KB
/
Copy pathFollowCamera.cpp
File metadata and controls
163 lines (126 loc) · 3.44 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "FollowCamera.h"
using namespace std;
using namespace DirectX;
using namespace DirectX::SimpleMath;
const float FollowCamera::CAMERA_DISTANCE = 7.0f;
FollowCamera::FollowCamera(int width, int height)
: m_targetPos(0, 0, 0)
,Camera(width, height)
{
m_targetAngle = 0.0f;
m_keyboard = nullptr;
m_isChangeFPS = false;
m_player = nullptr;
}
FollowCamera::~FollowCamera()
{
}
void FollowCamera::Update()
{
// キーボードの状態取得
Keyboard::State keyboardState = m_keyboard->GetState();
m_keyboardTracker.Update(keyboardState);
if (m_keyboardTracker.IsKeyPressed(Keyboard::Keys::C))
{
// フラグ切り替え
m_isChangeFPS = !m_isChangeFPS;
}
if (m_player)
{
//目標座標
SetTargetPos(m_player->Get_transmat());
SetTargetAngle(m_player->Get_rotate());
}
if (m_isChangeFPS == true)
{
// 視点、参照点
Vector3 eyepos, refpos;
// ターゲットの座標は、自分の座標に追従(少し上方向にずらす)
eyepos = m_targetPos + Vector3(0, 0.75f, 0);
// ターゲット座標からカメラ座標への差分
Vector3 cameraV(0, 0, CAMERA_DISTANCE);
// カメラの視線方向の逆方向に回転
Matrix rotmat = Matrix::CreateRotationY(m_targetAngle);
cameraV = Vector3::TransformNormal(cameraV, rotmat);
// カメラ座標を計算
refpos = eyepos + cameraV;
Seteyepos(eyepos);
Setrefpos(refpos);
// 基底クラスの更新
Camera::Update();
}
else
{
// 視点、参照点
Vector3 eyepos, refpos;
// ターゲットの座標は、自分の座標に追従(少し上方向にずらす)
refpos = m_targetPos + Vector3(0, 2.0f, 0);
// ターゲット座標からカメラ座標への差分
Vector3 cameraV(0, 0, CAMERA_DISTANCE);
// カメラの視線方向の逆方向に回転
Matrix rotmat = Matrix::CreateRotationY(m_targetAngle);
cameraV = Vector3::TransformNormal(cameraV, rotmat);
// カメラ座標を計算
eyepos = refpos + cameraV;
// 視点を現在位置から補完する
eyepos = m_eyepos + (eyepos - m_eyepos) * 0.1f;
// 参照点を現在位置から補完する
refpos = m_refpos + (refpos - m_refpos) * 0.2f;
Seteyepos(eyepos);
Setrefpos(refpos);
// 基底クラスの更新
Camera::Update();
}
}
void FollowCamera::SetTargetPos(Vector3 targetPos)
{
m_targetPos = targetPos;
}
void FollowCamera::SetTargetAngle(float targetAngle)
{
m_targetAngle = targetAngle;
}
void FollowCamera::SetKeyboard(DirectX::Keyboard* keyboard)
{
m_keyboard = keyboard;
}
// TPSゴム紐カメラマン
/*
// 視点、参照点
Vector3 eyepos, refpos;
// ターゲットの座標は、自分の座標に追従(少し上方向にずらす)
refpos = m_targetPos + Vector3(0, 2.0f, 0);
// ターゲット座標からカメラ座標への差分
Vector3 cameraV(0, 0, CAMERA_DISTANCE);
// カメラの視線方向の逆方向に回転
Matrix rotmat = Matrix::CreateRotationY(m_targetAngle);
cameraV = Vector3::TransformNormal(cameraV, rotmat);
// カメラ座標を計算
eyepos = refpos + cameraV;
// 視点を現在位置から補完する
eyepos = m_eyepos + (eyepos - m_eyepos) * 0.05f;
// 参照点を現在位置から補完する
refpos = m_refpos + (refpos - m_refpos) * 0.2f;
Seteyepos(eyepos);
Setrefpos(refpos);
// 基底クラスの更新
Camera::Update();
*/
// FPSカメラマン
/*
// 視点、参照点
Vector3 eyepos, refpos;
// ターゲットの座標は、自分の座標に追従(少し上方向にずらす)
eyepos = m_targetPos + Vector3(0, 0.25f, 0);
// ターゲット座標からカメラ座標への差分
Vector3 cameraV(0, 0, CAMERA_DISTANCE);
// カメラの視線方向の逆方向に回転
Matrix rotmat = Matrix::CreateRotationY(m_targetAngle);
cameraV = Vector3::TransformNormal(cameraV, rotmat);
// カメラ座標を計算
refpos = eyepos + cameraV;
Seteyepos(eyepos);
Setrefpos(refpos);
// 基底クラスの更新
Camera::Update();
*/