+#define VectorScale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale))
+#define VectorCompare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])&&((a)[2]==(b)[2]))
+#define VectorMA(a, scale, b, c) ((c)[0] = (a)[0] + (scale) * (b)[0],(c)[1] = (a)[1] + (scale) * (b)[1],(c)[2] = (a)[2] + (scale) * (b)[2])
+#define VectorNormalizeFast(_v)\
+{\
+ float _y, _number;\
+ _number = DotProduct(_v, _v);\
+ if (_number != 0.0)\
+ {\
+ *((long *)&_y) = 0x5f3759df - ((* (long *) &_number) >> 1);\
+ _y = _y * (1.5f - (_number * 0.5f * _y * _y));\
+ VectorScale(_v, _y, _v);\
+ }\
+}
+#define VectorRandom(v) {do{(v)[0] = lhrandom(-1, 1);(v)[1] = lhrandom(-1, 1);(v)[2] = lhrandom(-1, 1);}while(DotProduct(v, v) > 1);}
+
+// LordHavoc: quaternion math, untested, don't know if these are correct,
+// need to add conversion to/from matrices
+
+// returns length of quaternion
+#define qlen(a) ((float) sqrt((a)[0]*(a)[0]+(a)[1]*(a)[1]+(a)[2]*(a)[2]+(a)[3]*(a)[3]))
+// returns squared length of quaternion
+#define qlen2(a) ((a)[0]*(a)[0]+(a)[1]*(a)[1]+(a)[2]*(a)[2]+(a)[3]*(a)[3])
+// makes a quaternion from x, y, z, and a rotation angle (in degrees)
+// FIXME: this is almost definitely broken, need a rewrite
+#define QuatMake(x,y,z,r,c)\
+{\
+r2 = (r) * M_PI / 360;\
+if (r == 0)\
+{\
+(c)[0]=(float) ((x)*sin(r2));\
+(c)[1]=(float) ((y)*sin(r2));\
+(c)[2]=(float) ((z)*sin(r2));\
+(c)[3]=(float) 1;\
+}\
+else\
+{\
+float r2 = (r) * 0.5 * (M_PI / 180);\
+(c)[0]=(float) ((x)*sin(r2));\
+(c)[1]=(float) ((y)*sin(r2));\
+(c)[2]=(float) ((z)*sin(r2));\
+(c)[3]=(float) (cos(r2));\
+}\
+}
+// makes a quaternion from a vector and a rotation angle (in degrees)
+#define QuatFromVec(a,r,c) QuatMake((a)[0],(a)[1],(a)[2],(r))
+// copies a quaternion
+#define QuatCopy(a,c) {(c)[0]=(a)[0];(c)[1]=(a)[1];(c)[2]=(a)[2];(c)[3]=(a)[3];}
+#define QuatSubtract(a,b,c) {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];(c)[3]=(a)[3]-(b)[3];}
+#define QuatAdd(a,b,c) {(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];(c)[3]=(a)[3]+(b)[3];}
+#define QuatScale(a,b,c) {(c)[0]=(a)[0]*b;(c)[1]=(a)[1]*b;(c)[2]=(a)[2]*b;(c)[3]=(a)[3]*b;}
+// FIXME: this is wrong, do some more research on quaternions
+//#define QuatMultiply(a,b,c) {(c)[0]=(a)[0]*(b)[0];(c)[1]=(a)[1]*(b)[1];(c)[2]=(a)[2]*(b)[2];(c)[3]=(a)[3]*(b)[3];}
+// FIXME: this is wrong, do some more research on quaternions
+//#define QuatMultiplyAdd(a,b,d,c) {(c)[0]=(a)[0]*(b)[0]+d[0];(c)[1]=(a)[1]*(b)[1]+d[1];(c)[2]=(a)[2]*(b)[2]+d[2];(c)[3]=(a)[3]*(b)[3]+d[3];}
+#define qdist(a,b) ((float) sqrt(((b)[0]-(a)[0])*((b)[0]-(a)[0])+((b)[1]-(a)[1])*((b)[1]-(a)[1])+((b)[2]-(a)[2])*((b)[2]-(a)[2])+((b)[3]-(a)[3])*((b)[3]-(a)[3])))
+#define qdist2(a,b) (((b)[0]-(a)[0])*((b)[0]-(a)[0])+((b)[1]-(a)[1])*((b)[1]-(a)[1])+((b)[2]-(a)[2])*((b)[2]-(a)[2])+((b)[3]-(a)[3])*((b)[3]-(a)[3]))
+
+#define VectorCopy4(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];(b)[3]=(a)[3];}