Skip to content

Commit 8195fd5

Browse files
committed
Fix minor bug with parallel vector testing
1 parent e8d21a0 commit 8195fd5

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

code/math/vecmat.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,16 @@ vec3d *vm_vec_cross(vec3d *dest, const vec3d *src0, const vec3d *src1)
615615
return dest;
616616
}
617617

618-
// test if 2 vectors are parallel or not.
619618
int vm_test_parallel(const vec3d *src0, const vec3d *src1)
620619
{
621-
if ( (fl_abs(src0->xyz.x - src1->xyz.x) < 1e-4) && (fl_abs(src0->xyz.y - src1->xyz.y) < 1e-4) && (fl_abs(src0->xyz.z - src1->xyz.z) < 1e-4) ) {
622-
return 1;
623-
} else {
624-
return 0;
625-
}
620+
// This version assumes SIMD/SSE optimizations, which would essentially be only 2 operations
621+
// If SIMD/SSE is not available, you could check if the vectors are a scalar of each other. i.g. if((x1/x2) == (y1/y2) == (z1/z2)
622+
// TODO: make a compile-time check for SIMD/SSE optimizations, If we have them, then use the vecmath method, if not, then use the logical method.
623+
624+
vec3d test;
625+
626+
vm_vec_cross(&test, src0, src1);
627+
return vm_vec_equal(test, vmd_zero_vector);
626628
}
627629

628630
//computes non-normalized surface normal from three points.

code/math/vecmat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ float vm_vec_dot3(float x, float y, float z, vec3d *v);
204204
//dest CANNOT equal either source
205205
vec3d *vm_vec_cross(vec3d *dest, const vec3d *src0, const vec3d *src1);
206206

207-
// test if 2 vectors are parallel or not.
207+
/**
208+
* @brief Tests if the two vectors are parallel
209+
*/
208210
int vm_test_parallel(const vec3d *src0, const vec3d *src1);
209211

210212
//computes surface normal from three points. result is normalized

0 commit comments

Comments
 (0)