-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DSi theme: Add original launch dots animation
Closes #2474
- Loading branch information
1 parent
aacff55
commit be6a881
Showing
1 changed file
with
80 additions
and
60 deletions.
There are no files selected for viewing
140 changes: 80 additions & 60 deletions
140
romsel_dsimenutheme/arm9/source/graphics/launchDots.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,100 @@ | ||
#include "launchDots.h" | ||
#include "ThemeTextures.h" | ||
#include <gl2d.h> | ||
#include <algorithm> | ||
#include <cmath> | ||
|
||
// F(p, t) = (R(t), p*pi/6 + Vt) | ||
// 32 degrees = 3276 brads | ||
|
||
// Spacing between dots in binary radians | ||
#define DOT_INTERVAL 2730 | ||
|
||
// Initial radius of the circle | ||
#define DOT_INIT_RADIUS 36 | ||
|
||
// 90 degrees in binary radians | ||
#define BRAD_90_DEG 8192 | ||
|
||
// number of timesteps to animate | ||
#define DOTS_NUM_TIMESTEPS 32 | ||
#define DOTS_NUM_TIMESTEPS 36 | ||
|
||
/* | ||
* getRadius, getVelocity, and getDotRadiusFrame are the curves that | ||
* define the behaviour of the circle | ||
*/ | ||
|
||
// Gets the radius for the given frame | ||
inline int getRadius(int frame) { | ||
return DOT_INIT_RADIUS + std::min((int)(4 * frame * log(frame)), 10); | ||
} | ||
|
||
// Gets the angular velocity of the radius in brads for the given frame | ||
inline int getVelocity(int frame) { | ||
if (frame < 8) | ||
return 182 >> 2; //rotate slowly | ||
return 91 + (4 * frame); // 91 - 1 degrees of rotation at frame. | ||
} | ||
static u8 dotsXYPos[DOTS_NUM_TIMESTEPS][12][2] = { | ||
{{120, 77}, {102, 82}, {138, 82}, {89, 95}, {151, 95}, { 84, 113}, {156, 113}, { 89, 131}, {151, 131}, {102, 144}, {138, 144}, {120, 149}}, | ||
{{120, 75}, {101, 81}, {139, 81}, {88, 94}, {152, 94}, { 82, 113}, {158, 113}, { 88, 132}, {152, 132}, {101, 145}, {139, 145}, {120, 151}}, | ||
{{120, 73}, {100, 79}, {140, 79}, {86, 93}, {154, 93}, { 80, 113}, {160, 113}, { 86, 133}, {154, 133}, {100, 147}, {140, 147}, {120, 153}}, | ||
{{120, 71}, { 98, 78}, {141, 77}, {84, 92}, {155, 91}, { 78, 113}, {162, 113}, { 85, 135}, {156, 134}, { 99, 149}, {142, 148}, {120, 155}}, | ||
{{119, 69}, { 96, 76}, {143, 75}, {82, 90}, {157, 89}, { 76, 114}, {164, 112}, { 83, 137}, {158, 136}, { 97, 151}, {144, 150}, {121, 157}}, | ||
{{118, 68}, { 95, 76}, {142, 74}, {81, 91}, {157, 88}, { 75, 115}, {165, 111}, { 83, 138}, {159, 135}, { 98, 152}, {145, 150}, {122, 158}}, | ||
{{117, 67}, { 94, 75}, {140, 72}, {79, 93}, {158, 87}, { 74, 116}, {166, 110}, { 82, 139}, {161, 133}, {100, 154}, {146, 151}, {123, 159}}, | ||
{{115, 67}, { 93, 75}, {140, 71}, {78, 93}, {158, 86}, { 74, 118}, {166, 108}, { 82, 140}, {162, 133}, {100, 155}, {147, 151}, {125, 159}}, | ||
{{114, 66}, { 92, 75}, {140, 70}, {77, 93}, {158, 85}, { 73, 119}, {167, 107}, { 82, 141}, {163, 133}, {100, 156}, {148, 151}, {126, 160}}, | ||
{{113, 66}, { 91, 76}, {139, 70}, {77, 94}, {157, 84}, { 73, 120}, {167, 106}, { 83, 142}, {163, 132}, {101, 156}, {149, 150}, {127, 160}}, | ||
{{112, 67}, { 90, 77}, {138, 69}, {76, 95}, {156, 83}, { 74, 121}, {166, 105}, { 84, 143}, {164, 131}, {102, 157}, {150, 149}, {128, 159}}, | ||
{{110, 67}, { 89, 78}, {136, 69}, {76, 97}, {155, 82}, { 74, 123}, {166, 103}, { 85, 144}, {164, 129}, {104, 157}, {151, 148}, {130, 159}}, | ||
{{109, 67}, { 88, 78}, {134, 68}, {75, 99}, {155, 81}, { 74, 124}, {166, 102}, { 85, 145}, {165, 127}, {106, 158}, {152, 148}, {131, 159}}, | ||
{{107, 68}, { 86, 80}, {132, 68}, {75, 101}, {153, 79}, { 75, 126}, {165, 100}, { 87, 147}, {165, 125}, {108, 158}, {154, 146}, {133, 158}}, | ||
{{106, 68}, { 85, 81}, {131, 67}, {74, 102}, {152, 78}, { 75, 127}, {165, 99}, { 88, 148}, {166, 124}, {109, 159}, {155, 145}, {134, 158}}, | ||
{{103, 69}, { 83, 83}, {128, 67}, {74, 105}, {150, 76}, { 76, 130}, {164, 96}, { 90, 150}, {166, 121}, {112, 159}, {157, 143}, {137, 157}}, | ||
{{101, 70}, { 82, 85}, {125, 66}, {73, 108}, {148, 75}, { 77, 132}, {163, 94}, { 92, 151}, {167, 118}, {115, 160}, {158, 141}, {139, 156}}, | ||
{{ 98, 71}, { 81, 87}, {122, 66}, {73, 111}, {146, 74}, { 78, 135}, {162, 91}, { 94, 152}, {167, 115}, {118, 160}, {159, 139}, {142, 155}}, | ||
{{ 0, 0}, { 79, 89}, {120, 66}, {73, 113}, {144, 72}, { 79, 137}, {161, 89}, { 96, 154}, {167, 113}, {120, 160}, {161, 137}, {144, 154}}, | ||
{{ 0, 0}, { 77, 93}, {116, 66}, {73, 117}, {140, 70}, { 81, 140}, {159, 86}, {100, 156}, {167, 109}, {124, 160}, {163, 133}, {147, 152}}, | ||
{{ 0, 0}, { 76, 96}, { 0, 0}, {73, 120}, {137, 69}, { 84, 143}, {156, 83}, {103, 157}, {167, 106}, {127, 160}, {164, 130}, {150, 149}}, | ||
{{ 0, 0}, { 75, 98}, { 0, 0}, {74, 124}, {135, 68}, { 86, 145}, {154, 81}, {105, 158}, {166, 102}, {131, 159}, {165, 128}, {152, 147}}, | ||
{{ 0, 0}, { 76, 100}, { 0, 0}, {75, 127}, {133, 68}, { 87, 147}, {153, 79}, {107, 158}, {165, 99}, {134, 158}, {165, 126}, {154, 146}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, {67, 130}, { 0, 0}, { 90, 149}, {150, 77}, {111, 159}, {164, 96}, {137, 157}, {166, 122}, {156, 143}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, {77, 132}, { 0, 0}, { 92, 151}, {148, 75}, {114, 160}, {163, 94}, {139, 156}, {167, 119}, {158, 141}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, {79, 136}, { 0, 0}, { 95, 153}, { 0, 0}, {118, 160}, {161, 90}, {143, 154}, {167, 115}, {160, 138}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, {81, 139}, { 0, 0}, { 98, 154}, { 0, 0}, {121, 160}, {159, 87}, {146, 152}, {167, 112}, {161, 135}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, {83, 139}, { 0, 0}, {100, 154}, { 0, 0}, {125, 158}, { 0, 0}, {148, 148}, {167, 106}, {163, 131}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, {84, 139}, { 0, 0}, {102, 153}, { 0, 0}, {128, 155}, { 0, 0}, {150, 145}, {166, 101}, {164, 127}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, {86, 140}, { 0, 0}, {105, 152}, { 0, 0}, {131, 153}, { 0, 0}, {153, 141}, { 0, 0}, {165, 122}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, {87, 139}, { 0, 0}, {108, 150}, { 0, 0}, {134, 150}, { 0, 0}, {155, 137}, { 0, 0}, {165, 117}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {111, 149}, { 0, 0}, {137, 147}, { 0, 0}, {157, 132}, { 0, 0}, {166, 112}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {114, 148}, { 0, 0}, {140, 144}, { 0, 0}, {159, 128}, { 0, 0}, { 0, 0}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {118, 146}, { 0, 0}, {143, 140}, { 0, 0}, {161, 123}, { 0, 0}, { 0, 0}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {122, 144}, { 0, 0}, {145, 137}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}}, | ||
{{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {148, 132}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}} | ||
}; | ||
|
||
// This curve could be improved... | ||
// Gets the weight/ frame of the dot from 0 (empty) to 5 (largest) for the given index and frame | ||
inline int getDotRadiusFrame(int dotIndex, int frame) { | ||
if (frame - dotIndex < 2) return 5; | ||
if (frame - dotIndex > 8) return 0; | ||
// Sin between [-1. 1] => [0, 2] | ||
float SIN = fixedToFloat(sinLerp((dotIndex * DOT_INTERVAL) - BRAD_90_DEG - (frame * getVelocity(frame))), 12) + 1; | ||
|
||
return std::min((SIN * 10 / 4), (float)5); | ||
// return ((frame % 4) + dotIndex) % 5; return 5 | ||
} | ||
|
||
|
||
inline int getDotX(int dotIndex, int frame) { | ||
return getRadius(frame) * fixedToFloat(cosLerp((dotIndex * DOT_INTERVAL) - BRAD_90_DEG - (frame * getVelocity(frame))), 12); | ||
} | ||
|
||
inline int getDotY(int dotIndex, int frame) { | ||
return getRadius(frame) * fixedToFloat(sinLerp((dotIndex * DOT_INTERVAL) - BRAD_90_DEG - (frame * getVelocity(frame))), 12); | ||
} | ||
static u8 dotsSizes[DOTS_NUM_TIMESTEPS][12] = { | ||
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, | ||
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, | ||
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, | ||
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, | ||
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, | ||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||
{0, 0, 0, 1, 0, 2, 0, 3, 0, 3, 0, 2}, | ||
{0, 0, 0, 0, 0, 2, 0, 3, 0, 2, 0, 1}, | ||
{0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 0, 0}, | ||
{0, 0, 0, 0, 0, 1, 0, 2, 0, 1, 0, 0}, | ||
{0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0}, | ||
{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0} | ||
}; | ||
|
||
static int radFrame = 0; | ||
|
||
void LaunchDots::drawFrame(int frame) { | ||
for (int i = 0; i < 12; i++) { | ||
int X = getDotX(i, frame); | ||
int Y = getDotY(i, frame); | ||
int dotFrame = getDotRadiusFrame(i, frame); | ||
if (dotFrame == -1) | ||
if (dotsSizes[frame][i] == 0) | ||
continue; | ||
glSprite((128 - (DOT_INIT_RADIUS >> 2)) + X, (96 + (DOT_INIT_RADIUS >> 2) + (DOT_INIT_RADIUS >> 3)) + Y, | ||
GL_FLIP_NONE, &tex().launchdotImage()[dotFrame & 15]); | ||
glSprite(dotsXYPos[frame][i][0], dotsXYPos[frame][i][1], GL_FLIP_NONE, &tex().launchdotImage()[dotsSizes[frame][i]]); | ||
} | ||
} | ||
void LaunchDots::drawAuto() { | ||
drawFrame(radFrame); | ||
if (radFrame < DOTS_NUM_TIMESTEPS) { | ||
drawFrame(radFrame); | ||
radFrame++; | ||
} else { | ||
radFrame = DOTS_NUM_TIMESTEPS; | ||
} | ||
} |