// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "tdm/Types.h" #include "tdm/Ang.h" #include "tdm/Mat.h" #include "tdm/Computations.h" #include "tdm/Transforms.h" namespace tdm { template struct axis_angle { vec3 axis; rad angle; axis_angle(vec3 axis_, rad angle_) : axis{axis_}, angle{angle_} { } axis_angle(rad x, rad y, rad z, handedness h = handedness::right) { const mat4 m = rotate(x, y, z, h); angle = rad{std::acos((trace(m.template submat<3, 3>(0, 0)) - static_cast(1.0)) / static_cast(2.0))}; const T factor = static_cast(1.0) / (static_cast(2.0) * std::sin(angle.value)); axis[0] = factor * (m(2, 1) - m(1, 2)); axis[1] = factor * (m(0, 2) - m(2, 0)); axis[2] = factor * (m(1, 0) - m(0, 1)); } axis_angle(const rad3& angles, handedness h = handedness::right) : axis_angle{angles[0], angles[1], angles[2], h} { } }; } // namespace tdm