1 #pragma version(1)
2 #pragma stateVertex(PV)
3 #pragma stateFragment(PF)
4 #pragma stateStore(PFS)
5
6 // Scratch buffer layout
7 #define SCRATCH_FADE 0
8 #define SCRATCH_ZOOM 1
9 #define SCRATCH_ROT 2
10
11 //#define STATE_POS_X 0
12 #define STATE_DONE 1
13 //#define STATE_PRESSURE 2
14 #define STATE_ZOOM 3
15 //#define STATE_WARP 4
16 #define STATE_ORIENTATION 5
17 #define STATE_SELECTION 6
18 #define STATE_FIRST_VISIBLE 7
19 #define STATE_COUNT 8
20 #define STATE_TOUCH 9
21
filter(float val,float target,float str)22 float filter(float val, float target, float str)
23 {
24 float delta = (target - val);
25 return val + delta * str;
26 }
27
28
main(void * con,int ft,int launchID)29 int main(void* con, int ft, int launchID)
30 {
31 int rowCount;
32 int imageID;
33 int done = loadI32(0, STATE_DONE);
34 int selectedID = loadI32(0, STATE_SELECTION);
35 int iconCount = loadI32(0, STATE_COUNT);
36
37 float f = loadF(2, 0);
38
39 float iconSize = 1.f;
40 float iconSpacing = 0.2f;
41 float z = 4.f;
42
43 pfClearColor(0.0f, 0.0f, 0.0f, f);
44 if (done) {
45 } else {
46 if (f < 0.8f) {
47 f = f + 0.02f;
48 storeF(2, 0, f);
49 }
50 }
51
52 float touchCut = 1.f;
53 if (loadI32(0, STATE_TOUCH)) {
54 touchCut = 5.f;
55 }
56
57
58 float targetZoom = ((float)loadI32(0, STATE_ZOOM)) / 1000.f;
59 float zoom = filter(loadF(2, SCRATCH_ZOOM), targetZoom, 0.15 * touchCut);
60 storeF(2, SCRATCH_ZOOM, zoom);
61
62 float targetPos = loadI32(0, STATE_FIRST_VISIBLE) / (-20.0f);
63 float pos = filter(loadF(2, SCRATCH_ROT), targetPos, 0.1f * touchCut);
64 storeF(2, SCRATCH_ROT, pos);
65 pos = pos - 1.f;
66
67 color(1.0f, 1.0f, 1.0f, 1.0f);
68
69
70 // Draw flat icons first
71 int index = ((int)pos) * 4;
72 int row;
73 int col;
74 float xoffset = -0.3f;
75 float gridSize = iconSize * 4.f + iconSpacing * 3.f;
76 float yoffset = (pos - ((int)pos));
77 for (row = 0; row < 4; row ++) {
78 float ty1 = (gridSize / 2.f) - ((float)row - yoffset) * (iconSize + iconSpacing) - iconSize;
79 float ty2 = ty1 + iconSize;
80
81 for (col = 0; (col < 4) && (index < iconCount); col ++) {
82 if (index >= 0) {
83 bindTexture(NAMED_PF, 0, loadI32(1, index));
84 float fcol = col;
85 float tx1 = xoffset + (-gridSize / 2.f) + (fcol * (iconSize + iconSpacing));
86 float tx2 = tx1 + iconSize;
87
88 drawQuad(tx1, ty1, z,
89 tx2, ty1, z,
90 tx2, ty2, z,
91 tx1, ty2, z);
92 }
93 index++;
94 }
95 }
96
97 // bottom roller
98 {
99 float roll = (1.f - yoffset) * 0.5f * 3.14f;
100 float tmpSin = sinf(roll);
101 float tmpCos = cosf(roll);
102
103 for (col = 0; (col < 4) && (index < iconCount) && (index >= 0); col ++) {
104 float ty2 = (gridSize / 2.f) - ((float)row - yoffset) * (iconSize + iconSpacing);
105 float ty1 = ty2 - tmpCos * iconSize;
106
107 float tz1 = z + tmpSin * iconSize;
108 float tz2 = z;
109
110 float tx1 = xoffset + (-gridSize / 2.f) + ((float)col * (iconSize + iconSpacing));
111 float tx2 = tx1 + iconSize;
112
113 bindTexture(NAMED_PF, 0, loadI32(1, index));
114 drawQuad(tx1, ty1, tz1,
115 tx2, ty1, tz1,
116 tx2, ty2, tz2,
117 tx1, ty2, tz2);
118 index++;
119 }
120 }
121
122 // Top roller
123 {
124 index = (((int)pos) * 4) - 4;
125 float roll = yoffset * 0.5f * 3.14f;
126 float tmpSin = sinf(roll);
127 float tmpCos = cosf(roll);
128
129 for (col = 0; (col < 4) && (index < iconCount) && (index >= 0); col ++) {
130 float ty1 = (gridSize / 2.f) - ((float)-1.f - yoffset) * (iconSize + iconSpacing) - iconSize;
131 float ty2 = ty1 + tmpCos * iconSize;
132
133 float tz1 = z;
134 float tz2 = z + tmpSin * iconSize;
135
136 float tx1 = xoffset + (-gridSize / 2.f) + ((float)col * (iconSize + iconSpacing));
137 float tx2 = tx1 + iconSize;
138
139 bindTexture(NAMED_PF, 0, loadI32(1, index));
140 drawQuad(tx1, ty1, tz1,
141 tx2, ty1, tz1,
142 tx2, ty2, tz2,
143 tx1, ty2, tz2);
144 index++;
145 }
146 }
147
148
149
150
151 return 1;
152 }
153
154
155
156