Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 1 | #pragma version(1) |
| 2 | #pragma stateVertex(PV) |
| 3 | #pragma stateFragment(PFTexLinear) |
| 4 | #pragma stateStore(PSIcons) |
| 5 | |
| 6 | #define PI 3.14159f |
| 7 | |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 8 | int g_SpecialHWWar; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 9 | |
| 10 | // Attraction to center values from page edge to page center. |
| 11 | float g_AttractionTable[9]; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 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; |
| 20 | int g_PosMax; |
| 21 | float g_Zoom; |
| 22 | float g_OldPosPage; |
| 23 | float g_OldPosVelocity; |
| 24 | float g_OldZoom; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 25 | float g_MoveToTotalTime; |
| 26 | float g_MoveToTime; |
| 27 | float g_MoveToOldPos; |
| 28 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 29 | |
| 30 | // Drawing constants, should be parameters ====== |
| 31 | #define VIEW_ANGLE 1.28700222f |
| 32 | |
| 33 | int g_DrawLastFrame; |
| 34 | int lastFrame(int draw) { |
| 35 | // We draw one extra frame to work around the last frame post bug. |
| 36 | // We also need to track if we drew the last frame to deal with large DT |
| 37 | // in the physics. |
| 38 | int ret = g_DrawLastFrame | draw; |
| 39 | g_DrawLastFrame = draw; |
| 40 | return ret; // should return draw instead. |
| 41 | } |
| 42 | |
| 43 | void updateReadback() { |
| 44 | if ((g_OldPosPage != g_PosPage) || |
| 45 | (g_OldPosVelocity != g_PosVelocity) || |
| 46 | (g_OldZoom != g_Zoom)) { |
| 47 | |
| 48 | g_OldPosPage = g_PosPage; |
| 49 | g_OldPosVelocity = g_PosVelocity; |
| 50 | g_OldZoom = g_Zoom; |
| 51 | |
| 52 | int i[3]; |
| 53 | i[0] = g_PosPage * (1 << 16); |
| 54 | i[1] = g_PosVelocity * (1 << 16); |
| 55 | i[2] = g_OldZoom * (1 << 16); |
| 56 | sendToClient(&i[0], 1, 12, 1); |
| 57 | } |
| 58 | } |
| 59 | |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 60 | void setColor(float r, float g, float b, float a) { |
| 61 | if (g_SpecialHWWar) { |
| 62 | color(0, 0, 0, 0.001f); |
| 63 | } else { |
| 64 | color(r, g, b, a); |
| 65 | } |
| 66 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 67 | |
| 68 | void init() { |
| 69 | g_AttractionTable[0] = 6.5f; |
| 70 | g_AttractionTable[1] = 6.5f; |
| 71 | g_AttractionTable[2] = 7.0f; |
| 72 | g_AttractionTable[3] = 6.0f; |
| 73 | g_AttractionTable[4] = -6.0f; |
| 74 | g_AttractionTable[5] = -7.0f; |
| 75 | g_AttractionTable[6] = -6.5f; |
| 76 | g_AttractionTable[7] = -6.5f; |
| 77 | g_AttractionTable[8] = -6.5f; // dup 7 to avoid a clamp later |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 78 | g_PhysicsTableSize = 7; |
| 79 | |
| 80 | g_PosVelocity = 0; |
| 81 | g_PosPage = 0; |
| 82 | g_LastTouchDown = 0; |
| 83 | g_LastPositionX = 0; |
| 84 | g_Zoom = 0; |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 85 | g_SpecialHWWar = 1; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 86 | g_MoveToTime = 0; |
| 87 | g_MoveToOldPos = 0; |
| 88 | g_MoveToTotalTime = 0.5f; |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void resetHWWar() { |
| 92 | g_SpecialHWWar = 1; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void move() { |
| 96 | if (g_LastTouchDown) { |
| 97 | float dx = -(state->newPositionX - g_LastPositionX); |
| 98 | g_PosVelocity = 0; |
| 99 | g_PosPage += dx * 4; |
| 100 | |
| 101 | float pmin = -0.25f; |
| 102 | float pmax = g_PosMax + 0.25f; |
| 103 | g_PosPage = clampf(g_PosPage, pmin, pmax); |
| 104 | } |
| 105 | g_LastTouchDown = state->newTouchDown; |
| 106 | g_LastPositionX = state->newPositionX; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 107 | g_MoveToTime = 0; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 108 | //debugF("Move P", g_PosPage); |
| 109 | } |
| 110 | |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 111 | void moveTo() { |
| 112 | g_MoveToTime = g_MoveToTotalTime; |
| 113 | g_PosVelocity = 0; |
| 114 | g_MoveToOldPos = g_PosPage; |
| 115 | } |
| 116 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 117 | void fling() { |
| 118 | g_LastTouchDown = 0; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 119 | g_PosVelocity = -state->flingVelocity * 4; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 120 | float av = fabsf(g_PosVelocity); |
| 121 | float minVel = 3.5f; |
| 122 | |
| 123 | minVel *= 1.f - (fabsf(fracf(g_PosPage + 0.5f) - 0.5f) * 0.45f); |
| 124 | |
| 125 | if (av < minVel && av > 0.2f) { |
| 126 | if (g_PosVelocity > 0) { |
| 127 | g_PosVelocity = minVel; |
| 128 | } else { |
| 129 | g_PosVelocity = -minVel; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if (g_PosPage <= 0) { |
| 134 | g_PosVelocity = maxf(0, g_PosVelocity); |
| 135 | } |
| 136 | if (g_PosPage > g_PosMax) { |
| 137 | g_PosVelocity = minf(0, g_PosVelocity); |
| 138 | } |
| 139 | } |
| 140 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 141 | float |
| 142 | modf(float x, float y) |
| 143 | { |
| 144 | return x-(y*floorf(x/y)); |
| 145 | } |
| 146 | |
| 147 | void updatePos() { |
| 148 | if (g_LastTouchDown) { |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | int outOfRange = 0; |
| 153 | float tablePosNorm = fracf(g_PosPage + 0.5f); |
| 154 | float tablePosF = tablePosNorm * g_PhysicsTableSize; |
| 155 | int tablePosI = tablePosF; |
| 156 | float tablePosFrac = tablePosF - tablePosI; |
| 157 | float accel = lerpf(g_AttractionTable[tablePosI], |
| 158 | g_AttractionTable[tablePosI + 1], |
| 159 | tablePosFrac) * g_DT; |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 160 | float friction = 4.f * g_DT; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 161 | |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 162 | if (g_MoveToTime) { |
| 163 | float a = 2.f * (state->targetPos - g_MoveToOldPos) / |
| 164 | (g_MoveToTotalTime * g_MoveToTotalTime); |
| 165 | if (g_MoveToTime > (g_MoveToTotalTime * 0.5f)) { |
| 166 | // slowing |
| 167 | g_PosPage = state->targetPos - 0.5f * a * (g_MoveToTime * g_MoveToTime); |
| 168 | } else { |
| 169 | // accelerating. |
| 170 | float t = g_MoveToTotalTime - g_MoveToTime; |
| 171 | g_PosPage = g_MoveToOldPos + 0.5f * a * (t * t); |
| 172 | } |
| 173 | g_MoveToTime -= g_DT; |
| 174 | if (g_MoveToTime <= 0) { |
| 175 | g_MoveToTime = 0; |
| 176 | g_PosPage = state->targetPos; |
| 177 | } |
| 178 | return; |
| 179 | } |
| 180 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 181 | if (g_PosPage < -0.5f) { |
| 182 | accel = g_AttractionTable[0] * g_DT; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 183 | outOfRange = 1; |
| 184 | } |
| 185 | if ((g_PosPage - g_PosMax) > 0.5f) { |
| 186 | accel = g_AttractionTable[(int)g_PhysicsTableSize] * g_DT; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 187 | outOfRange = 1; |
| 188 | } |
| 189 | |
| 190 | // If our velocity is low OR acceleration is opposing it, apply it. |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 191 | if (fabsf(g_PosVelocity) < 1.0f || (g_PosVelocity * accel) < 0 || outOfRange) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 192 | g_PosVelocity += accel; |
| 193 | } |
| 194 | |
| 195 | if ((friction > fabsf(g_PosVelocity)) && |
| 196 | (friction > fabsf(accel)) && |
| 197 | !outOfRange) { |
| 198 | // Special get back to center and overcome friction physics. |
| 199 | float t = tablePosNorm - 0.5f; |
| 200 | if (fabsf(t) < (friction * g_DT)) { |
| 201 | // really close, just snap |
| 202 | g_PosPage = roundf(g_PosPage); |
| 203 | g_PosVelocity = 0; |
| 204 | } else { |
| 205 | if (t > 0) { |
| 206 | g_PosVelocity = -friction; |
| 207 | } else { |
| 208 | g_PosVelocity = friction; |
| 209 | } |
| 210 | } |
| 211 | } else { |
| 212 | // Normal physics |
| 213 | if (g_PosVelocity > 0) { |
| 214 | g_PosVelocity -= friction; |
| 215 | g_PosVelocity = maxf(g_PosVelocity, 0); |
| 216 | } else { |
| 217 | g_PosVelocity += friction; |
| 218 | g_PosVelocity = minf(g_PosVelocity, 0); |
| 219 | } |
| 220 | } |
| 221 | g_PosPage += g_PosVelocity * g_DT; |
| 222 | |
| 223 | // Check for out of boundry conditions. |
| 224 | if (g_PosPage < 0 && g_PosVelocity < 0) { |
| 225 | g_PosPage = maxf(g_PosPage, -0.49); |
| 226 | float damp = 1.0 + (g_PosPage * 4); |
| 227 | damp = clampf(damp, 0.f, 0.9f); |
| 228 | g_PosVelocity *= damp; |
| 229 | } |
| 230 | if (g_PosPage > g_PosMax && g_PosVelocity > 0) { |
| 231 | g_PosPage = minf(g_PosPage, g_PosMax + 0.49); |
| 232 | float damp = 1.0 - ((g_PosPage - g_PosMax) * 4); |
| 233 | damp = clampf(damp, 0.f, 0.9f); |
| 234 | g_PosVelocity *= damp; |
| 235 | } |
| 236 | } |
| 237 | |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 238 | int positionStrip(float row, float column, int isTop, float p) |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 239 | { |
| 240 | float mat1[16]; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 241 | float x = 0.5f * (column - 1.5f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 242 | float scale = 72.f * 3 / getWidth(); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 243 | |
| 244 | if (isTop) { |
| 245 | matrixLoadTranslate(mat1, x, 0.8f, 0.f); |
| 246 | matrixScale(mat1, scale, scale, 1.f); |
| 247 | } else { |
| 248 | matrixLoadTranslate(mat1, x, -0.9f, 0.f); |
| 249 | matrixScale(mat1, scale, -scale, 1.f); |
| 250 | } |
Jason Sams | 461073b | 2009-10-20 12:06:28 -0700 | [diff] [blame^] | 251 | matrixTranslate(mat1, 0, p * 2, 0.f); |
| 252 | matrixRotate(mat1, -p * 50, 1, 0, 0); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 253 | vpLoadModelMatrix(mat1); |
| 254 | |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 255 | float soff = -(row * 1.4); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 256 | if (isTop) { |
| 257 | matrixLoadScale(mat1, 1.f, -0.85f, 1.f); |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 258 | matrixTranslate(mat1, 0, soff - 0.97f, 0); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 259 | } else { |
| 260 | matrixLoadScale(mat1, 1.f, 0.85f, 1.f); |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 261 | matrixTranslate(mat1, 0, soff - 0.45f, 0); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 262 | } |
| 263 | vpLoadTextureMatrix(mat1); |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 264 | return -soff * 10.f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | void |
| 268 | draw_home_button() |
| 269 | { |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 270 | setColor(1.0f, 1.0f, 1.0f, 1.0f); |
Joe Onorato | d63458b | 2009-10-15 21:19:09 -0700 | [diff] [blame] | 271 | bindTexture(NAMED_PFTexLinear, 0, state->homeButtonId); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 272 | |
| 273 | float scale = 2.0f / SCREEN_WIDTH_PX; |
| 274 | |
| 275 | float x = 0.0f; |
| 276 | |
| 277 | float y = -(SCREEN_HEIGHT_PX / (float)SCREEN_WIDTH_PX); |
| 278 | y += g_Zoom * (scale * params->homeButtonTextureHeight / 2); |
| 279 | |
| 280 | float z = 0.0f; |
| 281 | drawSprite(x, y, z, params->homeButtonTextureWidth, params->homeButtonTextureHeight); |
| 282 | } |
| 283 | |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 284 | void drawFrontGrid(float rowOffset, float p) |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 285 | { |
| 286 | float h = getHeight(); |
| 287 | float w = getWidth(); |
| 288 | |
| 289 | int intRowOffset = rowOffset; |
| 290 | float rowFrac = rowOffset - intRowOffset; |
| 291 | float colWidth = getWidth() / 4; |
| 292 | float rowHeight = colWidth + 25.f; |
| 293 | float yoff = h - ((h - (rowHeight * 4.f)) / 2); |
| 294 | |
| 295 | yoff -= 110; |
| 296 | |
| 297 | int row, col; |
| 298 | int iconNum = intRowOffset * 4; |
| 299 | float ymax = yoff; |
| 300 | float ymin = yoff - (3 * rowHeight) - 70; |
| 301 | |
| 302 | for (row = 0; row < 5; row++) { |
| 303 | float y = yoff - ((-rowFrac + row) * rowHeight); |
| 304 | |
| 305 | for (col=0; col < 4; col++) { |
| 306 | if (iconNum >= state->iconCount) { |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | if (iconNum >= 0) { |
| 311 | float x = colWidth * col - ((128 - colWidth) / 2); |
| 312 | |
| 313 | if ((y >= ymin) && (y <= ymax)) { |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 314 | setColor(1.f, 1.f, 1.f, 1.f); |
Joe Onorato | 742d7fc | 2009-10-15 19:48:16 -0700 | [diff] [blame] | 315 | |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 316 | if (state->selectedIconIndex == iconNum && !p) { |
Joe Onorato | 742d7fc | 2009-10-15 19:48:16 -0700 | [diff] [blame] | 317 | bindTexture(NAMED_PFTexLinear, 0, state->selectedIconTexture); |
| 318 | drawSpriteScreenspace(x, y, 0, 128, 128); |
| 319 | } |
| 320 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 321 | bindTexture(NAMED_PFTexLinear, 0, loadI32(ALLOC_ICON_IDS, iconNum)); |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 322 | if (!p) { |
| 323 | drawSpriteScreenspace(x, y, 0, 128, 128); |
| 324 | } else { |
| 325 | float px = ((x + 64) - (getWidth() / 2)) / (getWidth() / 2); |
| 326 | float py = ((y + 64) - (getHeight() / 2)) / (getWidth() / 2); |
| 327 | float d = 64.f / (getWidth() / 2); |
| 328 | px *= p + 1; |
| 329 | py *= p + 1; |
| 330 | drawQuadTexCoords(px - d, py - d, -p, 0, 1, |
| 331 | px - d, py + d, -p, 0, 0, |
| 332 | px + d, py + d, -p, 1, 0, |
| 333 | px + d, py - d, -p, 1, 1); |
| 334 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | float y2 = y - 44; |
| 338 | float a = 1.f; |
| 339 | if (y2 < ymin) { |
| 340 | a = 1.f - (ymin - y2) * 0.02f; |
| 341 | } |
| 342 | if (y > (ymax + 40)) { |
| 343 | a = 1.f - (y - (ymax + 40)) * 0.02f; |
| 344 | } |
| 345 | a = clampf(a, 0, 1); |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 346 | a *= maxf(0, 1.f - p * 5.f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 347 | |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 348 | setColor(1, 1, 1, a); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 349 | bindTexture(NAMED_PFTexLinear, 0, loadI32(ALLOC_LABEL_IDS, iconNum)); |
| 350 | drawSpriteScreenspace(x, y - 44, 0, |
| 351 | params->bubbleBitmapWidth, params->bubbleBitmapHeight); |
| 352 | } |
| 353 | iconNum++; |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 358 | void drawStrip(float row, float column, int isTop, int iconNum, float p) |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 359 | { |
| 360 | if (iconNum < 0) return; |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 361 | int offset = positionStrip(row, column, isTop, p); |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 362 | bindTexture(NAMED_PFTexLinear, 0, loadI32(ALLOC_ICON_IDS, iconNum)); |
| 363 | if (offset < -20) return; |
| 364 | offset = clamp(offset, 0, 199 - 20); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 365 | drawSimpleMeshRange(NAMED_SMMesh, offset * 6, 20 * 6); |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Jason Sams | 461073b | 2009-10-20 12:06:28 -0700 | [diff] [blame^] | 368 | void drawTop(float rowOffset, float p) |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 369 | { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 370 | int row, col; |
| 371 | int iconNum = 0; |
| 372 | for (row = 0; row < rowOffset; row++) { |
| 373 | for (col=0; col < 4; col++) { |
| 374 | if (iconNum >= state->iconCount) { |
| 375 | return; |
| 376 | } |
Jason Sams | 461073b | 2009-10-20 12:06:28 -0700 | [diff] [blame^] | 377 | drawStrip(rowOffset - row, col, 1, iconNum, p); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 378 | iconNum++; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 383 | void drawBottom(float rowOffset, float p) |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 384 | { |
| 385 | float pos = -1.f; |
| 386 | int intRowOffset = rowOffset; |
| 387 | pos -= rowOffset - intRowOffset; |
| 388 | |
| 389 | int row, col; |
| 390 | int iconNum = (intRowOffset + 3) * 4; |
| 391 | while (1) { |
| 392 | for (col=0; col < 4; col++) { |
| 393 | if (iconNum >= state->iconCount) { |
| 394 | return; |
| 395 | } |
| 396 | if (pos > -1) { |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 397 | drawStrip(pos, col, 0, iconNum, p); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 398 | } |
| 399 | iconNum++; |
| 400 | } |
| 401 | pos += 1.f; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | int |
| 406 | main(int launchID) |
| 407 | { |
| 408 | // Compute dt in seconds. |
| 409 | int newTime = uptimeMillis(); |
| 410 | g_DT = (newTime - g_LastTime) / 1000.f; |
| 411 | g_LastTime = newTime; |
| 412 | |
| 413 | if (!g_DrawLastFrame) { |
| 414 | // If we stopped rendering we cannot use DT. |
| 415 | // assume 30fps in this case. |
| 416 | g_DT = 0.033f; |
| 417 | } |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 418 | // physics may break if DT is large. |
| 419 | g_DT = minf(g_DT, 0.2f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 420 | |
| 421 | if (g_Zoom != state->zoomTarget) { |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 422 | float dz; |
| 423 | if (state->zoomTarget > 0.5f) { |
| 424 | dz = (1 - g_Zoom) * 0.2f; |
| 425 | } else { |
| 426 | dz = -g_DT - (1 - g_Zoom) * 0.2f; |
| 427 | } |
| 428 | if (dz && (fabsf(dz) < 0.02f)) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 429 | if (dz > 0) { |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 430 | dz = 0.02f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 431 | } else { |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 432 | dz = -0.02f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | if (fabsf(g_Zoom - state->zoomTarget) < fabsf(dz)) { |
| 436 | g_Zoom = state->zoomTarget; |
| 437 | } else { |
| 438 | g_Zoom += dz; |
| 439 | } |
| 440 | updateReadback(); |
| 441 | } |
| 442 | |
| 443 | // Set clear value to dim the background based on the zoom position. |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 444 | if ((g_Zoom < 0.001f) && (state->zoomTarget < 0.001f) && !g_SpecialHWWar) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 445 | pfClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 446 | // When we're zoomed out and not tracking motion events, reset the pos to 0. |
| 447 | if (!g_LastTouchDown) { |
| 448 | g_PosPage = 0; |
| 449 | } |
| 450 | return lastFrame(0); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 451 | } else { |
| 452 | pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom); |
| 453 | } |
| 454 | |
| 455 | // icons & labels |
| 456 | int iconCount = state->iconCount; |
| 457 | g_PosMax = ((iconCount + 3) / 4) - 4; |
| 458 | if (g_PosMax < 0) g_PosMax = 0; |
| 459 | |
| 460 | updatePos(0.1f); |
| 461 | updateReadback(); |
| 462 | |
| 463 | //debugF(" draw g_PosPage", g_PosPage); |
| 464 | |
| 465 | // Draw the icons ======================================== |
| 466 | |
| 467 | //bindProgramFragment(NAMED_PFColor); |
| 468 | //positionStrip(1, 0, 0); |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 469 | //drawSimpleMesh(NAMED_SMMesh); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 470 | |
| 471 | bindProgramFragment(NAMED_PFTexLinear); |
| 472 | |
| 473 | |
Jason Sams | 461073b | 2009-10-20 12:06:28 -0700 | [diff] [blame^] | 474 | drawTop(g_PosPage, 1-g_Zoom); |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 475 | drawBottom(g_PosPage, 1-g_Zoom); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 476 | |
| 477 | { |
| 478 | float mat1[16]; |
| 479 | matrixLoadIdentity(mat1); |
| 480 | vpLoadModelMatrix(mat1); |
| 481 | vpLoadTextureMatrix(mat1); |
| 482 | } |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 483 | drawFrontGrid(g_PosPage, 1-g_Zoom); |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 484 | draw_home_button(); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 485 | |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 486 | |
| 487 | // This is a WAR to do a rendering pass without drawing during init to |
| 488 | // force the driver to preload and compile its shaders. |
| 489 | // Without this the first animation does not appear due to the time it |
| 490 | // takes to init the driver state. |
| 491 | if (g_SpecialHWWar) { |
| 492 | g_SpecialHWWar = 0; |
| 493 | return 1; |
| 494 | } |
| 495 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 496 | // Bug workaround where the last frame is not always displayed |
| 497 | // So we keep rendering until the bug is fixed. |
| 498 | return lastFrame((g_PosVelocity != 0) || fracf(g_PosPage) || g_Zoom != state->zoomTarget); |
| 499 | } |
| 500 | |