Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 1 | #pragma version(1) |
| 2 | #pragma stateVertex(PV) |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 3 | #pragma stateFragment(PFTexNearest) |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 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 | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 12 | float g_FrictionTable[9]; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 13 | float g_PhysicsTableSize; |
| 14 | |
| 15 | float g_PosPage; |
| 16 | float g_PosVelocity; |
| 17 | float g_LastPositionX; |
| 18 | int g_LastTouchDown; |
| 19 | float g_DT; |
| 20 | int g_LastTime; |
| 21 | int g_PosMax; |
| 22 | float g_Zoom; |
| 23 | float g_OldPosPage; |
| 24 | float g_OldPosVelocity; |
| 25 | float g_OldZoom; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 26 | float g_MoveToTotalTime; |
| 27 | float g_MoveToTime; |
| 28 | float g_MoveToOldPos; |
| 29 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 30 | |
| 31 | // Drawing constants, should be parameters ====== |
| 32 | #define VIEW_ANGLE 1.28700222f |
| 33 | |
| 34 | int g_DrawLastFrame; |
| 35 | int lastFrame(int draw) { |
| 36 | // We draw one extra frame to work around the last frame post bug. |
| 37 | // We also need to track if we drew the last frame to deal with large DT |
| 38 | // in the physics. |
| 39 | int ret = g_DrawLastFrame | draw; |
| 40 | g_DrawLastFrame = draw; |
| 41 | return ret; // should return draw instead. |
| 42 | } |
| 43 | |
| 44 | void updateReadback() { |
| 45 | if ((g_OldPosPage != g_PosPage) || |
| 46 | (g_OldPosVelocity != g_PosVelocity) || |
| 47 | (g_OldZoom != g_Zoom)) { |
| 48 | |
| 49 | g_OldPosPage = g_PosPage; |
| 50 | g_OldPosVelocity = g_PosVelocity; |
| 51 | g_OldZoom = g_Zoom; |
| 52 | |
| 53 | int i[3]; |
| 54 | i[0] = g_PosPage * (1 << 16); |
| 55 | i[1] = g_PosVelocity * (1 << 16); |
| 56 | i[2] = g_OldZoom * (1 << 16); |
| 57 | sendToClient(&i[0], 1, 12, 1); |
| 58 | } |
| 59 | } |
| 60 | |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 61 | void setColor(float r, float g, float b, float a) { |
| 62 | if (g_SpecialHWWar) { |
| 63 | color(0, 0, 0, 0.001f); |
| 64 | } else { |
| 65 | color(r, g, b, a); |
| 66 | } |
| 67 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 68 | |
| 69 | void init() { |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 70 | g_AttractionTable[0] = 20.0f; |
| 71 | g_AttractionTable[1] = 20.0f; |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 72 | g_AttractionTable[2] = 20.0f; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 73 | g_AttractionTable[3] = 10.0f; |
| 74 | g_AttractionTable[4] = -10.0f; |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 75 | g_AttractionTable[5] = -20.0f; |
| 76 | g_AttractionTable[6] = -20.0f; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 77 | g_AttractionTable[7] = -20.0f; |
| 78 | g_AttractionTable[8] = -20.0f; // dup 7 to avoid a clamp later |
| 79 | g_FrictionTable[0] = 10.0f; |
| 80 | g_FrictionTable[1] = 10.0f; |
| 81 | g_FrictionTable[2] = 11.0f; |
| 82 | g_FrictionTable[3] = 15.0f; |
| 83 | g_FrictionTable[4] = 15.0f; |
| 84 | g_FrictionTable[5] = 11.0f; |
| 85 | g_FrictionTable[6] = 10.0f; |
| 86 | g_FrictionTable[7] = 10.0f; |
| 87 | g_FrictionTable[8] = 10.0f; // dup 7 to avoid a clamp later |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 88 | g_PhysicsTableSize = 7; |
| 89 | |
| 90 | g_PosVelocity = 0; |
| 91 | g_PosPage = 0; |
| 92 | g_LastTouchDown = 0; |
| 93 | g_LastPositionX = 0; |
| 94 | g_Zoom = 0; |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 95 | g_SpecialHWWar = 1; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 96 | g_MoveToTime = 0; |
| 97 | g_MoveToOldPos = 0; |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 98 | g_MoveToTotalTime = 0.2f; // Duration of scrolling 1 line |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void resetHWWar() { |
| 102 | g_SpecialHWWar = 1; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void move() { |
| 106 | if (g_LastTouchDown) { |
| 107 | float dx = -(state->newPositionX - g_LastPositionX); |
| 108 | g_PosVelocity = 0; |
Jason Sams | 6ec11bc | 2010-01-19 17:56:52 -0800 | [diff] [blame] | 109 | g_PosPage += dx * 5.2f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 110 | |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 111 | float pmin = -0.49f; |
| 112 | float pmax = g_PosMax + 0.49f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 113 | g_PosPage = clampf(g_PosPage, pmin, pmax); |
| 114 | } |
| 115 | g_LastTouchDown = state->newTouchDown; |
| 116 | g_LastPositionX = state->newPositionX; |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 117 | g_MoveToTime = 0; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 118 | //debugF("Move P", g_PosPage); |
| 119 | } |
| 120 | |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 121 | void moveTo() { |
| 122 | g_MoveToTime = g_MoveToTotalTime; |
| 123 | g_PosVelocity = 0; |
| 124 | g_MoveToOldPos = g_PosPage; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 125 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 126 | // debugF("======= moveTo", state->targetPos); |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Joe Onorato | 3a8820b | 2009-11-10 15:06:42 -0800 | [diff] [blame] | 129 | void setZoom() { |
| 130 | g_Zoom = state->zoomTarget; |
| 131 | g_DrawLastFrame = 1; |
| 132 | updateReadback(); |
| 133 | } |
| 134 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 135 | void fling() { |
| 136 | g_LastTouchDown = 0; |
Jason Sams | 37e7c2b | 2009-10-19 12:55:43 -0700 | [diff] [blame] | 137 | g_PosVelocity = -state->flingVelocity * 4; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 138 | float av = fabsf(g_PosVelocity); |
| 139 | float minVel = 3.5f; |
| 140 | |
| 141 | minVel *= 1.f - (fabsf(fracf(g_PosPage + 0.5f) - 0.5f) * 0.45f); |
| 142 | |
| 143 | if (av < minVel && av > 0.2f) { |
| 144 | if (g_PosVelocity > 0) { |
| 145 | g_PosVelocity = minVel; |
| 146 | } else { |
| 147 | g_PosVelocity = -minVel; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if (g_PosPage <= 0) { |
| 152 | g_PosVelocity = maxf(0, g_PosVelocity); |
| 153 | } |
| 154 | if (g_PosPage > g_PosMax) { |
| 155 | g_PosVelocity = minf(0, g_PosVelocity); |
| 156 | } |
| 157 | } |
| 158 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 159 | float |
| 160 | modf(float x, float y) |
| 161 | { |
| 162 | return x-(y*floorf(x/y)); |
| 163 | } |
| 164 | |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 165 | |
| 166 | /* |
| 167 | * Interpolates values in the range 0..1 to a curve that eases in |
| 168 | * and out. |
| 169 | */ |
| 170 | float |
| 171 | getInterpolation(float input) { |
| 172 | return (cosf((input + 1) * PI) / 2.0f) + 0.5f; |
| 173 | } |
| 174 | |
| 175 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 176 | void updatePos() { |
| 177 | if (g_LastTouchDown) { |
| 178 | return; |
| 179 | } |
| 180 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 181 | float tablePosNorm = fracf(g_PosPage + 0.5f); |
| 182 | float tablePosF = tablePosNorm * g_PhysicsTableSize; |
| 183 | int tablePosI = tablePosF; |
| 184 | float tablePosFrac = tablePosF - tablePosI; |
| 185 | float accel = lerpf(g_AttractionTable[tablePosI], |
| 186 | g_AttractionTable[tablePosI + 1], |
| 187 | tablePosFrac) * g_DT; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 188 | float friction = lerpf(g_FrictionTable[tablePosI], |
| 189 | g_FrictionTable[tablePosI + 1], |
| 190 | tablePosFrac) * g_DT; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 191 | |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 192 | if (g_MoveToTime) { |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 193 | // New position is old posiition + (total distance) * (interpolated time) |
| 194 | g_PosPage = g_MoveToOldPos + (state->targetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime); |
Jason Sams | c1c521e | 2009-10-19 14:45:45 -0700 | [diff] [blame] | 195 | g_MoveToTime -= g_DT; |
| 196 | if (g_MoveToTime <= 0) { |
| 197 | g_MoveToTime = 0; |
| 198 | g_PosPage = state->targetPos; |
| 199 | } |
| 200 | return; |
| 201 | } |
| 202 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 203 | // If our velocity is low OR acceleration is opposing it, apply it. |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 204 | if (fabsf(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 205 | g_PosVelocity += accel; |
| 206 | } |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 207 | //debugF("g_PosPage", g_PosPage); |
| 208 | //debugF(" g_PosVelocity", g_PosVelocity); |
| 209 | //debugF(" friction", friction); |
| 210 | //debugF(" accel", accel); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 211 | |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 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 | if ((friction > fabsf(g_PosVelocity)) && (friction > fabsf(accel))) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 222 | // Special get back to center and overcome friction physics. |
| 223 | float t = tablePosNorm - 0.5f; |
| 224 | if (fabsf(t) < (friction * g_DT)) { |
| 225 | // really close, just snap |
| 226 | g_PosPage = roundf(g_PosPage); |
| 227 | g_PosVelocity = 0; |
| 228 | } else { |
| 229 | if (t > 0) { |
| 230 | g_PosVelocity = -friction; |
| 231 | } else { |
| 232 | g_PosVelocity = friction; |
| 233 | } |
| 234 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 235 | } |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 236 | |
| 237 | // Check for out of boundry conditions. |
| 238 | if (g_PosPage < 0 && g_PosVelocity < 0) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 239 | float damp = 1.0 + (g_PosPage * 4); |
| 240 | damp = clampf(damp, 0.f, 0.9f); |
| 241 | g_PosVelocity *= damp; |
| 242 | } |
| 243 | if (g_PosPage > g_PosMax && g_PosVelocity > 0) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 244 | float damp = 1.0 - ((g_PosPage - g_PosMax) * 4); |
| 245 | damp = clampf(damp, 0.f, 0.9f); |
| 246 | g_PosVelocity *= damp; |
| 247 | } |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 248 | |
| 249 | g_PosPage += g_PosVelocity * g_DT; |
| 250 | g_PosPage = clampf(g_PosPage, -0.49, g_PosMax + 0.49); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 253 | |
| 254 | void |
| 255 | draw_home_button() |
| 256 | { |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 257 | setColor(1.0f, 1.0f, 1.0f, 1.0f); |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 258 | bindTexture(NAMED_PFTexNearest, 0, state->homeButtonId); |
Jason Sams | 96b49d8 | 2009-10-20 14:28:53 -0700 | [diff] [blame] | 259 | float x = (SCREEN_WIDTH_PX - params->homeButtonTextureWidth) / 2; |
| 260 | float y = (g_Zoom - 1.f) * params->homeButtonTextureHeight; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 261 | |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 262 | y -= 30; // move the house to the edge of the screen as it doesn't fill the texture. |
Jason Sams | 96b49d8 | 2009-10-20 14:28:53 -0700 | [diff] [blame] | 263 | drawSpriteScreenspace(x, y, 0, params->homeButtonTextureWidth, params->homeButtonTextureHeight); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 266 | void drawFrontGrid(float rowOffset, float p) |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 267 | { |
| 268 | float h = getHeight(); |
| 269 | float w = getWidth(); |
| 270 | |
| 271 | int intRowOffset = rowOffset; |
| 272 | float rowFrac = rowOffset - intRowOffset; |
| 273 | float colWidth = getWidth() / 4; |
| 274 | float rowHeight = colWidth + 25.f; |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 275 | float yoff = 0.5f * h + 1.5f * rowHeight; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 276 | |
| 277 | int row, col; |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 278 | int iconNum = (intRowOffset - 5) * 4; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 279 | |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 280 | bindProgramVertex(NAMED_PVCurve); |
| 281 | |
| 282 | storeF(ALLOC_VP_CONSTANTS, 4, p); |
| 283 | |
| 284 | for (row = -5; row < 15; row++) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 285 | float y = yoff - ((-rowFrac + row) * rowHeight); |
| 286 | |
| 287 | for (col=0; col < 4; col++) { |
| 288 | if (iconNum >= state->iconCount) { |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | if (iconNum >= 0) { |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 293 | float x = colWidth * col + (colWidth / 2); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 294 | |
Jason Sams | 37f262d | 2010-01-20 11:19:51 -0800 | [diff] [blame^] | 295 | bindProgramFragment(NAMED_PFTexMip); |
| 296 | |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 297 | storeF(ALLOC_VP_CONSTANTS, 2, x); |
| 298 | storeF(ALLOC_VP_CONSTANTS, 3, y); |
Jason Sams | 37f262d | 2010-01-20 11:19:51 -0800 | [diff] [blame^] | 299 | if (state->selectedIconIndex == iconNum && !p) { |
| 300 | //bindTexture(NAMED_PFTexMip, 0, state->selectedIconTexture); |
| 301 | //bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_ICON_IDS, iconNum)); |
| 302 | //storeF(ALLOC_VP_CONSTANTS, 0, 100.f); |
| 303 | //storeF(ALLOC_VP_CONSTANTS, 1, 100.f); |
| 304 | //drawSimpleMesh(NAMED_SMCell); |
| 305 | } |
| 306 | |
| 307 | storeF(ALLOC_VP_CONSTANTS, 0, 74.f); |
| 308 | storeF(ALLOC_VP_CONSTANTS, 1, 74.f); |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 309 | bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_ICON_IDS, iconNum)); |
| 310 | drawSimpleMesh(NAMED_SMCell); |
Joe Onorato | 742d7fc | 2009-10-15 19:48:16 -0700 | [diff] [blame] | 311 | |
Jason Sams | 37f262d | 2010-01-20 11:19:51 -0800 | [diff] [blame^] | 312 | bindProgramFragment(NAMED_PFTexMipAlpha); |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 313 | storeF(ALLOC_VP_CONSTANTS, 0, 128.f); |
| 314 | storeF(ALLOC_VP_CONSTANTS, 1, 64.f); |
| 315 | storeF(ALLOC_VP_CONSTANTS, 3, y - 64.f); |
Jason Sams | 37f262d | 2010-01-20 11:19:51 -0800 | [diff] [blame^] | 316 | bindTexture(NAMED_PFTexMipAlpha, 0, loadI32(ALLOC_LABEL_IDS, iconNum)); |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 317 | drawSimpleMesh(NAMED_SMCell); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 318 | } |
| 319 | iconNum++; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 324 | |
| 325 | int |
| 326 | main(int launchID) |
| 327 | { |
| 328 | // Compute dt in seconds. |
| 329 | int newTime = uptimeMillis(); |
| 330 | g_DT = (newTime - g_LastTime) / 1000.f; |
| 331 | g_LastTime = newTime; |
Jason Sams | 2e19c05 | 2009-10-20 18:19:55 -0700 | [diff] [blame] | 332 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 333 | if (!g_DrawLastFrame) { |
| 334 | // If we stopped rendering we cannot use DT. |
| 335 | // assume 30fps in this case. |
| 336 | g_DT = 0.033f; |
| 337 | } |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 338 | // physics may break if DT is large. |
| 339 | g_DT = minf(g_DT, 0.2f); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 340 | |
| 341 | if (g_Zoom != state->zoomTarget) { |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 342 | float dz; |
| 343 | if (state->zoomTarget > 0.5f) { |
| 344 | dz = (1 - g_Zoom) * 0.2f; |
| 345 | } else { |
| 346 | dz = -g_DT - (1 - g_Zoom) * 0.2f; |
| 347 | } |
| 348 | if (dz && (fabsf(dz) < 0.02f)) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 349 | if (dz > 0) { |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 350 | dz = 0.02f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 351 | } else { |
Jason Sams | 09c6fc0 | 2009-10-16 17:23:23 -0700 | [diff] [blame] | 352 | dz = -0.02f; |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | if (fabsf(g_Zoom - state->zoomTarget) < fabsf(dz)) { |
| 356 | g_Zoom = state->zoomTarget; |
| 357 | } else { |
| 358 | g_Zoom += dz; |
| 359 | } |
| 360 | updateReadback(); |
| 361 | } |
| 362 | |
| 363 | // Set clear value to dim the background based on the zoom position. |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 364 | if ((g_Zoom < 0.001f) && (state->zoomTarget < 0.001f) && !g_SpecialHWWar) { |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 365 | pfClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 366 | // When we're zoomed out and not tracking motion events, reset the pos to 0. |
| 367 | if (!g_LastTouchDown) { |
| 368 | g_PosPage = 0; |
| 369 | } |
| 370 | return lastFrame(0); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 371 | } else { |
| 372 | pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom); |
| 373 | } |
| 374 | |
| 375 | // icons & labels |
| 376 | int iconCount = state->iconCount; |
| 377 | g_PosMax = ((iconCount + 3) / 4) - 4; |
| 378 | if (g_PosMax < 0) g_PosMax = 0; |
| 379 | |
| 380 | updatePos(0.1f); |
| 381 | updateReadback(); |
| 382 | |
| 383 | //debugF(" draw g_PosPage", g_PosPage); |
| 384 | |
| 385 | // Draw the icons ======================================== |
Jason Sams | b4ecab2 | 2010-01-19 16:43:26 -0800 | [diff] [blame] | 386 | drawFrontGrid(g_PosPage, 1-g_Zoom); |
Jason Sams | c851479 | 2009-10-29 14:27:29 -0700 | [diff] [blame] | 387 | |
| 388 | bindProgramFragment(NAMED_PFTexNearest); |
Jason Sams | b52dfa0 | 2009-10-14 20:16:14 -0700 | [diff] [blame] | 389 | draw_home_button(); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 390 | |
Jason Sams | 41b61c8 | 2009-10-15 15:40:54 -0700 | [diff] [blame] | 391 | // This is a WAR to do a rendering pass without drawing during init to |
| 392 | // force the driver to preload and compile its shaders. |
| 393 | // Without this the first animation does not appear due to the time it |
| 394 | // takes to init the driver state. |
| 395 | if (g_SpecialHWWar) { |
| 396 | g_SpecialHWWar = 0; |
| 397 | return 1; |
| 398 | } |
| 399 | |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 400 | // Bug workaround where the last frame is not always displayed |
| 401 | // So we keep rendering until the bug is fixed. |
Mike Cleron | 7d5d746 | 2009-10-20 14:06:00 -0700 | [diff] [blame] | 402 | return lastFrame((g_PosVelocity != 0) || fracf(g_PosPage) || g_Zoom != state->zoomTarget || (g_MoveToTime != 0)); |
Jason Sams | 0f505e5 | 2009-10-13 17:18:35 -0700 | [diff] [blame] | 403 | } |
| 404 | |