make the vector macros more readable

This commit is contained in:
Bill Currie 2004-04-07 02:29:41 +00:00
parent 27da4ad233
commit 524c02e97a

View file

@ -44,18 +44,59 @@ extern const vec_t * const vec3_origin;
#define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
#define DotProduct(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
#define VectorSubtract(a,b,c) do {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];} while (0)
#define VectorNegate(a,b) do {(b)[0]=-(a)[0];(b)[1]=-(a)[1];(b)[2]=-(a)[2];} while (0)
#define VectorAdd(a,b,c) do {(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];} while (0)
#define VectorCopy(a,b) do {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];} while (0)
#define VectorMult(a,b,c) do {(c)[0]=(a)[0]*(b)[0];(c)[1]=(a)[1]*(b)[1];(c)[2]=(a)[2]*(b)[2];} while (0)
#define VectorMultAdd(a,s,b,c) do {(c)[0]=(a)[0]+(s)*(b)[0];(c)[1]=(a)[1]+(s)*(b)[1];(c)[2]=(a)[2]+(s)*(b)[2];} while (0)
#define VectorMultSub(a,s,b,c) do {(c)[0]=(a)[0]-(s)*(b)[0];(c)[1]=(a)[1]-(s)*(b)[1];(c)[2]=(a)[2]-(s)*(b)[2];} while (0)
#define DotProduct(a,b) ((a)[0] * (b)[0] + (a)[1] * (b)[1] + (a)[2] * (b)[2])
#define VectorSubtract(a,b,c) \
do { \
(c)[0] = (a)[0] - (b)[0]; \
(c)[1] = (a)[1] - (b)[1]; \
(c)[2] = (a)[2] - (b)[2]; \
} while (0)
#define VectorNegate(a,b) \
do { \
(b)[0] = -(a)[0]; \
(b)[1] = -(a)[1]; \
(b)[2] = -(a)[2]; \
} while (0)
#define VectorAdd(a,b,c) \
do { \
(c)[0]=(a)[0]+(b)[0]; \
(c)[1]=(a)[1]+(b)[1]; \
(c)[2]=(a)[2]+(b)[2]; \
} while (0)
#define VectorCopy(a,b) \
do { \
(b)[0]=(a)[0]; \
(b)[1]=(a)[1]; \
(b)[2]=(a)[2]; \
} while (0)
#define VectorMult(a,b,c) \
do { \
(c)[0]=(a)[0]*(b)[0]; \
(c)[1]=(a)[1]*(b)[1]; \
(c)[2]=(a)[2]*(b)[2]; \
} while (0)
#define VectorMultAdd(a,s,b,c) \
do { \
(c)[0]=(a)[0]+(s)*(b)[0]; \
(c)[1]=(a)[1]+(s)*(b)[1]; \
(c)[2]=(a)[2]+(s)*(b)[2]; \
} while (0)
#define VectorMultSub(a,s,b,c) \
do { \
(c)[0]=(a)[0]-(s)*(b)[0]; \
(c)[1]=(a)[1]-(s)*(b)[1]; \
(c)[2]=(a)[2]-(s)*(b)[2]; \
} while (0)
#define VectorLength(a) sqrt(DotProduct(a, a))
#define VectorScale(a,b,c) do {(c)[0]=(a)[0]*(b);(c)[1]=(a)[1]*(b);(c)[2]=(a)[2]*(b);} while (0)
#define VectorCompare(x, y) (((x)[0] == (y)[0]) && ((x)[1] == (y)[1]) && ((x)[2] == (y)[2]))
#define VectorScale(a,b,c) \
do { \
(c)[0]=(a)[0]*(b); \
(c)[1]=(a)[1]*(b); \
(c)[2]=(a)[2]*(b); \
} while (0)
#define VectorCompare(x, y) \
(((x)[0] == (y)[0]) && ((x)[1] == (y)[1]) && ((x)[2] == (y)[2]))
#define VectorIsZero(a) ((a)[0] == 0 && (a)[1] == 0 && (a)[2] == 0)
#define VectorZero(a) ((a)[2] = (a)[1] = (a)[0] = 0);
@ -72,9 +113,10 @@ extern const vec_t * const vec3_origin;
* Yes, this is the same as sqrt(VectorSubtract then DotProduct),
* however that way would involve more vars, this is cheaper.
*/
#define VectorDistance_fast(a, b) ((((a)[0] - (b)[0]) * ((a)[0] - (b)[0])) + \
(((a)[1] - (b)[1]) * ((a)[1] - (b)[1])) + \
(((a)[2] - (b)[2]) * ((a)[2] - (b)[2])))
#define VectorDistance_fast(a, b) \
((((a)[0] - (b)[0]) * ((a)[0] - (b)[0])) + \
(((a)[1] - (b)[1]) * ((a)[1] - (b)[1])) + \
(((a)[2] - (b)[2]) * ((a)[2] - (b)[2])))
#define VectorDistance(a, b) sqrt(VectorDistance_fast(a, b))