diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-04-14 16:44:03 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-04-14 16:46:03 -0600 |
commit | dfd6bc3c91c7bd508b5bde820366784bd980a677 (patch) | |
tree | df44a1950dd589cad9eb08345fec5ab2457adba2 /src/gui/status.cpp | |
parent | 87d906c4f3529e7ce8f836876292efbfbe765990 (diff) | |
download | mana-client-dfd6bc3c91c7bd508b5bde820366784bd980a677.tar.gz mana-client-dfd6bc3c91c7bd508b5bde820366784bd980a677.tar.bz2 mana-client-dfd6bc3c91c7bd508b5bde820366784bd980a677.tar.xz mana-client-dfd6bc3c91c7bd508b5bde820366784bd980a677.zip |
Start a MathUtils file
It has fast(inv)sqrt and weightedAverage.
Also cleanup the last ocmmit a bit.
Diffstat (limited to 'src/gui/status.cpp')
-rw-r--r-- | src/gui/status.cpp | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 9d85a317..27269acf 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -34,6 +34,7 @@ #include "net/ea/playerhandler.h" #include "utils/gettext.h" +#include "utils/mathutils.h" #include "utils/strprintf.h" #include "utils/stringutils.h" @@ -308,22 +309,22 @@ void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) { r1 = 0xcc; g1 = 0x00; b1 = 0x00; r2 = 0xcc; g2 = 0xcc; b2 = 0x00; - weight = (float)(curHP-(thresholdLevel)) / (float)thresholdLevel; + weight = (float) (curHP - (thresholdLevel)) / (float) thresholdLevel; // Reddish Brown -> Red } else if (curHP < thresholdLevel*2) { r1 = 0xcc; g1 = 0xcc; b1 = 0x00; r2 = 0xff; g2 = 0xcc; b2 = 0x00; - weight = (float)(curHP-(thresholdLevel*2)) / (float)thresholdLevel; - // Orange->Reddish Brown + weight = (float) (curHP - (thresholdLevel * 2)) / (float) thresholdLevel; + // Orange -> Reddish Brown } else { r1 = 0xff; g1 = 0xcc; b1 = 0x00; r2 = 0x99; g2 = 0xff; b2 = 0x99; - weight = (float)(curHP-(thresholdLevel*3)) / (float)thresholdLevel; - // Green ->Orange + weight = (float) (curHP - (thresholdLevel * 3)) / (float) thresholdLevel; + // Green -> Orange } //safety checks @@ -331,27 +332,20 @@ void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) if (weight<0.0f) weight=0.0f; //Do the color blend - r1 = (int)weightedAverage(r1,r2,weight); - g1 = (int)weightedAverage(g1,g2,weight); - b1 = (int)weightedAverage(b1,b2,weight); + r1 = (int) weightedAverage(r1, r2, weight); + g1 = (int) weightedAverage(g1, g2, weight); + b1 = (int) weightedAverage(b1, b2, weight); //more safety checks - if (r1>255) r1=255; - if (g1>255) g1=255; - if (b1>255) b1=255; + if (r1 > 255) r1 = 255; + if (g1 > 255) g1 = 255; + if (b1 > 255) b1 = 255; - bar->setColor(r1,g1,b1); + bar->setColor(r1, g1, b1); bar->setProgress((float) player_node->getHp() / (float) player_node->getMaxHp()); } -float StatusWindow::weightedAverage(float n1, float n2, float w) { - if (w<0.0f) return n1; - if (w>1.0f) return n2; - - return (w*n2 + (1.0f-w)*n1) / 2.0f; -} - void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) { if (showMax) |