
// Copyright 2019 Shlomi Steinberg
// 

#pragma once

#include <cmath>

#include "glm.hpp"

template <typename T>
void orthogonal_frame(const glm::vec<3,T> &n, glm::vec<3,T> &t1, glm::vec<3,T> &t2) noexcept {
    const auto sign = T(std::copysignf(1.0f, static_cast<float>(n.z)));
    const auto a = T(-1.0) / (sign + n.z);
    const auto b = n.x*n.y*a;
    t1 = { T(1) + sign*n.x*n.x*a, sign*b, -sign*n.x };
    t2 = { b, sign + n.y*n.y*a, -n.y };
}
