about summary refs log tree commit diff
path: root/src/game/g_vmath.h
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-03-19 23:08:26 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-03-19 23:08:26 +0000
commit6c972078ca1f5951b5e442fefb16a8e0b69b60c5 (patch)
tree7ed2bd8f480531bf891edaf2fa1166d4595bc4ad /src/game/g_vmath.h
parent7229789d58726ccea5c462dbe35a65f7388da658 (diff)
downloadzcatch-6c972078ca1f5951b5e442fefb16a8e0b69b60c5.tar.gz
zcatch-6c972078ca1f5951b5e442fefb16a8e0b69b60c5.zip
fixed non-intersecting hook problem. hook length is more visible now. fixed damange system (thanks to shootme)
Diffstat (limited to 'src/game/g_vmath.h')
-rw-r--r--src/game/g_vmath.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/game/g_vmath.h b/src/game/g_vmath.h
index db7f4a50..ac3e1870 100644
--- a/src/game/g_vmath.h
+++ b/src/game/g_vmath.h
@@ -65,6 +65,21 @@ inline vector2_base<T> normalize(const vector2_base<T> &v)
 typedef vector2_base<float> vec2;
 typedef vector2_base<bool> bvec2;
 typedef vector2_base<int> ivec2;
+
+template<typename T>
+inline vector2_base<T> closest_point_on_line(vector2_base<T> line_point0, vector2_base<T> line_point1, vector2_base<T> target_point)
+{
+	vector2_base<T> c = target_point - line_point0;
+	vector2_base<T> v = (line_point1 - line_point0);
+	v = normalize(v);
+	T d = length(line_point0-line_point1);
+	T t = dot(v, c)/d;
+	return mix(line_point0, line_point1, clamp(t, (T)0, (T)1));
+	/*
+	if (t < 0) t = 0;
+	if (t > 1.0f) return 1.0f;
+	return t;*/
+}
 	
 // ------------------------------------
 template<typename T>