Fix vec3_ortho

This commit is contained in:
Sundaram Ramaswamy
2021-06-09 23:11:19 +05:30
parent afdcae08dd
commit 2e8162b133
4 changed files with 22 additions and 12 deletions

View File

@@ -474,6 +474,9 @@ Functions documentation
possible orthogonal/perpendicular vector possible orthogonal/perpendicular vector
References:
* `On picking an orthogonal vector (and combing coconuts) <http://lolengine.net/blog/2013/09/21/picking-orthogonal-vector-combing-coconuts>`_
Parameters: Parameters:
| *[in]* **v** vector | *[in]* **v** vector
| *[out]* **dest** orthogonal/perpendicular vector | *[out]* **dest** orthogonal/perpendicular vector

View File

@@ -807,9 +807,10 @@ glm_vec3_minv(vec3 a, vec3 b, vec3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_vec3_ortho(vec3 v, vec3 dest) { glm_vec3_ortho(vec3 v, vec3 dest) {
dest[0] = v[1] - v[2]; float ignore;
dest[1] = v[2] - v[0]; float f = modff(fabsf(v[0]) + 0.5f, &ignore);
dest[2] = v[0] - v[1]; vec3 result = {-v[1], v[0] - f * v[2], f * v[1]};
glm_vec3_copy(result, dest);
} }
/*! /*!

View File

@@ -79,22 +79,20 @@ main(int argc, const char * argv[]) {
if (failed == 0) { if (failed == 0) {
fprintf(stderr, fprintf(stderr,
BOLDGREEN "\n All tests are passed " FINAL_TEXT "\n" RESET); BOLDGREEN "\n All tests passed " FINAL_TEXT "\n" RESET);
} }
fprintf(stderr, fprintf(stderr,
CYAN "\ncglm test results (%0.2fs):\n" RESET CYAN "\ncglm test results (%0.2fs):\n" RESET
"--------------------------\n" "--------------------------\n"
MAGENTA "%d" RESET " tests are runned, " MAGENTA "%d" RESET " tests ran, "
GREEN "%d" RESET " %s passed, " GREEN "%d" RESET " passed, "
RED "%d" RESET " %s failed\n\n" RESET, RED "%d" RESET " failed\n\n" RESET,
total, total,
count, count,
passed, passed,
passed > 1 ? "are" : "is", failed);
failed,
failed > 1 ? "are" : "is");
return failed; return failed;
} }

View File

@@ -1123,8 +1123,8 @@ TEST_IMPL(GLM_PREFIX, vec3_minv) {
} }
TEST_IMPL(GLM_PREFIX, vec3_ortho) { TEST_IMPL(GLM_PREFIX, vec3_ortho) {
vec3 v1, v2, v3; vec3 v1, v2, v3, v4 = {1.f, 1.f, 1.f};
vec3 v5, v6, v7; vec3 v5, v6, v7, v8;
float a; float a;
test_rand_vec3(v1); test_rand_vec3(v1);
@@ -1134,6 +1134,7 @@ TEST_IMPL(GLM_PREFIX, vec3_ortho) {
GLM(vec3_ortho)(v1, v5); GLM(vec3_ortho)(v1, v5);
GLM(vec3_ortho)(v2, v6); GLM(vec3_ortho)(v2, v6);
GLM(vec3_ortho)(v3, v7); GLM(vec3_ortho)(v3, v7);
GLM(vec3_ortho)(v4, v8);
a = glm_vec3_angle(v1, v5); a = glm_vec3_angle(v1, v5);
ASSERT(!isinf(a)) ASSERT(!isinf(a))
@@ -1150,6 +1151,13 @@ TEST_IMPL(GLM_PREFIX, vec3_ortho) {
ASSERT(!isnan(a)) ASSERT(!isnan(a))
ASSERT(test_eq(a, GLM_PI_2f)) ASSERT(test_eq(a, GLM_PI_2f))
a = glm_vec3_angle(v4, v8);
printf("(%f, %f, %f)\n", v4[0], v4[1], v4[2]);
printf("(%f, %f, %f)\n", v8[0], v8[1], v8[2]);
ASSERT(!isinf(a))
ASSERT(!isnan(a))
ASSERT(test_eq(a, GLM_PI_2f))
TEST_SUCCESS TEST_SUCCESS
} }