ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
util.hpp
Go to the documentation of this file.
1
11
12#ifndef TOYMAKERENGINE_UTIL_H
13#define TOYMAKERENGINE_UTIL_H
14
15#include <glm/glm.hpp>
16
17namespace ToyMaker {
27 glm::mat4 buildModelMatrix(glm::vec4 position, glm::quat orientation, glm::vec3 scale = glm::vec3{1.f, 1.f, 1.f});
28
35 inline float squareDistance(const glm::vec3& vector) {
36 return glm::dot(vector, vector);
37 }
38
47 inline bool isFinite(float number) {
48 return std::isfinite(number);
49 }
50
59 inline bool isFinite(const glm::vec3& vector) {
60 return isFinite(vector.x) && isFinite(vector.y) && isFinite(vector.z);
61 }
62
71 inline bool isPositiveStrict(float number) {
72 return number > 0.f;
73 }
74
83 inline bool isPositiveStrict(const glm::vec3& vector) {
84 return isPositiveStrict(vector.x) && isPositiveStrict(vector.y) && isPositiveStrict(vector.z);
85 }
86
92 inline bool isNumber(float number) {
93 return !std::isnan(number);
94 };
95
101 inline bool isNumber(const glm::vec3& vector) {
102 return isNumber(vector.x) && isNumber(vector.y) && isNumber(vector.z);
103 };
104
113 inline bool isNonNegative(float number) {
114 return number >= 0.f;
115 }
116
125 inline bool isNonNegative(const glm::vec3& vector) {
126 return isNonNegative(vector.x) && isNonNegative(vector.y) && isNonNegative(vector.z);
127 }
128
135 glm::quat getRotation(const glm::vec3& from, const glm::vec3& to);
136
141 float getAngle(const glm::vec3& from, const glm::vec3& to, const glm::vec3& axis);
142
148 glm::vec3 getOrthogonal(const glm::vec3& from);
149
158 std::pair<glm::vec3, glm::vec3> getTangents(const glm::vec3& vector);
159
165 bool isSensible(const glm::mat3& matrix);
166
173 glm::mat4 getScaleMatrix(const glm::mat4& fromTransform);
174
181 glm::mat4 getRotationMatrix(const glm::mat4& fromTransform);
182
188 glm::mat4 getTranslationMatrix(const glm::mat4& fromTransform);
189
214 public:
224 double inputLowerBound, double inputUpperBound,
225 double outputLowerBound, double outputUpperBound
226 );
227
234 double operator() (double value) const;
235 private:
246
252
258 };
259}
260
261#endif
double mInputUpperBound
The end of the input range.
Definition util.hpp:245
double mOutputLowerBound
The start of the output range.
Definition util.hpp:251
double mInputLowerBound
The start of the input range.
Definition util.hpp:240
RangeMapperLinear(double inputLowerBound, double inputUpperBound, double outputLowerBound, double outputUpperBound)
Constructs a range mapper with a fixed pair of input and output ranges.
Definition util.cpp:17
double mOutputUpperBound
The end of the output range.
Definition util.hpp:257
double operator()(double value) const
The operation that actually converts a value from its input range into its output range.
Definition util.cpp:29
glm::mat4 getScaleMatrix(const glm::mat4 &fromTransform)
Given a transform, returns scale matrix that was used to compose the transform.
Definition util.cpp:43
glm::quat getRotation(const glm::vec3 &from, const glm::vec3 &to)
Returns the rotation between two vectors represented as a quaternion.
Definition util.cpp:67
glm::mat4 getRotationMatrix(const glm::mat4 &fromTransform)
Given a transform, returns rotation matrix that was used to compose the transform.
Definition util.cpp:52
bool isPositiveStrict(float number)
Tests whether a number is strictly positive.
Definition util.hpp:71
glm::mat4 getTranslationMatrix(const glm::mat4 &fromTransform)
Given a transform, returns translation matrix that was used to compose the transform.
Definition util.cpp:58
bool isNumber(float number)
Tests whether a float is really a number (as opposed to a special error representation).
Definition util.hpp:92
glm::mat4 buildModelMatrix(glm::vec4 position, glm::quat orientation, glm::vec3 scale=glm::vec3{1.f, 1.f, 1.f})
Converts a position, orientation and scale into its model matrix equivalent.
Definition util.cpp:10
bool isNonNegative(float number)
Tests whether a number is non-negative.
Definition util.hpp:113
float squareDistance(const glm::vec3 &vector)
Returns the square of the length of a 3 component vector.
Definition util.hpp:35
bool isFinite(float number)
Tests whether a given number is finite.
Definition util.hpp:47
bool isSensible(const glm::mat3 &matrix)
Determines whether a particular matrix is valid and finite.
Definition math.cpp:775
std::pair< glm::vec3, glm::vec3 > getTangents(const glm::vec3 &vector)
Returns a pair of normalized tangents to an input vector.
Definition util.cpp:121
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition application.hpp:25
glm::vec3 getOrthogonal(const glm::vec3 &from)
Given some arbitrary non-zero vector, returns a normalized vector that is orthogonal to it.
Definition util.cpp:114
float getAngle(const glm::vec3 &from, const glm::vec3 &to, const glm::vec3 &axis)
Gets angle between two vectors about an axis vector in the range [-Pi, Pi].
Definition util.cpp:83