-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.h
More file actions
101 lines (77 loc) · 1.95 KB
/
Camera.h
File metadata and controls
101 lines (77 loc) · 1.95 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
#pragma once
#define GLM_ENABLE_EXPERIMENTAL
#include<glm/glm.hpp>
#include<glm/ext.hpp>
#include <glm/gtc/matrix_transform.hpp>
//仮想的なカメラのクラス
class Camera
{
private:
//ウィンドウのサイズ
int windowWidth, windowHeight;
//一つ前のフレームのマウス座標
double lastCursorX, lastCursorY;
//マウス移動の感度の調整
double mouseScale = 15.0;
//座標
glm::vec3 position;
//追従するオブジェクトの座標
glm::vec3 parentPos;
//球面座標上の半径
float distance;
//追従するオブジェクトとの距離
glm::vec3 offsetPos;
//画面の比率
float aspect;
//視野角
float viewAngle;
//カメラの移動速度
float viewPointSpeed;
//球面座標上の角度
float theta, phi;
//クリップ範囲
float zNear, zFar;
//ビュー行列の計算、キューブマッピング用の行列も同時に計算
void calcViewMat();
public:
//カメラの球面座標の移動のフラッグ
bool sphereMove;
//カメラの正面、右、上方向のベクトル
glm::vec3 forward, right, up;
//通常のレンダリング用のビュー行列
glm::mat4 viewMat;
//キューブマッピング用のビュー行列、通常のビュー行列のy成分の回転のみ反転している
glm::mat4 cubemapViewMat;
//投資投影行列
glm::mat4 perspectiveMat;
Camera(int width,int height);
//座標の設定
void setPosition(glm::vec3 pos);
//座標の取得
glm::vec3 getPosition() { return position; }
//追従するオブジェクトの位置を設定
void setParentPos(glm::vec3 position);
//球面座標上の半径の設定
void setDistance(float distance);
//追従するオブジェクトとの距離を設定
void setOffsetPos(glm::vec3 offset);
//球面座標の設定 引数は矢印キーから
void setSpherePos(float theta, float phi);
//視野角の設定
void setViewAngle(float f);
//視野角の取得
float getViewAngle();
//x方向の移動の取得
float getTheta();
//ファークリップ範囲の取得
void getzNearFar(float& near, float& far);
//追従するターゲットの座標を取得
glm::vec3 getViewTarget();
//カメラの更新処理
void Update();
//矢印キーからの入力を処理
void customUpdate();
void updateTransformMatrix();
//カメラの位置をセットする
void posReset();
};