Created
January 3, 2018 18:46
-
-
Save chrisforbes/b6214d7e60a14c8f3432e9f5a78380f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// select the face direction in the tangent plane to `this_face` | |
// most closely aligned with `v` | |
#include <limits> | |
glm::ivec3 get_closest_tangent(int this_face, glm::vec3 v) { | |
glm::ivec3 best; | |
float bestdot = std::numeric_limits<float>::lowest(); | |
for (int face = 0; face < 6; face++) { | |
// exclude normal direction and its inverse | |
if (face == this_face || face == (this_face ^ 1)) | |
continue; | |
auto vec = surface_index_to_normal(face); | |
auto val = glm::dot(glm::vec3(vec), v); | |
if (val > bestdot) { | |
best = vec; | |
bestdot = val; | |
} | |
} | |
return best; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment