Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 1 | #pragma version(1) |
| 2 | #pragma stateVertex(PV) |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 3 | #pragma stateFragment(PFTexLinear) |
| 4 | #pragma stateStore(PSIcons) |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 5 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 6 | #define PI 3.14159f |
| 7 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 8 | |
| 9 | // Attraction to center values from page edge to page center. |
| 10 | float g_AttractionTable[9]; |
| 11 | float g_FrictionTable[9]; |
| 12 | float g_PhysicsTableSize; |
| 13 | |
| 14 | float g_PosPage; |
| 15 | float g_PosVelocity; |
| 16 | float g_LastPositionX; |
| 17 | int g_LastTouchDown; |
| 18 | float g_DT; |
| 19 | int g_LastTime; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 20 | int g_PageCount; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 21 | float g_Zoom; |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 22 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 23 | // Drawing constants, should be parameters ====== |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 24 | #define VIEW_ANGLE 1.28700222f |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 25 | |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame^] | 26 | float g_OldPosPage; |
| 27 | float g_OldPosVelocity; |
| 28 | float g_OldZoom; |
| 29 | |
| 30 | void updateReadback() { |
| 31 | if ((g_OldPosPage != g_PosPage) || |
| 32 | (g_OldPosVelocity != g_PosVelocity) || |
| 33 | (g_OldZoom != g_Zoom)) { |
| 34 | |
| 35 | g_OldPosPage = g_PosPage; |
| 36 | g_OldPosVelocity = g_PosVelocity; |
| 37 | g_OldZoom = g_Zoom; |
| 38 | |
| 39 | int i[3]; |
| 40 | i[0] = g_PosPage * (1 << 16); |
| 41 | i[1] = g_PosVelocity * (1 << 16); |
| 42 | i[2] = g_OldZoom * (1 << 16); |
| 43 | sendToClient(&i[0], 1, 12, 1); |
| 44 | } |
| 45 | } |
| 46 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 47 | void init() { |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 48 | g_AttractionTable[0] = 6.5f; |
| 49 | g_AttractionTable[1] = 6.5f; |
| 50 | g_AttractionTable[2] = 7.0f; |
| 51 | g_AttractionTable[3] = 6.0f; |
| 52 | g_AttractionTable[4] = -6.0f; |
| 53 | g_AttractionTable[5] = -7.0f; |
| 54 | g_AttractionTable[6] = -6.5f; |
| 55 | g_AttractionTable[7] = -6.5f; |
| 56 | g_AttractionTable[8] = -6.5f; // dup 7 to avoid a clamp later |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 57 | g_FrictionTable[0] = 3.5f; |
| 58 | g_FrictionTable[1] = 3.6f; |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 59 | g_FrictionTable[2] = 4.0f; |
| 60 | g_FrictionTable[3] = 5.0f; |
| 61 | g_FrictionTable[4] = 5.0f; |
| 62 | g_FrictionTable[5] = 4.0f; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 63 | g_FrictionTable[6] = 3.6f; |
| 64 | g_FrictionTable[7] = 3.5f; |
| 65 | g_FrictionTable[8] = 3.5f; // dup 7 to avoid a clamp later |
| 66 | g_PhysicsTableSize = 7; |
| 67 | |
| 68 | g_PosVelocity = 0; |
| 69 | g_PosPage = 0; |
| 70 | g_LastTouchDown = 0; |
| 71 | g_LastPositionX = 0; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 72 | g_Zoom = 0; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void move() { |
| 76 | if (g_LastTouchDown) { |
| 77 | float dx = -(state->newPositionX - g_LastPositionX); |
| 78 | g_PosVelocity = 0; |
| 79 | g_PosPage += dx; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 80 | |
| 81 | float pmin = -0.25f; |
| 82 | float pmax = (g_PageCount - 1) + 0.25f; |
| 83 | g_PosPage = clampf(g_PosPage, pmin, pmax); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 84 | } |
| 85 | g_LastTouchDown = state->newTouchDown; |
| 86 | g_LastPositionX = state->newPositionX; |
Jason Sams | 28870b7 | 2009-09-30 17:32:05 -0700 | [diff] [blame] | 87 | //debugF("Move P", g_PosPage); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void fling() { |
| 91 | g_LastTouchDown = 0; |
| 92 | g_PosVelocity = -state->flingVelocityX; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 93 | float av = fabsf(g_PosVelocity); |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 94 | float minVel = 3.5f; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 95 | |
| 96 | minVel *= 1.f - (fabsf(fracf(g_PosPage + 0.5f) - 0.5f) * 0.45f); |
| 97 | |
| 98 | if (av < minVel && av > 0.2f) { |
| 99 | if (g_PosVelocity > 0) { |
| 100 | g_PosVelocity = minVel; |
| 101 | } else { |
| 102 | g_PosVelocity = -minVel; |
| 103 | } |
| 104 | } |
| 105 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 106 | if (g_PosPage <= 0) { |
| 107 | g_PosVelocity = maxf(0, g_PosVelocity); |
| 108 | } |
| 109 | if (g_PosPage > (g_PageCount - 1)) { |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 110 | g_PosVelocity = minf(0, g_PosVelocity); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 111 | } |
Jason Sams | 28870b7 | 2009-09-30 17:32:05 -0700 | [diff] [blame] | 112 | //debugF("fling v", g_PosVelocity); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 115 | void touchUp() { |
| 116 | g_LastTouchDown = 0; |
| 117 | } |
| 118 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 119 | int |
| 120 | count_pages(int iconCount) |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 121 | { |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 122 | int iconsPerPage = COLUMNS_PER_PAGE * ROWS_PER_PAGE; |
| 123 | int pages = iconCount / iconsPerPage; |
| 124 | if (pages*iconsPerPage != iconCount) { |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 125 | pages++; |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 126 | } |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 127 | return pages; |
| 128 | } |
| 129 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 130 | float |
| 131 | modf(float x, float y) |
| 132 | { |
| 133 | return x-(y*floorf(x/y)); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 136 | void updatePos() { |
| 137 | if (g_LastTouchDown) { |
| 138 | return; |
| 139 | } |
| 140 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 141 | float tablePosNorm = fracf(g_PosPage + 0.5f); |
| 142 | float tablePosF = tablePosNorm * g_PhysicsTableSize; |
| 143 | int tablePosI = tablePosF; |
| 144 | float tablePosFrac = tablePosF - tablePosI; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 145 | float accel = lerpf(g_AttractionTable[tablePosI], |
| 146 | g_AttractionTable[tablePosI + 1], |
| 147 | tablePosFrac) * g_DT; |
| 148 | float friction = lerpf(g_FrictionTable[tablePosI], |
| 149 | g_FrictionTable[tablePosI + 1], |
| 150 | tablePosFrac) * g_DT; |
| 151 | //debugF(" accel", accel); |
| 152 | //debugF(" friction", friction); |
| 153 | |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 154 | // If our velocity is low OR acceleration is opposing it, apply it. |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 155 | if (fabsf(g_PosVelocity) < 1.0f || (g_PosVelocity * accel) < 0) { |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 156 | g_PosVelocity += accel; |
| 157 | } |
| 158 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 159 | if ((friction > fabsf(g_PosVelocity)) && (friction > fabsf(accel))) { |
| 160 | // Special get back to center and overcome friction physics. |
| 161 | float t = tablePosNorm - 0.5f; |
| 162 | if (fabsf(t) < (friction * g_DT)) { |
| 163 | // really close, just snap |
| 164 | g_PosPage = roundf(g_PosPage); |
| 165 | g_PosVelocity = 0; |
| 166 | } else { |
| 167 | if (t > 0) { |
| 168 | g_PosVelocity = -friction; |
| 169 | } else { |
| 170 | g_PosVelocity = friction; |
| 171 | } |
| 172 | } |
| 173 | } else { |
| 174 | // Normal physics |
| 175 | if (g_PosVelocity > 0) { |
| 176 | g_PosVelocity -= friction; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 177 | g_PosVelocity = maxf(g_PosVelocity, 0); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 178 | } else { |
| 179 | g_PosVelocity += friction; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 180 | g_PosVelocity = minf(g_PosVelocity, 0); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | g_PosPage += g_PosVelocity * g_DT; |
| 184 | |
| 185 | // Check for out of boundry conditions. |
| 186 | if (g_PosPage < 0 && g_PosVelocity < 0) { |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 187 | float damp = 1.0 + (g_PosPage * 4); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 188 | damp = clampf(damp, 0.f, 0.9f); |
| 189 | g_PosVelocity *= damp; |
| 190 | } |
| 191 | if (g_PosPage > (g_PageCount-1) && g_PosVelocity > 0) { |
Jason Sams | 0aa7166 | 2009-10-02 18:43:18 -0700 | [diff] [blame] | 192 | float damp = 1.0 - ((g_PosPage - g_PageCount + 1) * 4); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 193 | damp = clampf(damp, 0.f, 0.9f); |
| 194 | g_PosVelocity *= damp; |
| 195 | } |
| 196 | } |
| 197 | |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 198 | float |
| 199 | far_size(float sizeAt0) |
| 200 | { |
| 201 | return sizeAt0 * (RADIUS+2) / 2; // -2 is the camera z=(z-camZ)/z |
| 202 | } |
| 203 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 204 | void |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 205 | draw_page(int icon, int lastIcon, float centerAngle, float scale) |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 206 | { |
| 207 | int row; |
| 208 | int col; |
| 209 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 210 | //debugF("center angle", centerAngle); |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 211 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 212 | float iconTextureWidth = ICON_WIDTH_PX / (float)ICON_TEXTURE_WIDTH_PX; |
| 213 | float iconTextureHeight = ICON_HEIGHT_PX / (float)ICON_TEXTURE_HEIGHT_PX; |
| 214 | |
| 215 | float iconWidthAngle = VIEW_ANGLE * ICON_WIDTH_PX / SCREEN_WIDTH_PX; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 216 | float columnGutterAngle = iconWidthAngle * 0.9f; |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 217 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 218 | float farIconSize = FAR_ICON_SIZE; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 219 | float iconGutterHeight = farIconSize * 1.3f; |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 220 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 221 | float farIconTextureSize = far_size(2 * ICON_TEXTURE_WIDTH_PX / (float)SCREEN_WIDTH_PX); |
| 222 | |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 223 | float normalizedLabelWidth = 2 * params->bubbleWidth / (float)SCREEN_WIDTH_PX; |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 224 | float farLabelHeight = far_size(params->bubbleHeight * (normalizedLabelWidth / params->bubbleWidth)); |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 225 | |
| 226 | for (row=0; row<ROWS_PER_PAGE && icon<=lastIcon; row++) { |
| 227 | float angle = centerAngle; |
| 228 | angle -= (columnGutterAngle + iconWidthAngle) * 1.5f; |
| 229 | |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 230 | float iconTop = (farIconSize + iconGutterHeight) * (1.85f + ICON_TOP_OFFSET) |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 231 | - row * (farIconSize + iconGutterHeight); |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 232 | float iconBottom = iconTop - farIconSize; |
| 233 | |
Jason Sams | 28870b7 | 2009-09-30 17:32:05 -0700 | [diff] [blame] | 234 | float labelY = iconBottom - farLabelHeight; |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 235 | float iconTextureTop = iconTop + (0.5f * (farIconTextureSize - farIconSize)); |
| 236 | float iconTextureBottom = iconTextureTop - farIconTextureSize; |
| 237 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 238 | for (col=0; col<COLUMNS_PER_PAGE && icon<=lastIcon; col++) { |
| 239 | // icon |
| 240 | float sine = sinf(angle); |
| 241 | float cosine = cosf(angle); |
| 242 | |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 243 | float centerX = sine * RADIUS; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 244 | float centerZ = cosine * RADIUS / scale; |
| 245 | |
| 246 | if (scale > 1.f) { |
| 247 | centerX *= scale; |
| 248 | } |
Joe Onorato | 0d1c563 | 2009-08-28 15:57:18 -0700 | [diff] [blame] | 249 | |
Jason Sams | 28870b7 | 2009-09-30 17:32:05 -0700 | [diff] [blame] | 250 | float iconLeftX = centerX - (/*cosine * */ farIconTextureSize * .5); |
| 251 | float iconRightX = centerX + (/*cosine * */ farIconTextureSize * .5); |
| 252 | float iconLeftZ = centerZ;// + (sine * farIconTextureSize * .5); |
| 253 | float iconRightZ = centerZ;// - (sine * farIconTextureSize * .5); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 254 | |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 255 | color(1.0f, 1.0f, 1.0f, 0.99f); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 256 | if (state->selectedIconIndex == icon) { |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 257 | bindTexture(NAMED_PFTexLinear, 0, state->selectedIconTexture); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 258 | drawQuadTexCoords( |
| 259 | iconLeftX, iconTextureTop, iconLeftZ, 0.0f, 0.0f, |
| 260 | iconRightX, iconTextureTop, iconRightZ, 1.0f, 0.0f, |
| 261 | iconRightX, iconTextureBottom, iconRightZ, 1.0f, 1.0f, |
| 262 | iconLeftX, iconTextureBottom, iconLeftZ, 0.0f, 1.0f); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 263 | } else { |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 264 | bindTexture(NAMED_PFTexLinear, 0, loadI32(ALLOC_ICON_IDS, icon)); |
Joe Onorato | 1291a8c | 2009-09-15 15:07:25 -0400 | [diff] [blame] | 265 | drawQuadTexCoords( |
| 266 | iconLeftX, iconTextureTop, iconLeftZ, 0.0f, 0.0f, |
| 267 | iconRightX, iconTextureTop, iconRightZ, 1.0f, 0.0f, |
| 268 | iconRightX, iconTextureBottom, iconRightZ, 1.0f, 1.0f, |
| 269 | iconLeftX, iconTextureBottom, iconLeftZ, 0.0f, 1.0f); |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 270 | } |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 271 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 272 | // label |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 273 | if (scale < 1.2f) { |
Jason Sams | 28870b7 | 2009-09-30 17:32:05 -0700 | [diff] [blame] | 274 | float a = (1.2f - maxf(scale, 1.0f)) * 5; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 275 | color(1.0f, 1.0f, 1.0f, a); |
Jason Sams | cd689e1 | 2009-09-29 15:28:22 -0700 | [diff] [blame] | 276 | bindTexture(NAMED_PFTexLinear, 0, loadI32(ALLOC_LABEL_IDS, icon)); |
Jason Sams | 28870b7 | 2009-09-30 17:32:05 -0700 | [diff] [blame] | 277 | drawSprite(centerX, labelY, centerZ, |
| 278 | params->bubbleBitmapWidth, params->bubbleBitmapHeight); |
Joe Onorato | 85a02a8 | 2009-09-08 12:34:22 -0700 | [diff] [blame] | 279 | } |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 280 | |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 281 | angle += columnGutterAngle + iconWidthAngle; |
| 282 | icon++; |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 287 | void |
| 288 | draw_home_button() |
| 289 | { |
| 290 | color(1.0f, 1.0f, 1.0f, 1.0f); |
| 291 | bindTexture(NAMED_PFTexLinear, 0, params->homeButtonId); |
| 292 | |
| 293 | float scale = 2.0f / SCREEN_WIDTH_PX; |
| 294 | |
| 295 | float x = 0.0f; |
| 296 | |
| 297 | float y = -(SCREEN_HEIGHT_PX / (float)SCREEN_WIDTH_PX); |
| 298 | y += g_Zoom * (scale * params->homeButtonTextureHeight / 2); |
| 299 | |
| 300 | float z = 0.0f; |
| 301 | drawSprite(x, y, z, params->homeButtonTextureWidth, params->homeButtonTextureHeight); |
| 302 | } |
| 303 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 304 | int |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 305 | main(int launchID) |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 306 | { |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 307 | // Compute dt in seconds. |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 308 | int newTime = uptimeMillis(); |
| 309 | g_DT = (newTime - g_LastTime) / 1000.f; |
| 310 | g_LastTime = newTime; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 311 | |
Joe Onorato | 2664634 | 2009-09-23 15:15:48 -0700 | [diff] [blame] | 312 | //debugF("zoom", g_Zoom); |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame^] | 313 | if (g_Zoom != state->zoomTarget) { |
| 314 | float dz = (state->zoomTarget - g_Zoom) * g_DT * 5; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 315 | if (dz && (fabsf(dz) < 0.03f)) { |
| 316 | if (dz > 0) { |
| 317 | dz = 0.03f; |
| 318 | } else { |
| 319 | dz = -0.03f; |
| 320 | } |
| 321 | } |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame^] | 322 | if (fabsf(g_Zoom - state->zoomTarget) < fabsf(dz)) { |
| 323 | g_Zoom = state->zoomTarget; |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 324 | } else { |
| 325 | g_Zoom += dz; |
| 326 | } |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame^] | 327 | updateReadback(); |
Joe Onorato | 006b25f | 2009-09-03 11:38:43 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 330 | // Set clear value to dim the background based on the zoom position. |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame^] | 331 | if ((g_Zoom < 0.001f) && (state->zoomTarget < 0.001f)) { |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 332 | pfClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
Joe Onorato | 360d035 | 2009-09-28 14:37:53 -0400 | [diff] [blame] | 333 | // When we're zoomed out and not tracking motion events, reset the pos to 0. |
| 334 | if (!g_LastTouchDown) { |
| 335 | g_PosPage = 0; |
| 336 | } |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame^] | 337 | return 1;//0; |
Jason Sams | 28870b7 | 2009-09-30 17:32:05 -0700 | [diff] [blame] | 338 | } else if (g_Zoom < 0.85f) { |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 339 | pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 340 | } else { |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 341 | pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom); |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 344 | // icons & labels |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 345 | int iconCount = state->iconCount; |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 346 | g_PageCount = count_pages(iconCount); |
Joe Onorato | 43e7bcf | 2009-08-08 18:53:53 -0700 | [diff] [blame] | 347 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 348 | updatePos(0.1f); |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame^] | 349 | updateReadback(); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 350 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 351 | //debugF(" draw g_PosPage", g_PosPage); |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 352 | |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 353 | // Draw the icons ======================================== |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 354 | |
| 355 | // Bug makes 1.0f alpha fail. |
| 356 | color(1.0f, 1.0f, 1.0f, 0.99f); |
| 357 | |
| 358 | int lastIcon = iconCount-1; |
| 359 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 360 | int page = g_PosPage; |
| 361 | float currentPagePosition = g_PosPage - page; |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 362 | |
Joe Onorato | d769a63 | 2009-08-11 17:09:02 -0700 | [diff] [blame] | 363 | int iconsPerPage = COLUMNS_PER_PAGE * ROWS_PER_PAGE; |
Joe Onorato | efabe00 | 2009-08-28 09:38:18 -0700 | [diff] [blame] | 364 | int icon = clamp(iconsPerPage * page, 0, lastIcon); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 365 | |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 366 | float scale = (1 / g_Zoom); |
Jason Sams | 78aebd8 | 2009-09-15 13:06:59 -0700 | [diff] [blame] | 367 | |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 368 | float pageAngle = VIEW_ANGLE * 1.2f; |
| 369 | draw_page(icon, lastIcon, -pageAngle*currentPagePosition, scale); |
| 370 | draw_page(icon+iconsPerPage, lastIcon, (-pageAngle*currentPagePosition)+pageAngle, scale); |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 371 | |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 372 | // Draw the border lines for debugging ======================================== |
| 373 | /* |
| 374 | bindProgramVertex(NAMED_PVOrtho); |
| 375 | bindProgramFragment(NAMED_PFOrtho); |
| 376 | bindProgramFragmentStore(NAMED_PFSText); |
| 377 | |
| 378 | color(1.0f, 1.0f, 0.0f, 0.99f); |
| 379 | int i; |
| 380 | for (i=0; i<ROWS_PER_PAGE+1; i++) { |
| 381 | int y = loadI32(ALLOC_Y_BORDERS, i); |
| 382 | drawRect(0, y, SCREEN_WIDTH_PX, y+1, 0.0f); |
| 383 | } |
| 384 | for (i=0; i<COLUMNS_PER_PAGE+1; i++) { |
| 385 | int x = loadI32(ALLOC_X_BORDERS, i); |
| 386 | drawRect(x, 0, x+1, SCREEN_HEIGHT_PX, 0.0f); |
| 387 | } |
| 388 | */ |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 389 | |
Joe Onorato | bcbeab8 | 2009-10-01 21:45:43 -0700 | [diff] [blame] | 390 | // Draw the home button ======================================== |
| 391 | draw_home_button(); |
| 392 | |
Joe Onorato | 6665c0f | 2009-09-02 15:27:24 -0700 | [diff] [blame] | 393 | /* |
Joe Onorato | 56848b0 | 2009-09-25 13:59:59 -0700 | [diff] [blame] | 394 | bindTexture(NAMED_PFOrtho, 0, loadI32(ALLOC_PARAMS, PARAM_SCROLL_HANDLE_ID)); |
Joe Onorato | c567acb | 2009-08-31 14:34:43 -0700 | [diff] [blame] | 395 | float handleLeft = 40 + (320 * (scrollXPx/(float)(maxScrollXPx))); |
| 396 | float handleTop = 680; |
| 397 | float handleWidth = loadI32(ALLOC_PARAMS, PARAM_SCROLL_HANDLE_TEX_WIDTH); |
| 398 | float handleHeight = loadI32(ALLOC_PARAMS, PARAM_SCROLL_HANDLE_TEX_HEIGHT); |
| 399 | drawRect(handleLeft, handleTop, handleLeft+handleWidth, handleTop+handleHeight, 0.0f); |
| 400 | */ |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 401 | |
Jason Sams | 86c87ed | 2009-09-18 13:55:55 -0700 | [diff] [blame] | 402 | // Bug workaround where the last frame is not always displayed |
Jason Sams | fd22dac | 2009-09-20 17:24:16 -0700 | [diff] [blame] | 403 | // So we keep rendering until the bug is fixed. |
Jason Sams | 12c14a8 | 2009-10-06 14:33:15 -0700 | [diff] [blame^] | 404 | return 1;//(g_PosVelocity != 0) || fracf(g_PosPage) || (g_Zoom != state->zoomTarget); |
Joe Onorato | 9383905 | 2009-08-06 20:34:32 -0700 | [diff] [blame] | 405 | } |
| 406 | |