-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrices.h
50 lines (42 loc) · 1.51 KB
/
matrices.h
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
#pragma once
#include "main.h"
inline D3DXMATRIX shift_matrix(D3DXVECTOR3 shift)
{
return D3DXMATRIX( 1, 0, 0, shift.x,
0, 1, 0, shift.y,
0, 0, 1, shift.z,
0, 0, 0, 1 );
}
inline D3DXMATRIX rotate_x_matrix(float angle)
{
return D3DXMATRIX( 1, 0, 0, 0,
0, cos(angle), -sin(angle), 0,
0, sin(angle), cos(angle), 0,
0, 0, 0, 1 );
}
inline D3DXMATRIX rotate_y_matrix(float angle)
{
return D3DXMATRIX( cos(angle), 0, sin(angle), 0,
0, 1, 0, 0,
-sin(angle), 0, cos(angle), 0,
0, 0, 0, 1 );
}
inline D3DXMATRIX rotate_z_matrix(float angle)
{
return D3DXMATRIX( cos(angle), -sin(angle), 0, 0,
sin(angle), cos(angle), 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 );
}
inline D3DXMATRIX rotate_x_matrix(float angle, D3DXVECTOR3 center)
{
return shift_matrix(center)*rotate_x_matrix(angle)*shift_matrix(-center) ;
}
inline D3DXMATRIX rotate_matrix(D3DXVECTOR3 angles)
{
return rotate_z_matrix(angles.z)*rotate_y_matrix(angles.y)*rotate_x_matrix(angles.x);
}
inline D3DXMATRIX rotate_and_shift_matrix(D3DXVECTOR3 angles, D3DXVECTOR3 shift)
{
return shift_matrix(shift)*rotate_matrix(angles);
}