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