4 const vector eX = '1 0 0';
5 const vector eY = '0 1 0';
6 const vector eZ = '0 0 1';
8 vector randompos(vector m1, vector m2)
12 v_x = m2_x * random() + m1_x;
13 v_y = m2_y * random() + m1_y;
14 v_z = m2_z * random() + m1_z;
18 float vlen2d(vector v)
20 return sqrt(v.x * v.x + v.y * v.y);
23 float vlen_maxnorm2d(vector v)
25 return max(v.x, v.y, -v.x, -v.y);
28 float vlen_minnorm2d(vector v)
30 return min(max(v.x, -v.x), max(v.y, -v.y));
33 float dist_point_line(vector p, vector l0, vector ldir)
35 ldir = normalize(ldir);
37 // remove the component in line direction
38 p = p - (p * ldir) * ldir;
40 // vlen of the remaining vector
44 /** requires that m2>m1 in all coordinates, and that m4>m3 */
45 float boxesoverlap(vector m1, vector m2, vector m3, vector m4) { return m2_x >= m3_x && m1_x <= m4_x && m2_y >= m3_y && m1_y <= m4_y && m2_z >= m3_z && m1_z <= m4_z; }
47 /** requires the same as boxesoverlap, but is a stronger condition */
48 float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs) { return smins.x >= bmins.x && smaxs.x <= bmaxs.x && smins.y >= bmins.y && smaxs.y <= bmaxs.y && smins.z >= bmins.z && smaxs.z <= bmaxs.z; }
57 vector vec3(float x, float y, float z)
67 vector get_corner_position(entity box, int corner)
71 case 1: return vec3(box.absmin.x, box.absmin.y, box.absmin.z);
72 case 2: return vec3(box.absmax.x, box.absmin.y, box.absmin.z);
73 case 3: return vec3(box.absmin.x, box.absmax.y, box.absmin.z);
74 case 4: return vec3(box.absmin.x, box.absmin.y, box.absmax.z);
75 case 5: return vec3(box.absmax.x, box.absmax.y, box.absmin.z);
76 case 6: return vec3(box.absmin.x, box.absmax.y, box.absmax.z);
77 case 7: return vec3(box.absmax.x, box.absmin.y, box.absmax.z);
78 case 8: return vec3(box.absmax.x, box.absmax.y, box.absmax.z);
79 default: return '0 0 0';
83 vector NearestPointOnBox(entity box, vector org)
85 vector m1 = box.mins + box.origin;
86 vector m2 = box.maxs + box.origin;
89 ret.x = bound(m1.x, org.x, m2.x);
90 ret.y = bound(m1.y, org.y, m2.y);
91 ret.z = bound(m1.z, org.z, m2.z);