MCPcopy Create free account
hub / github.com/axmolengine/axmol / updateRadial

Method updateRadial

core/2d/ProgressTimer.cpp:341–486  ·  view source on GitHub ↗

Update does the work of mapping the texture onto the triangles It now doesn't occur the cost of free/alloc data every update cycle. It also only changes the percentage point but no other points if they have not been modified. It now deals with flipped texture. If you run into this problem, just use the sprite property and enable the methods flipX, flipY.

Source from the content-addressed store, hash-verified

339// sprite property and enable the methods flipX, flipY.
340///
341void ProgressTimer::updateRadial()
342{
343 if (!_sprite)
344 {
345 return;
346 }
347 float alpha = _percentage / 100.f;
348
349 float angle = 2.f * ((float)M_PI) * (_reverseDirection ? alpha : 1.0f - alpha);
350
351 // We find the vector to do a hit detection based on the percentage
352 // We know the first vector is the one @ 12 o'clock (top,mid) so we rotate
353 // from that by the progress angle around the _midpoint pivot
354 Vec2 topMid(_midpoint.x, 1.f);
355 Vec2 percentagePt = topMid.rotateByAngle(_midpoint, angle);
356
357 int index = 0;
358 Vec2 hit;
359
360 if (alpha == 0.f)
361 {
362 // More efficient since we don't always need to check intersection
363 // If the alpha is zero then the hit point is top mid and the index is 0.
364 hit = topMid;
365 index = 0;
366 }
367 else if (alpha == 1.f)
368 {
369 // More efficient since we don't always need to check intersection
370 // If the alpha is one then the hit point is top mid and the index is 4.
371 hit = topMid;
372 index = 4;
373 }
374 else
375 {
376 // We run a for loop checking the edges of the texture to find the
377 // intersection point
378 // We loop through five points since the top is split in half
379
380 float min_t = FLT_MAX;
381
382 for (int i = 0; i <= kProgressTextureCoordsCount; ++i)
383 {
384 int pIndex = (i + (kProgressTextureCoordsCount - 1)) % kProgressTextureCoordsCount;
385
386 Vec2 edgePtA = boundaryTexCoord(i % kProgressTextureCoordsCount);
387 Vec2 edgePtB = boundaryTexCoord(pIndex);
388
389 // Remember that the top edge is split in half for the 12 o'clock position
390 // Let's deal with that here by finding the correct endpoints
391 if (i == 0)
392 {
393 edgePtB = edgePtA.lerp(edgePtB, 1 - _midpoint.x);
394 }
395 else if (i == 4)
396 {
397 edgePtA = edgePtA.lerp(edgePtB, 1 - _midpoint.x);
398 }

Callers

nothing calls this directly

Calls 10

updateColorFunction · 0.85
rotateByAngleMethod · 0.80
createVertexBufferMethod · 0.80
createIndexBufferMethod · 0.80
lerpMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
updateIndexBufferMethod · 0.45
dataMethod · 0.45
updateVertexBufferMethod · 0.45

Tested by

no test coverage detected