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