4 #define cross(a, b) ((a) >< (b))
6 vector cross(vector a, vector b)
9 '1 0 0' * (a.y * b.z - a.z * b.y)
10 + '0 1 0' * (a.z * b.x - a.x * b.z)
11 + '0 0 1' * (a.x * b.y - a.y * b.x);
15 const vector eX = '1 0 0';
16 const vector eY = '0 1 0';
17 const vector eZ = '0 0 1';
19 vector randompos(vector m1, vector m2)
23 v_x = m2_x * random() + m1_x;
24 v_y = m2_y * random() + m1_y;
25 v_z = m2_z * random() + m1_z;
29 float vlen2d(vector v)
31 return sqrt(v.x * v.x + v.y * v.y);
34 float vlen_maxnorm2d(vector v)
36 return max(v.x, v.y, -v.x, -v.y);
39 float vlen_minnorm2d(vector v)
41 return min(max(v.x, -v.x), max(v.y, -v.y));
44 float dist_point_line(vector p, vector l0, vector ldir)
46 ldir = normalize(ldir);
48 // remove the component in line direction
49 p = p - (p * ldir) * ldir;
51 // vlen of the remaining vector
55 /** requires that m2>m1 in all coordinates, and that m4>m3 */
56 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; }
58 /** requires the same as boxesoverlap, but is a stronger condition */
59 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; }
68 vector vec3(float x, float y, float z)
77 vector rotate(vector v, float a)
79 float a_sin = sin(a), a_cos = cos(a);
81 r.x = v.x * a_cos + v.y * a_sin;
82 r.y = -1 * v.x * a_sin + v.y * a_cos;
86 vector yinvert(vector v)
93 vector get_corner_position(entity box, int corner)
97 case 1: return vec3(box.absmin.x, box.absmin.y, box.absmin.z);
98 case 2: return vec3(box.absmax.x, box.absmin.y, box.absmin.z);
99 case 3: return vec3(box.absmin.x, box.absmax.y, box.absmin.z);
100 case 4: return vec3(box.absmin.x, box.absmin.y, box.absmax.z);
101 case 5: return vec3(box.absmax.x, box.absmax.y, box.absmin.z);
102 case 6: return vec3(box.absmin.x, box.absmax.y, box.absmax.z);
103 case 7: return vec3(box.absmax.x, box.absmin.y, box.absmax.z);
104 case 8: return vec3(box.absmax.x, box.absmax.y, box.absmax.z);
105 default: return '0 0 0';
109 vector NearestPointOnBox(entity box, vector org)
111 vector m1 = box.mins + box.origin;
112 vector m2 = box.maxs + box.origin;
115 ret.x = bound(m1.x, org.x, m2.x);
116 ret.y = bound(m1.y, org.y, m2.y);
117 ret.z = bound(m1.z, org.z, m2.z);