diff options
| author | oy <Tom_Adams@web.de> | 2011-01-04 11:58:25 +0100 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-01-04 11:58:25 +0100 |
| commit | bcba9e5c89fad11afc34e2f9c0124edf2d0da74f (patch) | |
| tree | 0f3cf517e6f3bdeb69ac614f2e1361332ea03483 /src | |
| parent | 336f00ae89be5051be20632c728076a436d93d3c (diff) | |
| download | zcatch-bcba9e5c89fad11afc34e2f9c0124edf2d0da74f.tar.gz zcatch-bcba9e5c89fad11afc34e2f9c0124edf2d0da74f.zip | |
moved HslToRgb stuff
Diffstat (limited to 'src')
| -rw-r--r-- | src/game/client/components/menus.cpp | 38 | ||||
| -rw-r--r-- | src/game/client/components/skins.cpp | 41 | ||||
| -rw-r--r-- | src/game/client/gameclient.h | 25 |
3 files changed, 26 insertions, 78 deletions
diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 6d3c494e..f06543a9 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -41,44 +41,6 @@ float CMenus::ms_FontmodHeight = 0.8f; IInput::CEvent CMenus::m_aInputEvents[MAX_INPUTEVENTS]; int CMenus::m_NumInputEvents; -inline float HueToRgb(float v1, float v2, float h) -{ - if(h < 0) h += 1; - if(h > 1) h -= 1; - if((6 * h) < 1) return v1 + ( v2 - v1 ) * 6 * h; - if((2 * h) < 1) return v2; - if((3 * h) < 2) return v1 + ( v2 - v1 ) * ((2.0f/3.0f) - h) * 6; - return v1; -} - -inline vec3 HslToRgb(vec3 In) -{ - float v1, v2; - vec3 Out; - - if(In.s == 0) - { - Out.r = In.l; - Out.g = In.l; - Out.b = In.l; - } - else - { - if(In.l < 0.5f) - v2 = In.l * (1 + In.s); - else - v2 = (In.l+In.s) - (In.s*In.l); - - v1 = 2 * In.l - v2; - - Out.r = HueToRgb(v1, v2, In.h + (1.0f/3.0f)); - Out.g = HueToRgb(v1, v2, In.h); - Out.b = HueToRgb(v1, v2, In.h - (1.0f/3.0f)); - } - - return Out; -} - CMenus::CMenus() { diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index 9c39e9ad..16135164 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -140,45 +140,6 @@ int CSkins::Find(const char *pName) return -1; } -// these converter functions were nicked from some random internet pages -static float HueToRgb(float v1, float v2, float h) -{ - if(h < 0) h += 1; - if(h > 1) h -= 1; - if((6 * h) < 1) return v1 + ( v2 - v1 ) * 6 * h; - if((2 * h) < 1) return v2; - if((3 * h) < 2) return v1 + ( v2 - v1 ) * ((2.0f/3.0f) - h) * 6; - return v1; -} - -static vec3 HslToRgb(vec3 in) -{ - float v1, v2; - vec3 Out; - - if(in.s == 0) - { - Out.r = in.l; - Out.g = in.l; - Out.b = in.l; - } - else - { - if(in.l < 0.5f) - v2 = in.l * (1 + in.s); - else - v2 = (in.l+in.s) - (in.s*in.l); - - v1 = 2 * in.l - v2; - - Out.r = HueToRgb(v1, v2, in.h + (1.0f/3.0f)); - Out.g = HueToRgb(v1, v2, in.h); - Out.b = HueToRgb(v1, v2, in.h - (1.0f/3.0f)); - } - - return Out; -} - vec3 CSkins::GetColorV3(int v) { return HslToRgb(vec3(((v>>16)&0xff)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f)); @@ -186,6 +147,6 @@ vec3 CSkins::GetColorV3(int v) vec4 CSkins::GetColorV4(int v) { - vec3 r = HslToRgb(vec3(((v>>16)&0xff)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f)); + vec3 r = GetColorV3(v); return vec4(r.r, r.g, r.b, 1.0f); } diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 2f8e21ea..5ee2c989 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -212,6 +212,31 @@ public: class CScoreboard *m_pScoreboard; }; + +inline float HueToRgb(float v1, float v2, float h) +{ + if(h < 0.0f) h += 1; + if(h > 1.0f) h -= 1; + if((6.0f * h) < 1.0f) return v1 + (v2 - v1) * 6.0f * h; + if((2.0f * h) < 1.0f) return v2; + if((3.0f * h) < 2.0f) return v1 + (v2 - v1) * ((2.0f/3.0f) - h) * 6.0f; + return v1; +} + +inline vec3 HslToRgb(vec3 HSL) +{ + if(HSL.s == 0.0f) + return vec3(HSL.l, HSL.l, HSL.l); + else + { + float v2 = HSL.l < 0.5f ? HSL.l * (1.0f + HSL.s) : (HSL.l+HSL.s) - (HSL.s*HSL.l); + float v1 = 2.0f * HSL.l - v2; + + return vec3(HueToRgb(v1, v2, HSL.h + (1.0f/3.0f)), HueToRgb(v1, v2, HSL.h), HueToRgb(v1, v2, HSL.h - (1.0f/3.0f))); + } +} + + extern const char *Localize(const char *Str); #endif |