sKit  0.0.9
math.cpp
Go to the documentation of this file.
1 #include "math.hpp"
2 
3 #include <array>
4 #include <cmath>
5 #include <glm/matrix.hpp>
6 
7 namespace sKit {
8 namespace math {
9 
10 auto map(
11  float value,
12  float inputMin,
13  float inputMax,
14  float outputMin,
15  float outputMax,
16  bool clamp
17 ) -> float {
18  if (std::abs(inputMin - inputMax) < std::numeric_limits<float>::epsilon()) {
19  return outputMin;
20  } else {
21  float outVal =
22  ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) +
23  outputMin);
24 
25  if (clamp) {
26  if (outputMax < outputMin) {
27  if (outVal < outputMax)
28  outVal = outputMax;
29  else if (outVal > outputMin)
30  outVal = outputMin;
31  } else {
32  if (outVal > outputMax)
33  outVal = outputMax;
34  else if (outVal < outputMin)
35  outVal = outputMin;
36  }
37  }
38  return outVal;
39  }
40 }
41 
42 auto flatten(const glm::mat4& mat) -> std::array<float, 16> {
43  std::array<float, 16> flat;
44  for (int i = 0; i < 4; i++) {
45  for (int j = 0; j < 4; j++) {
46  flat[i * 4 + j] = mat[i][j];
47  }
48  }
49  return flat;
50 };
51 
52 } // namespace math
53 } // namespace sKit
sKit::math::flatten
auto flatten(const glm::mat4 &mat) -> std::array< float, 16 >
flattens a 4x4 matrix with row major order
Definition: math.cpp:42
sKit
Definition: camera.hpp:8
sKit::math::map
auto map(float value, float inputMin, float inputMax, float outputMin, float outputMax, bool clamp) -> float
Given a value and an input range, map the value to an output range.
Definition: math.cpp:10
math.hpp