about summary refs log tree commit diff
path: root/src/game/client/cl_skin.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-11-18 14:24:34 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-11-18 14:24:34 +0000
commitd4d1691fea007b04ad21686e8622efbbe53e9768 (patch)
tree5f7fcde7a4a3ef5efb4c9c09835ba561e6b2337e /src/game/client/cl_skin.cpp
parentdda8f6b33ee05acdf23883c91a0897a464b84061 (diff)
downloadzcatch-d4d1691fea007b04ad21686e8622efbbe53e9768.tar.gz
zcatch-d4d1691fea007b04ad21686e8622efbbe53e9768.zip
fixed so that the skins are sent over correctly and that team color overrides everything
Diffstat (limited to 'src/game/client/cl_skin.cpp')
-rw-r--r--src/game/client/cl_skin.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/game/client/cl_skin.cpp b/src/game/client/cl_skin.cpp
index 6e450b4f..292b0a99 100644
--- a/src/game/client/cl_skin.cpp
+++ b/src/game/client/cl_skin.cpp
@@ -80,3 +80,50 @@ int skin_find(const char *name)
 	return -1;
 }
 
+
+
+
+// these converter functions were nicked from some random internet pages
+static float hue_to_rgb(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;
+}
+
+vec3 hsl_to_rgb(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 = hue_to_rgb(v1, v2, in.h + (1.0f/3.0f));
+		out.g = hue_to_rgb(v1, v2, in.h);
+		out.b = hue_to_rgb(v1, v2, in.h - (1.0f/3.0f));
+	} 
+
+	return out;
+}
+
+vec4 skin_get_color(int v)
+{
+	vec3 r = hsl_to_rgb(vec3((v>>16)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f));
+	return vec4(r.r, r.g, r.b, 1.0f);
+}