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