Skip to content

Instantly share code, notes, and snippets.

@chrisforbes
Created January 3, 2018 18:46
Show Gist options
  • Save chrisforbes/b6214d7e60a14c8f3432e9f5a78380f2 to your computer and use it in GitHub Desktop.
Save chrisforbes/b6214d7e60a14c8f3432e9f5a78380f2 to your computer and use it in GitHub Desktop.
// 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