From 0d55476711737f72e4d985568a652aefe0883a54 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 29 Aug 2001 20:19:54 +0000 Subject: [PATCH] make VectorSubtract and VectorCompare macros and clean up the readability of R_DrawParticles --- include/QF/mathlib.h | 7 +++-- libs/util/mathlib.c | 4 +-- libs/video/renderer/gl/gl_dyn_part.c | 38 ++++++++-------------------- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/include/QF/mathlib.h b/include/QF/mathlib.h index 8d6de7f66..266b2ad6c 100644 --- a/include/QF/mathlib.h +++ b/include/QF/mathlib.h @@ -48,6 +48,9 @@ extern int nanmask; #define VectorMA(a,s,b,c) {(c)[0]=(a)[0]+(s)*(b)[0];(c)[1]=(a)[1]+(s)*(b)[1];(c)[2]=(a)[2]+(s)*(b)[2];} #define Length(a) sqrt(DotProduct(a, a)) +#define VectorScale(a,b,c) {(c)[0]=(a)[0]*(b);(c)[1]=(a)[1]*(b);(c)[2]=(a)[2]*(b);} +#define VectorCompare(x, y) ((x[0] == y[0]) && (x[1] == y[1]) && (x[2] == y[2])) + /* * VectorDistance, the distance between two points. * Yes, this is the same as sqrt(VectorSubtract then DotProduct), @@ -75,12 +78,12 @@ void _VectorSubtract (vec3_t veca, vec3_t vecb, vec3_t out); void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out); void _VectorCopy (vec3_t in, vec3_t out); -int VectorCompare (vec3_t v1, vec3_t v2); +int _VectorCompare (vec3_t v1, vec3_t v2); //vec_t Length (vec3_t v); void CrossProduct (const vec3_t v1, const vec3_t v2, vec3_t cross); float VectorNormalize (vec3_t v); // returns vector length void VectorInverse (vec3_t v); -void VectorScale (vec3_t in, vec_t scale, vec3_t out); +void _VectorScale (vec3_t in, vec_t scale, vec3_t out); int Q_log2(int val); void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]); diff --git a/libs/util/mathlib.c b/libs/util/mathlib.c index 42dc29b6e..fc4b9ad6b 100644 --- a/libs/util/mathlib.c +++ b/libs/util/mathlib.c @@ -369,7 +369,7 @@ AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) } int -VectorCompare (vec3_t v1, vec3_t v2) +_VectorCompare (vec3_t v1, vec3_t v2) { int i; @@ -470,7 +470,7 @@ VectorInverse (vec3_t v) } void -VectorScale (vec3_t in, vec_t scale, vec3_t out) +_VectorScale (vec3_t in, vec_t scale, vec3_t out) { out[0] = in[0] * scale; out[1] = in[1] * scale; diff --git a/libs/video/renderer/gl/gl_dyn_part.c b/libs/video/renderer/gl/gl_dyn_part.c index 7f1504bec..f847e675d 100644 --- a/libs/video/renderer/gl/gl_dyn_part.c +++ b/libs/video/renderer/gl/gl_dyn_part.c @@ -562,7 +562,7 @@ R_DrawParticles (void) float scale; particle_t *part; vec3_t up, right, o_up, o_right; - vec3_t up_scale, right_scale, up_right_scale; + vec3_t up_scale, right_scale, up_right_scale, down_right_scale; int activeparticles, maxparticle, j, k; // LordHavoc: particles should not affect zbuffer @@ -603,8 +603,7 @@ R_DrawParticles (void) at = (byte *) & d_8to24table[(byte) part->color]; alpha = part->alpha; -#define mVectorCompare(x, y) ((x[0] == y[0]) && (x[1] == y[1]) && (x[2] == y[2])) - if (mVectorCompare(part->up, part->right)) { + if (VectorCompare(part->up, part->right)) { memcpy(up, o_up, sizeof(up)); memcpy(right, o_right, sizeof(right)); } else { @@ -623,33 +622,16 @@ R_DrawParticles (void) scale = part->scale; - up_scale[0] = up[0] * scale; - up_scale[1] = up[1] * scale; - up_scale[2] = up[2] * scale; + VectorScale (up, scale, up_scale); + VectorScale (right, scale, right_scale); - right_scale[0] = right[0] * scale; - right_scale[1] = right[1] * scale; - right_scale[2] = right[2] * scale; + VectorAdd (right_scale, up_scale, up_right_scale); + VectorSubtract (right_scale, up_scale, down_right_scale); - up_right_scale[0] = (up[0] + right[0]) * scale; - up_right_scale[1] = (up[1] + right[1]) * scale; - up_right_scale[2] = (up[2] + right[2]) * scale; - - varray[0].vertex[0] = part->org[0] + up_right_scale[0]; - varray[0].vertex[1] = part->org[1] + up_right_scale[1]; - varray[0].vertex[2] = part->org[2] + up_right_scale[2]; - - varray[1].vertex[0] = part->org[0] - up_scale[0] + right_scale[0]; - varray[1].vertex[1] = part->org[1] - up_scale[1] + right_scale[1]; - varray[1].vertex[2] = part->org[2] - up_scale[2] + right_scale[2]; - - varray[2].vertex[0] = part->org[0] - up_right_scale[0]; - varray[2].vertex[1] = part->org[1] - up_right_scale[1]; - varray[2].vertex[2] = part->org[2] - up_right_scale[2]; - - varray[3].vertex[0] = part->org[0] + up_scale[0] - right_scale[0]; - varray[3].vertex[1] = part->org[1] + up_scale[1] - right_scale[1]; - varray[3].vertex[2] = part->org[2] + up_scale[2] - right_scale[2]; + VectorAdd (part->org, up_right_scale, varray[0].vertex); + VectorAdd (part->org, down_right_scale, varray[1].vertex); + VectorSubtract (part->org, up_right_scale, varray[2].vertex); + VectorSubtract (part->org, down_right_scale, varray[3].vertex); qfglBindTexture (GL_TEXTURE_2D, part->tex); qfglDrawArrays (GL_QUADS, 0, 4);