]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/vector.qh
Merge branch 'master' into TimePath/csqc_viewmodels
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / vector.qh
index 9813f2fa92d54b9ef2ccb9c1465e2d1e4c0eef3b..776bf6eedb888c8fd0df39b4d37b3ca0321894ca 100644 (file)
@@ -1,6 +1,31 @@
 #ifndef VECTOR_H
 #define VECTOR_H
 
+noref vector _vlen2;
+#define vlen2(v) \
+       (_vlen2 = (v), \
+         _vlen2.x * _vlen2.x \
+       + _vlen2.y * _vlen2.y \
+       + _vlen2.z * _vlen2.z)
+
+noref float _vdist_f;
+/** Vector distance comparison, avoids sqrt() */
+#define vdist(v, cmp, f) (vlen2(v) cmp (_vdist_f = (f), _vdist_f * _vdist_f))
+/*
+#define vdist(v, cmp, f) (vlen(v) cmp (f))
+*/
+
+#define cross(a, b) ((a) >< (b))
+/*
+vector cross(vector a, vector b)
+{
+       return
+               '1 0 0' * (a.y * b.z - a.z * b.y)
+       +       '0 1 0' * (a.z * b.x - a.x * b.z)
+       +       '0 0 1' * (a.x * b.y - a.y * b.x);
+}
+*/
+
 const vector eX = '1 0 0';
 const vector eY = '0 1 0';
 const vector eZ = '0 0 1';
@@ -15,11 +40,6 @@ vector randompos(vector m1, vector m2)
        return v;
 }
 
-float vlen2d(vector v)
-{
-       return sqrt(v.x * v.x + v.y * v.y);
-}
-
 float vlen_maxnorm2d(vector v)
 {
        return max(v.x, v.y, -v.x, -v.y);
@@ -58,20 +78,11 @@ float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs) { ret
        up = v_up; \
 } while (0)
 
-vector vec2(vector v)
-{
-       v.z = 0;
-       return v;
-}
+noref vector _vec2;
+#define vec2(v) (_vec2 = (v), _vec2.z = 0, _vec2)
 
-vector vec3(float x, float y, float z)
-{
-       vector v;
-       v.x = x;
-       v.y = y;
-       v.z = z;
-       return v;
-}
+noref vector _vec3;
+#define vec3(x, y, z) (_vec3_x = (x), _vec3_y = (y), _vec3_z = (z), _vec3)
 
 vector rotate(vector v, float a)
 {
@@ -82,11 +93,8 @@ vector rotate(vector v, float a)
        return r;
 }
 
-vector yinvert(vector v)
-{
-       v.y = 1 - v.y;
-       return v;
-}
+noref vector _yinvert;
+#define yinvert(v) (_yinvert = (v), _yinvert.y = 1 - _yinvert.y, _yinvert)
 
 #ifndef MENUQC
        vector get_corner_position(entity box, int corner)