SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Math.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "Types.h"
7 
8 #define GLM_FORCE_RADIANS
9 //#define GLM_SWIZZLE
10 
11 #include <glm/glm.hpp>
12 #include <glm/gtc/constants.hpp>
13 #include <glm/gtc/epsilon.hpp>
14 #define GLM_ENABLE_EXPERIMENTAL
15 #include <glm/gtx/compatibility.hpp>
16 #include <glm/gtx/norm.hpp>
17 #include <limits>
18 #include <math.h>
19 
20 namespace ai {
21 
22 inline float toRadians (float degree) {
23  return glm::radians(degree);
24 }
25 
26 inline bool isInfinite (const glm::vec3& vec) {
27  return glm::any(glm::isinf(vec));
28 }
29 
30 inline float toDegrees (float radians) {
31  return glm::degrees(radians);
32 }
33 
34 inline glm::vec3 fromRadians(float radians) {
35  return glm::vec3(glm::cos(radians), 0.0f, glm::sin(radians));
36 }
37 
38 inline float angle(const glm::vec3& v) {
39  const float _angle = glm::atan(v.z, v.x);
40  return _angle;
41 }
42 
43 inline glm::vec3 advance (const glm::vec3& src, const glm::vec3& direction, const float scale) {
44  return src + (scale * direction);
45 }
46 
47 template<typename T>
48 inline T clamp(T a, T low, T high) {
49  return glm::clamp(a, low, high);
50 }
51 
52 static const glm::vec3 ZERO(0.0f);
53 static const glm::vec3 VEC3_INFINITE(std::numeric_limits<float>::infinity());
54 
55 inline glm::vec3 parse(const std::string& in) {
56  float x = 0.0f;
57  float y = 0.0f;
58  float z = 0.0f;
59 
60 #ifdef _MSC_VER
61  if (::sscanf_s(in.c_str(), "%f:%f:%f", &x, &y, &z) != 3) {
62 #else
63  if (::sscanf(in.c_str(), "%f:%f:%f", &x, &y, &z) != 3) {
64 #endif
65  return VEC3_INFINITE;
66  }
67 
68  return glm::vec3(x, y, z);
69 }
70 
71 }