-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera_Class.h
More file actions
146 lines (124 loc) · 3.14 KB
/
Camera_Class.h
File metadata and controls
146 lines (124 loc) · 3.14 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
#define MOVE_FORWARD 1
#define MOVE_BACK 2
#define MOVE_UP 3
#define MOVE_DOWN 4
#define MOVE_RIGHT 5
#define MOVE_LEFT 6
#define ROTATE_YAW 1
#define ROTATE_PITCH 2
class camera_class
{
private:
IDirect3DDevice9* device;
D3DXMATRIX viewMatrix;
D3DXMATRIX projMatrix;
D3DXMATRIX rotateBuffer;
D3DXVECTOR3 pos;
D3DXVECTOR3 look;
D3DXVECTOR3 right;
D3DXVECTOR3 up;
DWORD ObjectID;
char buffer[256];
LPCTSTR camName;
public:
void initCamBase(IDirect3DDevice9* bDevice)
{
device = bDevice;
camName = L"Camera";
pos = D3DXVECTOR3(0.0f, 0.0f, -20.0f);
look = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
right = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
this->resetMatrices();
}
void move(short moveType)
{
switch(moveType)
{
case MOVE_FORWARD:
pos += look * 0.025;
break;
case MOVE_BACK:
pos -= look * 0.025;
break;
case MOVE_UP:
break;
case MOVE_DOWN:
break;
case MOVE_RIGHT:
pos += D3DXVECTOR3(right.x, 0.0f, right.z) * 0.025;
break;
case MOVE_LEFT:
pos -= D3DXVECTOR3(right.x, 0.0f, right.z) * 0.025;
break;
}
this->resetMatrices();
}
void rotate(float dX, float dY)
{
if(dX > 0)
{
D3DXMatrixRotationAxis(&rotateBuffer, &up, dX * 0.15f);
D3DXVec3TransformCoord(&right, &right, &rotateBuffer);
D3DXVec3TransformCoord(&look, &look, &rotateBuffer);
}
if(dX < 0)
{
D3DXMatrixRotationAxis(&rotateBuffer, &up, dX * 0.15f);
D3DXVec3TransformCoord(&right, &right, &rotateBuffer);
D3DXVec3TransformCoord(&look, &look, &rotateBuffer);
}
if(dY > 0)
{
D3DXMatrixRotationAxis(&rotateBuffer, &right, dY * 0.15f);
D3DXVec3TransformCoord(&up, &up, &rotateBuffer);
D3DXVec3TransformCoord(&look, &look, &rotateBuffer);
}
if(dY < 0)
{
D3DXMatrixRotationAxis(&rotateBuffer, &right, dY * 0.15f);
D3DXVec3TransformCoord(&up, &up, &rotateBuffer);
D3DXVec3TransformCoord(&look, &look, &rotateBuffer);
}
this->resetMatrices();
}
LPCTSTR getCamName()
{ return camName; }
D3DXVECTOR3* getPtRight()
{ return &right;}
D3DXVECTOR3* getPtUp()
{ return &up;}
D3DXVECTOR3* getPtLook()
{ return &look;}
void resetMatrices()
{
D3DXVec3Normalize(&look, &look);
D3DXVec3Cross(&up, &look, &right);
D3DXVec3Normalize(&up, &up);
D3DXVec3Cross(&right, &up, &look);
D3DXVec3Normalize(&right, &right);
// Ñòðîèì ìàòðèöó âèäà:
float x = -D3DXVec3Dot(&right, &pos);
float y = -D3DXVec3Dot(&up, &pos);
float z = -D3DXVec3Dot(&look, &pos);
(viewMatrix)(0, 0) = right.x;
(viewMatrix)(0, 1) = up.x;
(viewMatrix)(0, 2) = look.x;
(viewMatrix)(0, 3) = 0.0f;
(viewMatrix)(1, 0) = right.y;
(viewMatrix)(1, 1) = up.y;
(viewMatrix)(1, 2) = look.y;
(viewMatrix)(1, 3) = 0.0f;
(viewMatrix)(2, 0) = right.z;
(viewMatrix)(2, 1) = up.z;
(viewMatrix)(2, 2) = look.z;
(viewMatrix)(2, 3) = 0.0f;
(viewMatrix)(3, 0) = x;
(viewMatrix)(3, 1) = y;
(viewMatrix)(3, 2) = z;
(viewMatrix)(3, 3) = 1.0f;
D3DXMatrixPerspectiveFovLH(&projMatrix, D3DX_PI * 0.2f, (float)DirectXWidth/(float)DirectXHeight, 0.01f, 1000.0f);
device->SetTransform(D3DTS_VIEW, &viewMatrix);
device->SetTransform(D3DTS_PROJECTION, &projMatrix);
}
};