-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
63 lines (53 loc) · 1.53 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// FEM elements
#pragma once
#include <cmath>
#include <initializer_list>
#include <cassert>
#if SUPPRESS_ASSERT
#undef assert
#define assert(x) 0
#endif
#ifndef PI
#define PI 3.1415926535897932384626
#endif
#undef max
#undef min
#undef abs
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
template<typename T> T abs(T x) { return x > 0 ? x : -x; }
#include "glm/glm/glm.hpp"
using glm::clamp; using glm::mix; using glm::sign;
using glm::vec2; using glm::vec3; using glm::vec4;
using glm::ivec2; using glm::ivec3; using glm::ivec4;
using glm::dot; using glm::cross; using glm::outerProduct;
using glm::mat2; using glm::mat3; using glm::mat4;
using glm::mat2x3; using glm::mat3x2; using glm::mat2x4; using glm::mat4x2;
using glm::inverse; using glm::transpose; using glm::determinant;
namespace std {
template<>
struct hash<glm::ivec2> {
size_t operator()(const glm::ivec2& v) const {
return hash<uint64_t>()(*(uint64_t*)&v);
}
};
template<>
struct hash<glm::ivec3> {
size_t operator()(const glm::ivec3& v) const {
return hash<int>()(v.x) ^ hash<int>()(v.y) ^ hash<int>()(v.z);
}
};
template<>
struct hash<glm::ivec4> {
size_t operator()(const glm::ivec4& v) const {
return hash<int>()(v.x) ^ hash<int>()(v.y) ^ hash<int>()(v.z) ^ hash<int>()(v.w);
}
};
}
// timer
#include <chrono>
auto _TIME_START = std::chrono::high_resolution_clock::now();
float getTimePast() {
auto t1 = std::chrono::high_resolution_clock::now();
return std::chrono::duration<float>(t1 - _TIME_START).count();
}