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