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