From: Mario Date: Thu, 31 Dec 2015 08:00:47 +0000 (+1000) Subject: Strip some handy lib functions out of turret util code X-Git-Tag: xonotic-v0.8.2~1351 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f2c96017370447327508b7021883c8e50a5732c7;p=xonotic%2Fxonotic-data.pk3dir.git Strip some handy lib functions out of turret util code --- diff --git a/qcsrc/common/turrets/util.qc b/qcsrc/common/turrets/util.qc index c56ba66e9..17f42c811 100644 --- a/qcsrc/common/turrets/util.qc +++ b/qcsrc/common/turrets/util.qc @@ -1,114 +1,3 @@ -/* -* Return a angle within +/- 360. -*/ -float anglemods(float v) -{ - v = v - 360 * floor(v / 360); - - if(v >= 180) - return v - 360; - else if(v <= -180) - return v + 360; - else - return v; -} - -/* -* Return the short angle -*/ -float shortangle_f(float ang1, float ang2) -{ - if(ang1 > ang2) - { - if(ang1 > 180) - return ang1 - 360; - } - else - { - if(ang1 < -180) - return ang1 + 360; - } - - return ang1; -} - -vector shortangle_v(vector ang1, vector ang2) -{ - vector vtmp; - - vtmp_x = shortangle_f(ang1_x,ang2_x); - vtmp_y = shortangle_f(ang1_y,ang2_y); - vtmp_z = shortangle_f(ang1_z,ang2_z); - - return vtmp; -} - -vector shortangle_vxy(vector ang1, vector ang2) -{ - vector vtmp = '0 0 0'; - - vtmp_x = shortangle_f(ang1_x,ang2_x); - vtmp_y = shortangle_f(ang1_y,ang2_y); - - return vtmp; -} - - -/* -* Get "real" origin, in worldspace, even if ent is attached to something else. -*/ -vector real_origin(entity ent) -{ - entity e; - vector v = ((ent.absmin + ent.absmax) * 0.5); - - e = ent.tag_entity; - while(e) - { - v = v + ((e.absmin + e.absmax) * 0.5); - e = e.tag_entity; - } - - return v; -} - -/* -* Return the angle between two enteties -*/ -vector angleofs(entity from, entity to) -{ - vector v_res; - - v_res = normalize(to.origin - from.origin); - v_res = vectoangles(v_res); - v_res = v_res - from.angles; - - if (v_res_x < 0) v_res_x += 360; - if (v_res_x > 180) v_res_x -= 360; - - if (v_res_y < 0) v_res_y += 360; - if (v_res_y > 180) v_res_y -= 360; - - return v_res; -} - -vector angleofs3(vector from, vector from_a, entity to) -{ - vector v_res; - - v_res = normalize(to.origin - from); - v_res = vectoangles(v_res); - v_res = v_res - from_a; - - if (v_res_x < 0) v_res_x += 360; - if (v_res_x > 180) v_res_x -= 360; - - if (v_res_y < 0) v_res_y += 360; - if (v_res_y > 180) v_res_y -= 360; - - return v_res; -} - /* * Update self.tur_shotorg by getting up2date bone info * NOTICE this func overwrites the global v_forward, v_right and v_up vectors. diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 52df2b647..55a5274f4 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -18,6 +18,26 @@ #include "mapinfo.qh" #endif +#ifndef MENUQC +/* +* Get "real" origin, in worldspace, even if ent is attached to something else. +*/ +vector real_origin(entity ent) +{ + entity e; + vector v = ((ent.absmin + ent.absmax) * 0.5); + + e = ent.tag_entity; + while(e) + { + v = v + ((e.absmin + e.absmax) * 0.5); + e = e.tag_entity; + } + + return v; +} +#endif + string wordwrap_buffer; void wordwrap_buffer_put(string s) diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index a9f3a9ffa..bf2bb1be9 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -1,6 +1,8 @@ #ifndef COMMON_UTIL_H #define COMMON_UTIL_H +vector real_origin(entity ent); + // this returns a tempstring containing a copy of s with additional \n newlines added, it also replaces \n in the text with a real newline // NOTE: s IS allowed to be a tempstring string wordwrap(string s, float l); diff --git a/qcsrc/lib/_all.inc b/qcsrc/lib/_all.inc index 31d70ffe4..307b4bd08 100644 --- a/qcsrc/lib/_all.inc +++ b/qcsrc/lib/_all.inc @@ -30,6 +30,7 @@ #include "warpzone/mathlib.qc" #include "accumulate.qh" +#include "angle.qc" #include "arraylist.qh" #include "bits.qh" #include "bool.qh" diff --git a/qcsrc/lib/angle.qc b/qcsrc/lib/angle.qc new file mode 100644 index 000000000..f921d74b0 --- /dev/null +++ b/qcsrc/lib/angle.qc @@ -0,0 +1,94 @@ +.vector origin; +.vector angles; + +/* +* Return a angle within +/- 360. +*/ +float anglemods(float v) +{ + v = v - 360 * floor(v / 360); + + if(v >= 180) + return v - 360; + else if(v <= -180) + return v + 360; + else + return v; +} + +/* +* Return the short angle +*/ +float shortangle_f(float ang1, float ang2) +{ + if(ang1 > ang2) + { + if(ang1 > 180) + return ang1 - 360; + } + else + { + if(ang1 < -180) + return ang1 + 360; + } + + return ang1; +} + +vector shortangle_v(vector ang1, vector ang2) +{ + vector vtmp; + + vtmp_x = shortangle_f(ang1_x,ang2_x); + vtmp_y = shortangle_f(ang1_y,ang2_y); + vtmp_z = shortangle_f(ang1_z,ang2_z); + + return vtmp; +} + +vector shortangle_vxy(vector ang1, vector ang2) +{ + vector vtmp = '0 0 0'; + + vtmp_x = shortangle_f(ang1_x,ang2_x); + vtmp_y = shortangle_f(ang1_y,ang2_y); + + return vtmp; +} + +/* +* Return the angle between two enteties +*/ +vector angleofs(entity from, entity to) +{ + vector v_res; + + v_res = normalize(to.origin - from.origin); + v_res = vectoangles(v_res); + v_res = v_res - from.angles; + + if (v_res_x < 0) v_res_x += 360; + if (v_res_x > 180) v_res_x -= 360; + + if (v_res_y < 0) v_res_y += 360; + if (v_res_y > 180) v_res_y -= 360; + + return v_res; +} + +vector angleofs3(vector from, vector from_a, entity to) +{ + vector v_res; + + v_res = normalize(to.origin - from); + v_res = vectoangles(v_res); + v_res = v_res - from_a; + + if (v_res_x < 0) v_res_x += 360; + if (v_res_x > 180) v_res_x -= 360; + + if (v_res_y < 0) v_res_y += 360; + if (v_res_y > 180) v_res_y -= 360; + + return v_res; +}