-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtransform.fx
75 lines (67 loc) · 2.25 KB
/
transform.fx
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
//-------------------------------------------
// Returns a translation matrix
//-------------------------------------------
float3x3 makeTranslationMatrix ( float2 pos )
{
return float3x3(
1, 0, 0,
0, 1, 0,
pos.x, pos.y, 1
);
}
//-------------------------------------------
// Returns a rotation matrix
//-------------------------------------------
float3x3 makeRotationMatrix ( float angle )
{
float s = sin(angle);
float c = cos(angle);
return float3x3(
c, s, 0,
-s, c, 0,
0, 0, 1
);
}
//-------------------------------------------
// Returns a scale matrix
//-------------------------------------------
float3x3 makeScaleMatrix ( float2 scale )
{
return float3x3(
scale.x, 0, 0,
0, scale.y, 0,
0, 0, 1
);
}
//-------------------------------------------
// Returns a combined matrix of doom
//-------------------------------------------
float3x3 makeTextureTransform ( float2 prePosition, float2 scale, float2 scaleCenter, float rotAngle, float2 rotCenter, float2 postPosition )
{
float3x3 matPrePosition = makeTranslationMatrix( prePosition );
float3x3 matToScaleCen = makeTranslationMatrix( -scaleCenter );
float3x3 matScale = makeScaleMatrix( scale );
float3x3 matFromScaleCen = makeTranslationMatrix( scaleCenter );
float3x3 matToRotCen = makeTranslationMatrix( -rotCenter );
float3x3 matRot = makeRotationMatrix( rotAngle );
float3x3 matFromRotCen = makeTranslationMatrix( rotCenter );
float3x3 matPostPosition = makeTranslationMatrix( postPosition );
float3x3 result =
mul(
mul(
mul(
mul(
mul(
mul(
mul(
matPrePosition
,matToScaleCen)
,matScale)
,matFromScaleCen)
,matToRotCen)
,matRot)
,matFromRotCen)
,matPostPosition)
;
return result;
}