diff options
author | Romain Guy <romainguy@android.com> | 2009-08-18 11:39:17 -0700 |
---|---|---|
committer | Romain Guy <romainguy@android.com> | 2009-08-18 11:39:17 -0700 |
commit | cac80a6e1324cb0679977a61533edfe3f7f9cf6b (patch) | |
tree | 8830a27d415fff879f66cde105c4ed56340476e6 /libs/rs/rsScriptC_Lib.cpp | |
parent | 6a2d513a4ad116fc5405d4d4f1f6fdb692bdefbc (diff) |
Tweak the galaxy
Diffstat (limited to 'libs/rs/rsScriptC_Lib.cpp')
-rw-r--r-- | libs/rs/rsScriptC_Lib.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp index 0ecdf9a06998..5f8ee2a9ec80 100644 --- a/libs/rs/rsScriptC_Lib.cpp +++ b/libs/rs/rsScriptC_Lib.cpp @@ -170,6 +170,44 @@ static void SC_storeMatrix(uint32_t bank, uint32_t offset, const rsc_Matrix *m) #define DEG_TO_RAD PI / 180.0f #define RAD_TO_DEG 180.0f / PI +static float SC_sinf_fast(float x) +{ + const float A = 1.0f / (2.0f * M_PI); + const float B = -16.0f; + const float C = 8.0f; + + // scale angle for easy argument reduction + x *= A; + + if (fabsf(x) >= 0.5f) { + // argument reduction + x = x - ceilf(x + 0.5f) + 1.0f; + } + + const float y = B * x * fabsf(x) + C * x; + return 0.2215f * (y * fabsf(y) - y) + y; +} + +static float SC_cosf_fast(float x) +{ + x += float(M_PI / 2); + + const float A = 1.0f / (2.0f * M_PI); + const float B = -16.0f; + const float C = 8.0f; + + // scale angle for easy argument reduction + x *= A; + + if (fabsf(x) >= 0.5f) { + // argument reduction + x = x - ceilf(x + 0.5f) + 1.0f; + } + + const float y = B * x * fabsf(x) + C * x; + return 0.2215f * (y * fabsf(y) - y) + y; +} + static float SC_randf(float max) { float r = (float)rand(); @@ -846,6 +884,10 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = { "int", "(int)" }, { "absf", (void *)&fabs, "float", "(float)" }, + { "sinf_fast", (void *)&SC_sinf_fast, + "float", "(float)" }, + { "cosf_fast", (void *)&SC_cosf_fast, + "float", "(float)" }, { "sinf", (void *)&sinf, "float", "(float)" }, { "cosf", (void *)&cosf, |