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