7#include "misc/Globals.h"
11#include "math/GLMath.hpp"
12#include "misc/Error.h"
13#include "misc/Profiler.hpp"
61 const glm::vec3& location,
float& radius,
float& theta,
float& phi);
118 if (glm::all(glm::epsilonEqual(direction, glm::vec3(0.0F, 0.0F, 0.0F),
smallFloatEpsilon))) {
119 return glm::vec3(0.0F, 0.0F, 0.0F);
124 constexpr float lengthDelta = 0.001F;
125 const auto length = glm::length(direction);
126 if (!glm::epsilonEqual(length, 1.0F, lengthDelta)) [[unlikely]] {
128 Error error(
"the specified direction vector should have been normalized");
134 glm::vec3 worldRotation = glm::vec3(0.0F, 0.0F, 0.0F);
136 worldRotation.z = glm::degrees(std::atan2(direction.y, direction.x));
137 worldRotation.y = glm::degrees(-std::asin(direction.z));
140 if (glm::isnan(worldRotation.z)) {
142 "found NaN in the Z component of the calculated rotation, setting this component's value to "
144 worldRotation.z = 0.0F;
146 if (glm::isnan(worldRotation.y)) {
148 "found NaN in the Y component of the calculated rotation, setting this component's value to "
150 worldRotation.y = 0.0F;
173 return worldRotation;
181 phi = glm::radians(phi);
182 theta = glm::radians(theta);
184 const auto sinPhi = std::sin(phi);
185 const auto sinTheta = std::sin(theta);
186 const auto cosPhi = std::cos(phi);
187 const auto cosTheta = std::cos(theta);
188 return glm::vec3(radius * sinPhi * cosTheta, radius * sinPhi * sinTheta, radius * cosPhi);
192 const glm::vec3& location,
float& radius,
float& theta,
float& phi) {
193 radius = glm::sqrt(location.x * location.x + location.y * location.y + location.z * location.z);
194 theta = glm::degrees(glm::atan2(location.y, location.x));
196 glm::atan2(glm::sqrt(location.x * location.x + location.y * location.y), location.z));
200 glm::vec3 reciprocal;
205 reciprocal.x = 1.0F / vector.x;
211 reciprocal.y = 1.0F / vector.y;
217 reciprocal.z = 1.0F / vector.z;
224 return glm::rotate(glm::radians(rotation.z), glm::vec3(0.0F, 0.0F, 1.0F)) *
225 glm::rotate(glm::radians(rotation.y), glm::vec3(0.0F, 1.0F, 0.0F)) *
226 glm::rotate(glm::radians(rotation.x), glm::vec3(1.0F, 0.0F, 0.0F));
230 const auto width = max - min;
231 const auto offsetValue = value - min;
233 return (offsetValue - (floor(offsetValue / width) * width)) + min;
237 const auto squareSum = vector.x * vector.x + vector.y * vector.y + vector.z * vector.z;
240 return glm::vec3(0.0F, 0.0F, 0.0F);
243 return vector * glm::inversesqrt(squareSum);
std::string getFullErrorMessage() const
Definition: Error.cpp:84
void showError() const
Definition: Error.cpp:102
static Logger & get()
Definition: Logger.cpp:41
void warn(std::string_view sText, const std::source_location location=std::source_location::current()) const
Definition: Logger.cpp:62
Definition: MathHelpers.hpp:17
static float normalizeToRange(float value, float min, float max)
Definition: MathHelpers.hpp:229
static const float smallFloatEpsilon
Definition: MathHelpers.hpp:111
static glm::vec3 convertNormalizedDirectionToRollPitchYaw(const glm::vec3 &direction)
Definition: MathHelpers.hpp:114
static glm::mat4x4 buildRotationMatrix(const glm::vec3 &rotation)
Definition: MathHelpers.hpp:223
static glm::vec3 calculateReciprocalVector(const glm::vec3 &vector)
Definition: MathHelpers.hpp:199
static glm::vec3 normalizeSafely(const glm::vec3 &vector)
Definition: MathHelpers.hpp:236
static void convertCartesianCoordinatesToSpherical(const glm::vec3 &location, float &radius, float &theta, float &phi)
Definition: MathHelpers.hpp:191
static glm::vec3 convertRollPitchYawToDirection(const glm::vec3 &rotation)
Definition: MathHelpers.hpp:176
static glm::vec3 convertSphericalToCartesianCoordinates(float radius, float theta, float phi)
Definition: MathHelpers.hpp:180
static const glm::vec3 forward
Definition: Globals.h:25