Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 1 | #pragma version(1) |
| 2 | #pragma stateVertex(PV) |
| 3 | #pragma stateFragment(PF) |
| 4 | #pragma stateFragmentStore(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 | |
| 22 | |
| 23 | float filter(float val, float target, float str) |
| 24 | { |
| 25 | float delta = (target - val); |
| 26 | return val + delta * str; |
| 27 | } |
| 28 | |
| 29 | int main(void* con, int ft, int launchID) |
| 30 | { |
| 31 | int rowCount; |
| 32 | int row; |
| 33 | int col; |
| 34 | int imageID; |
| 35 | int done = loadI32(0, STATE_DONE); |
| 36 | int selectedID = loadI32(0, STATE_SELECTION); |
| 37 | |
| 38 | float f = loadF(2, 0); |
| 39 | |
| 40 | pfClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 41 | if (done) { |
| 42 | if (f > 0.02f) { |
| 43 | //f = f - 0.02f; |
| 44 | //storeF(2, 0, f); |
| 45 | } |
| 46 | } else { |
| 47 | if (f < 0.8f) { |
| 48 | f = f + 0.02f; |
| 49 | storeF(2, 0, f); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | float touchCut = 1.f; |
| 54 | if (loadI32(0, STATE_TOUCH)) { |
| 55 | touchCut = 4.f; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | float targetZoom = ((float)loadI32(0, STATE_ZOOM)) / 1000.f; |
| 60 | float zoom = filter(loadF(2, SCRATCH_ZOOM), targetZoom, 0.15 * touchCut); |
| 61 | storeF(2, SCRATCH_ZOOM, zoom); |
| 62 | |
| 63 | float targetRot = loadI32(0, STATE_FIRST_VISIBLE) / 180.0f * 3.14f; |
| 64 | targetRot = targetRot * 0.80f - .12f; |
| 65 | float drawRot = filter(loadF(2, SCRATCH_ROT), targetRot, 0.1f * touchCut); |
| 66 | storeF(2, SCRATCH_ROT, drawRot); |
| 67 | |
| 68 | float diam = 8.f; |
| 69 | float scale = 1.0f / zoom; |
| 70 | |
| 71 | // Bug makes 1.0f alpha fail. |
| 72 | color(1.0f, 1.0f, 1.0f, 0.99f); |
| 73 | |
| 74 | float rot = drawRot * scale; |
| 75 | float rotStep = 16.0f / 180.0f * 3.14f * scale; |
| 76 | rowCount = 4; |
| 77 | int index = 0; |
| 78 | int iconCount = loadI32(0, STATE_COUNT); |
| 79 | while (iconCount) { |
| 80 | float tmpSin = sinf(rot); |
| 81 | float tmpCos = cosf(rot); |
| 82 | //debugF("rot", rot); |
| 83 | |
| 84 | float tx1 = tmpSin * diam - (tmpCos * scale * 0.9f); |
| 85 | float tx2 = tx1 + (tmpCos * scale * 1.8f); |
| 86 | float tz1 = tmpCos * diam + (tmpSin * scale * 0.9f); |
| 87 | float tz2 = tz1 - (tmpSin * scale * 1.8f); |
| 88 | |
| 89 | int y; |
| 90 | for (y = rowCount -1; (y >= 0) && iconCount; y--) { |
| 91 | float ty1 = ((y * 3.1f) - 5.f) * scale; |
| 92 | float ty2 = ty1 + scale * 1.8f; |
| 93 | bindTexture(NAMED_PF, 0, loadI32(1, index)); |
| 94 | drawQuad(tx1, ty1, tz1, |
| 95 | tx2, ty1, tz2, |
| 96 | tx2, ty2, tz2, |
| 97 | tx1, ty2, tz1); |
| 98 | |
| 99 | iconCount--; |
| 100 | index++; |
| 101 | } |
| 102 | rot = rot + rotStep; |
| 103 | } |
| 104 | |
| 105 | if ((zoom < 1.1f) && (zoom > 0.9f)) { |
| 106 | bindProgramVertex(NAMED_PVOrtho); |
| 107 | bindProgramFragment(NAMED_PFText); |
| 108 | bindProgramFragmentStore(NAMED_PFSText); |
| 109 | |
| 110 | rot = drawRot * scale; |
| 111 | index = 0; |
| 112 | iconCount = loadI32(0, STATE_COUNT); |
| 113 | while (iconCount) { |
| 114 | int y; |
| 115 | |
| 116 | float tx = 240.f + floorf(sinf(rot) * 430.f) - 64.f + 16.f; |
| 117 | |
| 118 | float alpha = 2.4f - (fabsf(tx - 240.f + 48.f) / 76.f); |
| 119 | if (alpha > 0.99f) { |
| 120 | alpha = 0.99f; |
| 121 | } |
| 122 | alpha = alpha * (1.f - (fabsf(zoom - 1.f) * 10.f)); |
| 123 | |
| 124 | tx = tx + 0.25f; |
| 125 | |
| 126 | for (y = rowCount -1; (y >= 0) && iconCount; y--) { |
| 127 | |
| 128 | if (alpha > 0) { |
| 129 | color(1.0f, 1.0f, 1.0f, alpha); |
| 130 | |
| 131 | float ty = 654.f - y * 150.f; |
| 132 | |
| 133 | ty = ty + 0.25f; |
| 134 | |
| 135 | bindTexture(NAMED_PFText, 0, loadI32(3, index)); |
| 136 | drawRect(tx, ty, tx + 128.f, ty + 64.f, 0.5f); |
| 137 | } |
| 138 | iconCount--; |
| 139 | index++; |
| 140 | } |
| 141 | rot = rot + rotStep; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | bindProgramVertex(NAMED_PV); |
| 146 | bindProgramFragment(NAMED_PF); |
| 147 | bindProgramFragmentStore(NAMED_PFS); |
| 148 | } |
| 149 | |
| 150 | // Draw the selected icon |
| 151 | color(1.0f, 1.0f, 1.0f, 0.9f); |
| 152 | rot = drawRot * scale; |
| 153 | index = 0; |
| 154 | iconCount = loadI32(0, STATE_COUNT); |
| 155 | while (iconCount) { |
| 156 | int y; |
| 157 | for (y = rowCount -1; (y >= 0) && iconCount; y--) { |
| 158 | if (index == selectedID) { |
| 159 | |
| 160 | float tmpSin = sinf(rot) * scale; |
| 161 | float tmpCos = cosf(rot) * scale; |
| 162 | float tx1 = tmpSin * diam * 0.9f - tmpCos * 2.f; |
| 163 | float tx2 = tx1 + (tmpCos * 4.f); |
| 164 | float tz1 = tmpCos * diam * 0.9f + tmpSin * 2.f; |
| 165 | float tz2 = tz1 - (tmpSin * 4.f); |
| 166 | |
| 167 | float ty1 = ((y * 3.1f) - 4.5f) * scale; |
| 168 | float ty2 = ty1 + scale * 4.f; |
| 169 | bindTexture(NAMED_PF, 0, loadI32(1, index)); |
| 170 | drawQuad(tx1, ty1, tz1, |
| 171 | tx2, ty1, tz2, |
| 172 | tx2, ty2, tz2, |
| 173 | tx1, ty2, tz1); |
| 174 | } |
| 175 | iconCount--; |
| 176 | index++; |
| 177 | } |
| 178 | rot = rot + rotStep; |
| 179 | } |
| 180 | |
| 181 | return 1; |
| 182 | } |
| 183 | |
| 184 | |